Initial commit
[staging/xdg-launcher.git] / examples / hybrid-html5 / app / Frontend / pages / SampleHome / SampleHome.js
1 (function() {
2 'use strict';
3
4 // WARNING: make sure than app/frontend/services/AppConfig.js match your server
5
6 // list all rependencies within the page + controler if needed
7 angular.module('SampleHomeModule', ['SubmitButton', 'TokenRefresh','ModalNotification'])
8
9   .controller('SampleHomeController', function (AppCall, Notification) {
10         var scope = this; // I hate JavaScript
11         scope.uuid   ="none";
12         scope.token  ="none";
13         scope.session="none";
14         scope.status ="err-no";
15
16         console.log ("Home Controller");
17         
18         scope.OnResponse= function(jresp, errcode) {
19             
20             // Update UI response global display zone
21             scope.status   = jresp.request.status;
22             scope.errcode  = errcode;
23             scope.request  = jresp.request;
24             scope.response = jresp.response;
25             
26             var action=jresp.request.reqid.toUpperCase();
27                         
28             switch (action) {
29                 case 'PING':
30                     break;
31                     
32                 default:
33                     Notification.error ({message: "Invalid RequestID:" + jresp.request.reqid , delay: 5000});
34                     return;
35             } 
36
37             // update button classes within home.html
38             scope.class [jresp.request.reqid]="success";            
39             console.log ("OK: "+ JSON.stringify(jresp));
40         };
41         
42         scope.ProcessError= function(response, errcode, config) {
43             Notification.error ({message: "Invalid API:" + response.request.reqid , delay: 5000});
44             scope.status   = "err-fx";
45             scope.errcode  = errcode;
46             scope.request  = response.request;
47             scope.response = "";            
48             console.log ("FX: "+ JSON.stringify(response));
49         };
50
51         scope.RefreshSession = function() {
52             console.log ("RefreshSession");
53             AppCall.get ("xxxxxx", "ping", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
54         };
55         
56         scope.Initialised = function () {
57             scope.class = {connect: "success"};
58         };
59         
60    });
61
62 console.log ("SampleControler Loaded");
63 })();