Started move to new framework version
[src/app-framework-demo.git] / afb-client / app / Frontend / etc / AppConfig.js
index bd1aae0..5c9283e 100644 (file)
@@ -23,7 +23,7 @@
                        ping    : '/api/token/check',
                        initial : urlquery.token || '123456789',  // typical dev initial token
                        timeout : 3600,         // timeout is updated client sessin context creation
-                       pingrate: 60,           // Ping rate to check if server is still alive
+                       pingrate: 30,           // Ping rate to check if server is still alive
                        uuid    : '',           // uuid map with cookie or long term session access key
                        token   : ''            // will be returned from authentication    
                     }
             })
             
             // Factory is a singleton and share its context within all instances.
-            .factory('AppCall', function ($http, AppConfig) {
+            .factory('AppCall', function ($http, AppConfig, $log) {
                 var myCalls = {
-                    get : function(plugin, action, query, callback) {
-                        if (!query.token) query.token = AppConfig.session.token; // add token to provided query                        
-                        $http.get('/api/' + plugin + '/' + action , {params: query}).then (callback, callback);
+                    get : function(plugin, action, query, cbresponse, cberror) {                                                
+                        if (!query.token) query.token = AppConfig.session.token; // add token to provided query
+                        var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then (onsuccess, onerror);
+                        
+                        handle.onsuccess (function(data, errcode, headers, config) {
+                            // if token was updated keep it within application cache
+                            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;
+                        
+                            cbresponse(data, errcode, headers, config);
+                        });
+                        
+                        handle.onerror   (function(data, errcode, headers, config) {
+                            if (cberror) cberror(data, errcode, headers, config);
+                            else cbresponse(data, errcode, headers, config);
+                        });
                     }
-
                 };
                 return myCalls;
             });
-    
 
 })();
\ No newline at end of file