174365404ebffa5fa3ca0398b31005882af1ea6c
[src/app-framework-demo.git] / afb-client / app / Frontend / pages / Home / HomeModule.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('HomeModule', ['SubmitButton', 'TokenRefresh','ModalNotification'])
8
9   .controller('HomeController', 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             if (jresp.request.status !== "success") {
27                 Notification.error ({message: "Invalid API call:" + jresp.request.info , delay: 5000});
28                 scope.class [jresp.request.reqid]="fail";   
29                 return;
30             }
31             
32             switch (jresp.request.reqid) {
33                 case 'login':
34                 case 'logout':
35                     scope.class={};
36                     break;
37                     
38                 case 'refresh':
39                 case 'check':
40                     break;
41                     
42                 default:
43                     Notification.error ({message: "Invalid RequestID:" + jresp.request.reqid , delay: 5000});
44                     return;
45             } 
46
47             // update button classes within home.html
48             scope.class [jresp.request.reqid]="success";            
49             console.log ("OK: "+ JSON.stringify(jresp));
50         };
51         
52         scope.ProcessError= function(response, errcode, config) {
53             Notification.error ({message: "Invalid API:" + response.request.reqid , delay: 5000});
54             scope.status   = "err-fx";
55             scope.errcode  = errcode;
56             scope.request  = response.request;
57             scope.response = "";            
58             console.log ("FX: "+ JSON.stringify(response));
59         };
60
61         scope.LoginClient = function() {
62             console.log ("LoginClient");
63             AppCall.get ("auth", "login", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
64         };        
65
66         scope.CheckSession = function() {
67             console.log ("CheckSession");
68             AppCall.get ("auth", "check", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
69            
70         };
71         
72         scope.RefreshSession = function() {
73             console.log ("RefreshSession");
74             AppCall.get ("auth", "refresh", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
75         };
76         
77         scope.LogoutClient = function() {
78             console.log ("LogoutClient");
79             AppCall.get ("auth", "logout", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
80         };
81         
82         scope.Initialised = function () {
83             scope.class = {login: "success"};
84         }
85         
86    });
87
88 console.log ("SampleControler Loaded");
89 })();