X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-demo.git;a=blobdiff_plain;f=afb-client%2Fapp%2FFrontend%2Fpages%2FHome%2FHomeModule.js;fp=afb-client%2Fapp%2FFrontend%2Fpages%2FHome%2FHomeModule.js;h=b082ee02ad71281760718132668b6d9b82bc054d;hp=fdbe520badd1bfc27bdd849e5774699311c1ec05;hb=c8a7784c665e1571400853c0c91b9c47be3ce86f;hpb=7b8fe1b305a36f925fc2757a2c126c88fb0a5137 diff --git a/afb-client/app/Frontend/pages/Home/HomeModule.js b/afb-client/app/Frontend/pages/Home/HomeModule.js index fdbe520..b082ee0 100644 --- a/afb-client/app/Frontend/pages/Home/HomeModule.js +++ b/afb-client/app/Frontend/pages/Home/HomeModule.js @@ -15,26 +15,24 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh','ModalNotification' console.log ("Home Controller"); - scope.ProcessResponse= function(data, errcode, headers, config) { - - if (data.request.status !== "success") { - Notification.error ({message: "Invalid API call:" + data.request.info , delay: 5000}); - return; - } + scope.OnResponse= function(jresp, errcode) { // Update UI response global display zone - scope.status = data.request.status; + scope.status = jresp.request.status; scope.errcode = errcode; - scope.request = data.request; - scope.response = data.response; + scope.request = jresp.request; + scope.response = jresp.response; + + if (jresp.request.status !== "success") { + Notification.error ({message: "Invalid API call:" + jresp.request.info , delay: 5000}); + scope.class [jresp.request.reqid]="fail"; + return; + } - switch (data.request.reqid) { - case 'open': + switch (jresp.request.reqid) { + case 'create': case 'reset': - scope.APIreset =''; - scope.APIcreate =''; - scope.APIrefresh=''; - scope.APIcheck =''; + scope.class={}; break; case 'refresh': @@ -42,56 +40,49 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh','ModalNotification' break; default: - Notification.error ({message: "Invalid RequestID:" + data.request.reqid , delay: 5000}); + Notification.error ({message: "Invalid RequestID:" + jresp.request.reqid , delay: 5000}); return; } - scope[reqid]="success"; - console.log ("OK: "+ JSON.stringify(data)); + // update button classes within home.html + scope.class [jresp.request.reqid]="success"; + console.log ("OK: "+ JSON.stringify(jresp)); }; - scope.ProcessError= function(data, errcode, headers, config) { - Notification.error ({message: "Invalid API:" + data.request.reqid , delay: 5000}); + scope.ProcessError= function(response, errcode, config) { + Notification.error ({message: "Invalid API:" + response.request.reqid , delay: 5000}); scope.status = "err-fx"; scope.errcode = errcode; - scope.request = data.request; + scope.request = response.request; scope.response = ""; - console.log ("FX: "+ JSON.stringify(data)); + console.log ("FX: "+ JSON.stringify(response)); }; scope.OpenSession = function() { console.log ("OpenSession"); - AppCall.get ("token", "create", {reqid:"open"}, scope.ProcessResponse, scope.InvalidApiCall); + AppCall.get ("token", "create", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); }; scope.CheckSession = function() { console.log ("CloseSession"); + AppCall.get ("token", "check", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); - var postdata= {/* any json your application may need */}; - var handler = $http.post(AppConfig.session.check + '?token='+AppConfig.session.token +'?idreq=open', postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); }; scope.RefreshSession = function() { console.log ("RefreshSession"); - var postdata= {/* any json your application may need */}; - var handler = $http.post(AppConfig.session.refresh + '?token='+AppConfig.session.token, postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); + AppCall.get ("token", "refresh", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); }; scope.ResetSession = function() { console.log ("ResetSession"); - var postdata= {/* any json your application may need */}; - var handler = $http.post(AppConfig.session.reset + '?token='+AppConfig.session.token, postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); + AppCall.get ("token", "reset", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); }; + scope.Initialised = function () { + scope.class = {create: "success"}; + } + }); console.log ("SampleControler Loaded");