11b38822832a07fd7ff6ecfea72cbf13f127fb6d
[src/app-framework-demo.git] / afb-client / app / Frontend / pages / Home / HomeModule.js
1 (function() {
2 'use strict';
3
4   var INITIAL_TOKEN=123456789;  // should match with --token=xxxx binder command line
5
6 // list all rependencies within the page + controler if needed
7 angular.module('HomeModule', ['SubmitButton'])
8
9   .controller('HomeController', function ($http, ConfigApp) {
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             var apiname= 'API'+ data.request.api.replace('-','_');
20             scope.status = "err-ok";
21             scope.errcode= errcode;
22             scope.request  = data.request;
23             scope.response = data.response;
24
25             // Make sure we clean everything when Open/Close is called
26             if (apiname === "APIcreate" || apiname === "APIreset") {
27                 scope["APIreset"]='';
28                 scope["APIcreate"]='';
29                 scope["APIrefresh"]='';
30                 scope["APIcheck"]='';
31             }
32             scope[apiname]="success";
33             
34             // If we have a new token let's update it
35             if (data.request.token) scope.token=data.request.token;
36             
37             console.log ("OK: "+ JSON.stringify(data));
38         };
39         
40         scope.ProcessError= function(data, errcode, headers, config) {
41             var apiname= 'API'+data.request.api.replace('-','_');
42             scope.status   = "err-fx";
43             scope.errcode  = errcode;
44             scope.request  = data.request;
45             scope.response = "";
46             scope[apiname]="fail";
47             
48             console.log ("FX: "+ JSON.stringify(data));
49         };
50
51         scope.OpenSession = function() {
52             console.log ("OpenSession"); 
53             var postdata= {/* any json your application may need */};
54             var handler = $http.post(ConfigApp.api.token + 'create?token='+INITIAL_TOKEN, postdata);
55             
56             handler.success(scope.ProcessResponse);
57             handler.error(scope.ProcessError);
58         };        
59
60         scope.CheckSession = function() {
61             console.log ("CloseSession");
62             var postdata= {/* any json your application may need */};
63             var handler = $http.post(ConfigApp.api.token + 'check?token='+scope.token, postdata);
64             
65             handler.success(scope.ProcessResponse);
66             handler.error(scope.ProcessError);
67         };
68         
69         scope.RefreshSession = function() {
70             console.log ("RefreshSession");
71             var postdata= {/* any json your application may need */};
72             var handler = $http.post(ConfigApp.api.token + 'refresh?token='+scope.token, postdata);
73             
74             handler.success(scope.ProcessResponse);
75             handler.error(scope.ProcessError);
76         };
77         
78         scope.ResetSession = function() {
79             console.log ("ResetSession");
80             var postdata= {/* any json your application may need */};
81             var handler = $http.post(ConfigApp.api.token + 'reset?token='+scope.token, postdata);
82             
83             handler.success(scope.ProcessResponse);
84             handler.error(scope.ProcessError);
85         };
86         
87    });
88
89 console.log ("SampleControler Loaded");
90 })();