4 // WARNING: make sure than app/frontend/services/ConfigApp.js match your server
6 // list all rependencies within the page + controler if needed
7 angular.module('HomeModule', ['SubmitButton', 'TokenRefresh'])
9 .controller('HomeController', function ($http, ConfigApp) {
10 var scope = this; // I hate JavaScript
14 scope.status ="err-no";
16 console.log ("Home Controller");
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;
25 // if token was refresh let's update ConfigApp
26 if (data.request.token) ConfigApp.session.token = data.request.token;
27 if (data.request.uuid) ConfigApp.session.uuid = data.request.uuid;
28 if (data.request.timeout) ConfigApp.session.timeout = data.request.timeout;
30 // Make sure we clean everything when Open/Close is called
31 if (apiname === "APIcreate" || apiname === "APIreset") {
33 scope["APIcreate"]='';
34 scope["APIrefresh"]='';
37 scope[apiname]="success";
39 // If we have a new token let's update it
40 if (data.request.token) scope.token=data.request.token;
42 console.log ("OK: "+ JSON.stringify(data));
45 scope.ProcessError= function(data, errcode, headers, config) {
46 var apiname= 'API'+data.request.api.replace('-','_');
47 scope.status = "err-fx";
48 scope.errcode = errcode;
49 scope.request = data.request;
51 scope[apiname]="fail";
53 console.log ("FX: "+ JSON.stringify(data));
56 scope.OpenSession = function() {
57 console.log ("OpenSession");
58 var postdata= {/* any json your application may need */};
59 var handler = $http.post(ConfigApp.api.token + 'create?token='+ConfigApp.session.token, postdata);
61 handler.success(scope.ProcessResponse);
62 handler.error(scope.ProcessError);
65 scope.CheckSession = function() {
66 console.log ("CloseSession");
67 var postdata= {/* any json your application may need */};
68 var handler = $http.post(ConfigApp.api.token + 'check?token='+scope.token, postdata);
70 handler.success(scope.ProcessResponse);
71 handler.error(scope.ProcessError);
74 scope.RefreshSession = function() {
75 console.log ("RefreshSession");
76 var postdata= {/* any json your application may need */};
77 var handler = $http.post(ConfigApp.api.token + 'refresh?token='+scope.token, postdata);
79 handler.success(scope.ProcessResponse);
80 handler.error(scope.ProcessError);
83 scope.ResetSession = function() {
84 console.log ("ResetSession");
85 var postdata= {/* any json your application may need */};
86 var handler = $http.post(ConfigApp.api.token + 'reset?token='+scope.token, postdata);
88 handler.success(scope.ProcessResponse);
89 handler.error(scope.ProcessError);
94 console.log ("SampleControler Loaded");