summaryrefslogtreecommitdiffstats
path: root/afb-client/app/Frontend/pages/SampleHome/SampleHome.js
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2016-05-28 12:28:19 +0200
committerFulup Ar Foll <fulup@iot.bzh>2016-05-28 12:28:19 +0200
commit95a5e12dca0e0e0eb93b3dad69e529d737840d38 (patch)
tree618f800406d41e6f23e5722671ed51ac0144bd8e /afb-client/app/Frontend/pages/SampleHome/SampleHome.js
parent6d06a2a9a02906ce4c848540d74c3c5798688664 (diff)
Clean up and documentation
Diffstat (limited to 'afb-client/app/Frontend/pages/SampleHome/SampleHome.js')
-rw-r--r--afb-client/app/Frontend/pages/SampleHome/SampleHome.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/afb-client/app/Frontend/pages/SampleHome/SampleHome.js b/afb-client/app/Frontend/pages/SampleHome/SampleHome.js
new file mode 100644
index 0000000..bce1b47
--- /dev/null
+++ b/afb-client/app/Frontend/pages/SampleHome/SampleHome.js
@@ -0,0 +1,104 @@
+(function() {
+'use strict';
+
+// WARNING: make sure than app/frontend/services/AppConfig.js match your server
+
+// list all rependencies within the page + controler if needed
+angular.module('SampleHomeModule', ['SamplePostModule', 'SubmitButton', 'TokenRefresh','ModalNotification'])
+
+ .controller('SampleHomeController', function (AppCall, Notification) {
+ var scope = this; // I hate JavaScript
+ scope.uuid ="none";
+ scope.token ="none";
+ scope.session="none";
+ scope.status ="err-no";
+
+ console.log ("Home Controller");
+
+ scope.OnResponse= function(jresp, errcode) {
+
+ // Update UI response global display zone
+ scope.status = jresp.request.status;
+ scope.errcode = errcode;
+ scope.request = jresp.request;
+ scope.response = jresp.response;
+
+ var action=jresp.request.reqid.toUpperCase();
+
+ switch (action) {
+ case 'CONNECT':
+ if (jresp.request.status !== "success") {
+ Notification.error ({message: action + ": Logout before reconnecting", delay: 5000});
+ scope.class [jresp.request.reqid]="fail";
+ return;
+ }
+ scope.class={}; // reset CSS buttons classes
+ break;
+
+ case 'LOGOUT':
+ if (jresp.request.status !== "success") {
+ Notification.error ({message: action + ": Do connect first", delay: 5000});
+ scope.class [jresp.request.reqid]="fail";
+ return;
+ }
+ scope.class={}; // reset CSS buttons classes
+ break;
+
+ case 'REFRESH':
+ case 'CHECK':
+ if (jresp.request.status !== "success") {
+ Notification.error ({message: action + ": Need to be Connected to check/refresh session", delay: 5000});
+ scope.class [jresp.request.reqid]="fail";
+ return;
+ }
+
+ break;
+
+ default:
+ Notification.error ({message: "Invalid RequestID:" + jresp.request.reqid , delay: 5000});
+ return;
+ }
+
+ // update button classes within home.html
+ scope.class [jresp.request.reqid]="success";
+ console.log ("OK: "+ JSON.stringify(jresp));
+ };
+
+ 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 = response.request;
+ scope.response = "";
+ console.log ("FX: "+ JSON.stringify(response));
+ };
+
+ scope.ConnectClient = function() {
+ console.log ("ConnectClient");
+ AppCall.get ("auth", "connect", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
+ };
+
+ scope.CheckSession = function() {
+ console.log ("CheckSession");
+ AppCall.get ("auth", "check", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
+
+ };
+
+ scope.RefreshSession = function() {
+ console.log ("RefreshSession");
+ AppCall.get ("auth", "refresh", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
+ };
+
+ scope.LogoutClient = function() {
+ console.log ("LogoutClient");
+ AppCall.get ("auth", "logout", {/*query*/}, scope.OnResponse, scope.InvalidApiCall);
+ };
+
+ scope.Initialised = function () {
+ scope.class = {connect: "success"};
+ };
+
+ });
+
+console.log ("SampleControler Loaded");
+})(); \ No newline at end of file