4 var INITIAL_TOKEN=123456789; // should match with --token=xxxx binder command line
6 // list all rependencies within the page + controler if needed
7 angular.module('HomeModule', ['SubmitButton'])
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 // Make sure we clean everything when Open/Close is called
26 if (apiname === "APIcreate" || apiname === "APIreset") {
28 scope["APIcreate"]='';
29 scope["APIrefresh"]='';
32 scope[apiname]="success";
34 // If we have a new token let's update it
35 if (data.request.token) scope.token=data.request.token;
37 console.log ("OK: "+ JSON.stringify(data));
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;
46 scope[apiname]="fail";
48 console.log ("FX: "+ JSON.stringify(data));
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);
56 handler.success(scope.ProcessResponse);
57 handler.error(scope.ProcessError);
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);
65 handler.success(scope.ProcessResponse);
66 handler.error(scope.ProcessError);
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);
74 handler.success(scope.ProcessResponse);
75 handler.error(scope.ProcessError);
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);
83 handler.success(scope.ProcessResponse);
84 handler.error(scope.ProcessError);
89 console.log ("SampleControler Loaded");