diff options
author | Fulup Ar Foll <fulup@iot.bzh> | 2016-05-24 09:23:56 +0200 |
---|---|---|
committer | Fulup Ar Foll <fulup@iot.bzh> | 2016-05-24 09:23:56 +0200 |
commit | 7b8fe1b305a36f925fc2757a2c126c88fb0a5137 (patch) | |
tree | 05623effa06276b7ccff95658f1a1dda01b48388 /afb-client/app/Frontend/pages/Home | |
parent | 35698424ab8973d91208df92471d18b1c901220e (diff) |
Started move to new framework version
Diffstat (limited to 'afb-client/app/Frontend/pages/Home')
-rw-r--r-- | afb-client/app/Frontend/pages/Home/HomeModule.js | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/afb-client/app/Frontend/pages/Home/HomeModule.js b/afb-client/app/Frontend/pages/Home/HomeModule.js index fb03ac8..fdbe520 100644 --- a/afb-client/app/Frontend/pages/Home/HomeModule.js +++ b/afb-client/app/Frontend/pages/Home/HomeModule.js @@ -4,9 +4,9 @@ // 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']) +angular.module('HomeModule', ['SubmitButton', 'TokenRefresh','ModalNotification']) - .controller('HomeController', function ($http, AppConfig) { + .controller('HomeController', function (AppCall, Notification) { var scope = this; // I hate JavaScript scope.uuid ="none"; scope.token ="none"; @@ -16,56 +16,59 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) console.log ("Home Controller"); scope.ProcessResponse= function(data, errcode, headers, config) { - var apiname= 'API'+ data.request.api.replace('-','_'); - scope.status = "err-ok"; - scope.errcode= errcode; - scope.request = data.request; - scope.response = data.response; - // if token was refresh let's update AppConfig - if (data.request.token) AppConfig.session.token = data.request.token; - if (data.request.uuid) AppConfig.session.uuid = data.request.uuid; - if (data.request.timeout) AppConfig.session.timeout = data.request.timeout; - - // Make sure we clean everything when Open/Close is called - if (apiname === "APIcreate" || apiname === "APIreset") { - scope.APIreset =''; - scope.APIcreate =''; - scope.APIrefresh=''; - scope.APIcheck =''; + if (data.request.status !== "success") { + Notification.error ({message: "Invalid API call:" + data.request.info , delay: 5000}); + return; } - scope[apiname]="success"; - // If we have a new token let's update it - if (data.request.token) scope.token=data.request.token; + // Update UI response global display zone + scope.status = data.request.status; + scope.errcode = errcode; + scope.request = data.request; + scope.response = data.response; + switch (data.request.reqid) { + case 'open': + case 'reset': + scope.APIreset =''; + scope.APIcreate =''; + scope.APIrefresh=''; + scope.APIcheck =''; + break; + + case 'refresh': + case 'check': + break; + + default: + Notification.error ({message: "Invalid RequestID:" + data.request.reqid , delay: 5000}); + return; + } + + scope[reqid]="success"; console.log ("OK: "+ JSON.stringify(data)); }; scope.ProcessError= function(data, errcode, headers, config) { - var apiname= 'API'+data.request.api.replace('-','_'); + Notification.error ({message: "Invalid API:" + data.request.reqid , delay: 5000}); scope.status = "err-fx"; scope.errcode = errcode; scope.request = data.request; - scope.response = ""; - scope[apiname]="fail"; - + scope.response = ""; console.log ("FX: "+ JSON.stringify(data)); }; scope.OpenSession = function() { - console.log ("OpenSession"); - var postdata= {/* any json your application may need */}; - var handler = $http.post(AppConfig.session.create + '?token='+AppConfig.session.initial, postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); + console.log ("OpenSession"); + AppCall.get ("token", "create", {reqid:"open"}, scope.ProcessResponse, scope.InvalidApiCall); }; scope.CheckSession = function() { console.log ("CloseSession"); + var postdata= {/* any json your application may need */}; - var handler = $http.post(AppConfig.session.check + '?token='+AppConfig.session.token, postdata); + var handler = $http.post(AppConfig.session.check + '?token='+AppConfig.session.token +'?idreq=open', postdata); handler.success(scope.ProcessResponse); handler.error(scope.ProcessError); |