- 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);
+ });