summaryrefslogtreecommitdiffstats
path: root/afb-client/app/Frontend/pages/Home/HomeModule.js
blob: b082ee02ad71281760718132668b6d9b82bc054d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(function() {
'use strict';

// WARNING: make sure than app/frontend/services/AppConfig.js match your server

// list all rependencies within the page + controler if needed
angular.module('HomeModule', ['SubmitButton', 'TokenRefresh','ModalNotification'])

  .controller('HomeController', function (AppCall, Notification) {
        var scope = this; // I hate JavaScript
        scope.uuid   ="none";
        scope.token  ="none";
        scope.session="none";
        scope.status ="err-no";

        console.log ("Home Controller");
        
        scope.OnResponse= function(jresp, errcode) {
            
            // Update UI response global display zone
            scope.status   = jresp.request.status;
            scope.errcode  = errcode;
            scope.request  = jresp.request;
            scope.response = jresp.response;
            
            if (jresp.request.status !== "success") {
                Notification.error ({message: "Invalid API call:" + jresp.request.info , delay: 5000});
                scope.class [jresp.request.reqid]="fail";   
                return;
            }
            
            switch (jresp.request.reqid) {
                case 'create':
                case 'reset':
                    scope.class={};
                    break;
                    
                case 'refresh':
                case 'check':
                    break;
                    
                default:
                    Notification.error ({message: "Invalid RequestID:" + jresp.request.reqid , delay: 5000});
                    return;
            } 

            // update button classes within home.html
            scope.class [jresp.request.reqid]="success";            
            console.log ("OK: "+ JSON.stringify(jresp));
        };
        
        scope.ProcessError= function(response, errcode, config) {
            Notification.error ({message: "Invalid API:" + response.request.reqid , delay: 5000});
            scope.status   = "err-fx";
            scope.errcode  = errcode;
            scope.request  = response.request;
            scope.response = "";            
            console.log ("FX: "+ JSON.stringify(response));
        };

        scope.OpenSession = function() {
            console.log ("OpenSession");
            AppCall.get ("token", "create", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
        };        

        scope.CheckSession = function() {
            console.log ("CloseSession");
            AppCall.get ("token", "check", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
           
        };
        
        scope.RefreshSession = function() {
            console.log ("RefreshSession");
            AppCall.get ("token", "refresh", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
        };
        
        scope.ResetSession = function() {
            console.log ("ResetSession");
            AppCall.get ("token", "reset", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
        };
        
        scope.Initialised = function () {
            scope.class = {create: "success"};
        }
        
   });

console.log ("SampleControler Loaded");
})();