Touchgui/www/js/main.js

changeset 0
e8ccd40d0ef6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Touchgui/www/js/main.js	Thu Jun 04 14:50:33 2015 +0200
     1.3 @@ -0,0 +1,77 @@
     1.4 +/*jslint unparam: true */
     1.5 +
     1.6 +/* jshint strict: true, -W097, unused:false  */
     1.7 +/*global window, document, d3, $, io, navigator, setTimeout */
     1.8 +
     1.9 +//Set the size of the Notifier Circle
    1.10 +$("#notifier_circle").width(0.8 * window.innerWidth);
    1.11 +$("#notifier_circle").height(0.8 * window.innerWidth);
    1.12 +
    1.13 +
    1.14 +/*
    1.15 +Function: validateIP()
    1.16 +Parameter: none
    1.17 +Description: Attempt to connect to server/Intel IoT platform
    1.18 +*/
    1.19 +function validateIP() {
    1.20 +    'use strict';
    1.21 +    var socket,
    1.22 +    //Get values from text fields
    1.23 +        ip_addr = $("#ip_address").val(),
    1.24 +        port = $("#port").val(),
    1.25 +        script = document.createElement("script");
    1.26 +
    1.27 +    //create script tag for socket.io.js file located on your IoT platform (development board)
    1.28 +    script.setAttribute("src", "http://" + ip_addr + ":" + port + "/socket.io/socket.io.js");
    1.29 +    document.head.appendChild(script);
    1.30 +    
    1.31 +    //Wait 1 second before connecting
    1.32 +    setTimeout(function () {
    1.33 +        try {
    1.34 +            //Connect to Server
    1.35 +            socket = io.connect("http://" + ip_addr + ":" + port);
    1.36 +
    1.37 +            //Attach a 'connected' event handler to the socket
    1.38 +            socket.on("connected", function (message) {
    1.39 +                navigator.notification.alert(
    1.40 +                    'Welcome',  // message
    1.41 +                    "",                     // callback
    1.42 +                    'Hi There!',            // title
    1.43 +                    'Ok'                  // buttonName
    1.44 +                );
    1.45 +            });
    1.46 +
    1.47 +            //Set all Back button to not show
    1.48 +            $.ui.showBackButton = false;
    1.49 +            //Load page with transition
    1.50 +            $.ui.loadContent("#main", false, false, "fade");
    1.51 +
    1.52 +            socket.on("message", function (message) {
    1.53 +                //alert("Is anyone there? "+message);
    1.54 +                if (message === "present") {
    1.55 +                    $("#notifier_circle").attr("class", "green");
    1.56 +                    //Update log
    1.57 +                    $("#feedback_log").append(Date().substr(0, 21) + " Someone is Present!<br>");
    1.58 +                    //Prompt user with Cordova notification alert
    1.59 +                    navigator.notification.alert(
    1.60 +                        'Someone is Present!',  // message
    1.61 +                        "",                     // callback
    1.62 +                        'Check Your Door',            // title
    1.63 +                        'Ok'                  // buttonName
    1.64 +                    );
    1.65 +                    //Wait 2 seconds then turn back to gray
    1.66 +                    setTimeout(function () {
    1.67 +                        $("#notifier_circle").attr("class", "gray");
    1.68 +                    }, 3000);
    1.69 +                }
    1.70 +            });
    1.71 +        } catch (e) {
    1.72 +            navigator.notification.alert(
    1.73 +                "Server Not Available!",  // message
    1.74 +                "",                     // callback
    1.75 +                'Connection Error!',            // title
    1.76 +                'Ok'                  // buttonName
    1.77 +            );
    1.78 +        }
    1.79 +    }, 1000);
    1.80 +}

mercurial