Order Counter in Windows Store Apps

Introduction

Today we are going to learn how to create a Windows Store App for an Order counter using JavaScript. This example shows how to count the orders and when we release the order then how to manage the counter to show only an unreleased order.

I assume, you can create a simple Windows Store App using JavaScript. For more help visit Simple Windows Store Apps using JavaScript.

To start the creation of the app, add two JavaScript pages by right-clicking on the js folder in the Solution Explorer and select Add > new item > JavaScript Page and then give an appropriate name. In the same way, add one HTML page to your project.

order-window-store-app.jpg

Write the following code in default.html:

<!DOCTYPE html>

<html>

<head>

    <title></title>

    <script src="js/script.js"></script>

</head>

<body>

    <div data-win-control="apps.pageInput">

        <button id="button1">Order Activate</button>

        <button id="button2">Order Release</button>

        <br />

        <br />

    </div>

    <div data-win-control="apps.pageOutput">

    </div>

</body>

</html>

Write the following code in default.js:
 

(function () {

    "use strict";

    var exampleTitle = "Order counter";

    var pages = [

        { url: "page.html" }

    ];

 

    function activated(eventObject) {

        if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {

            eventObject.setPromise(WinJS.UI.processAll().then(function () {

                var url = WinJS.Application.sessionState.lastUrl || pages[0].url;

                return WinJS.Navigation.navigate(url);

            }));

        }

    }

    WinJS.Navigation.addEventListener("navigated", function (eventObject) {

        var url = eventObject.detail.location;

        var host = document.getElementById("contentHost");

        host.winControl && host.winControl.unload && host.winControl.unload();

        WinJS.Utilities.empty(host);

        eventObject.detail.setPromise(WinJS.UI.Pages.render(url, host, eventObject.detail.state).then(function () {

            WinJS.Application.sessionState.lastUrl = url;

        }));

    });

    WinJS.Namespace.define("apps", {

        exampleTitle: exampleTitle,

        pages: pages

    });

    WinJS.Application.addEventListener("activated", activated, false);

    WinJS.Application.start();

})(); 


Write the following code in page.html:
 

<!DOCTYPE html>

<html>

<head>

    <title></title>

    <script src="js/script.js"></script>

</head>

<body>

    <div data-win-control="apps.pageInput">

        <button id="button1">Order Activate</button>

        <button id="button2">Order Release</button>

        <br />

        <br />

    </div>

    <div data-win-control="apps.pageOutput">

    </div>

</body>

</html> 


Write the following code in script.js:
 

<!DOCTYPE html>

<html>

<head>

    <title></title>

    <script src="js/script.js"></script>

</head>

<body>

    <div data-win-control="apps.pageInput">

        <button id="button1">Order Activate</button>

        <button id="button2">Order Release</button>

        <br />

        <br />

    </div>

    <div data-win-control="apps.pageOutput">

    </div>

</body>

</html> 


Write the following code in script1.js:
 

(function () {

    var pageOutput = WinJS.Class.define(

        function (element, options) {

            element.winControl = this;

            this.element = element;

            new WinJS.Utilities.QueryCollection(element)

                        .setAttribute("role", "region")

                        .setAttribute("aria-labelledby", "outputLabel")

                        .setAttribute("aria-live", "assertive");

            element.id = "output";

 

            this._addOutputLabel(element);

            this._addStatusOutput(element);

        }, {

            _addOutputLabel: function (element) {

                var label = document.createElement("h2");

                label.id = "outputLabel";

                label.textContent = "Output";

                element.parentNode.insertBefore(label, element);

            },

            _addStatusOutput: function (element) {

                var statusDiv = document.createElement("div");

                statusDiv.id = "statusMessage";

                element.insertBefore(statusDiv, element.childNodes[0]);

            }

        }

    );

    var currentpageUrl = null;

    WinJS.Navigation.addEventListener("navigating", function (evt) {

        currentpageUrl = evt.detail.location;

    });

 

    WinJS.log = function (message, tag, type) {

        var statusDiv = document.getElementById("statusMessage");

        statusDiv.innerText = message;

    };

    function activated(e) {

        WinJS.Utilities.query("#featureLabel")[0].textContent = apps.exampleTitle;

    }

 

    WinJS.Application.addEventListener("activated", activated, false);

    WinJS.Namespace.define("apps", {

        pageOutput: pageOutput

    });

})(); 


Output:


order-Windows-store-apps.jpg


Summary


In this article I described how to create a Windows Store App to count orders using JavaScript. I hope this article has helped you in understanding this topic. Please share it. If you know more about this, your feedback and constructive contributions are welcome.


Recommended Free Ebook
Similar Articles