Started move to new framework version
[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.ProcessResponse= function(data, errcode, headers, config) {
19             
20             if (data.request.status !== "success") {
21                 Notification.error ({message: "Invalid API call:" + data.request.info , delay: 5000});
22                 return;
23             }
24             
25             // Update UI response global display zone
26             scope.status   = data.request.status;
27             scope.errcode  = errcode;
28             scope.request  = data.request;
29             scope.response = data.response;
30             
31             switch (data.request.reqid) {
32                 case 'open':
33                 case 'reset':
34                     scope.APIreset  ='';
35                     scope.APIcreate ='';
36                     scope.APIrefresh='';
37                     scope.APIcheck  ='';
38                     break;
39                     
40                 case 'refresh':
41                 case 'check':
42                     break;
43                     
44                 default:
45                     Notification.error ({message: "Invalid RequestID:" + data.request.reqid , delay: 5000});
46                     return;
47             } 
48
49             scope[reqid]="success";            
50             console.log ("OK: "+ JSON.stringify(data));
51         };
52         
53         scope.ProcessError= function(data, errcode, headers, config) {
54             Notification.error ({message: "Invalid API:" + data.request.reqid , delay: 5000});
55             scope.status   = "err-fx";
56             scope.errcode  = errcode;
57             scope.request  = data.request;
58             scope.response = "";            
59             console.log ("FX: "+ JSON.stringify(data));
60         };
61
62         scope.OpenSession = function() {
63             console.log ("OpenSession");
64             AppCall.get ("token", "create", {reqid:"open"}, scope.ProcessResponse, scope.InvalidApiCall);
65         };        
66
67         scope.CheckSession = function() {
68             console.log ("CloseSession");
69            
70             var postdata= {/* any json your application may need */};
71             var handler = $http.post(AppConfig.session.check + '?token='+AppConfig.session.token +'?idreq=open', postdata);
72             
73             handler.success(scope.ProcessResponse);
74             handler.error(scope.ProcessError);
75         };
76         
77         scope.RefreshSession = function() {
78             console.log ("RefreshSession");
79             var postdata= {/* any json your application may need */};
80             var handler = $http.post(AppConfig.session.refresh + '?token='+AppConfig.session.token, postdata);
81             
82             handler.success(scope.ProcessResponse);
83             handler.error(scope.ProcessError);
84         };
85         
86         scope.ResetSession = function() {
87             console.log ("ResetSession");
88             var postdata= {/* any json your application may need */};
89             var handler = $http.post(AppConfig.session.reset + '?token='+AppConfig.session.token, postdata);
90             
91             handler.success(scope.ProcessResponse);
92             handler.error(scope.ProcessError);
93         };
94         
95    });
96
97 console.log ("SampleControler Loaded");
98 })();