4 // _all modules only reference dependencies
5 angular.module('AppConfig', [])
7 // Factory is a singleton and share its context within all instances.
8 .factory('AppConfig', function (urlquery) {
11 paths: { // Warning paths should end with /
13 avatar: 'images/avatars/',
14 audio : 'images/audio/',
15 appli : 'images/appli/'
18 session: { // Those data are updated by session service
19 create : '/api/token/create',
20 refresh : '/api/token/refresh',
21 check : '/api/token/check',
22 reset : '/api/token/reset',
23 ping : '/api/token/check',
24 initial : urlquery.token || '123456789', // typical dev initial token
25 timeout : 3600, // timeout is updated client sessin context creation
26 pingrate: 30, // Ping rate to check if server is still alive
27 uuid : '', // uuid map with cookie or long term session access key
28 token : '' // will be returned from authentication
35 // Factory is a singleton and share its context within all instances.
36 .factory('AppCall', function ($http, AppConfig, $log) {
38 get : function(plugin, action, query, cbresponse, cberror) {
39 if (!query.token) query.token = AppConfig.session.token; // add token to provided query
40 var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then (onsuccess, onerror);
42 handle.onsuccess (function(data, errcode, headers, config) {
43 // if token was updated keep it within application cache
44 if (data.request.token) AppConfig.session.token = data.request.token;
45 if (data.request.uuid) AppConfig.session.uuid = data.request.uuid;
46 if (data.request.timeout) AppConfig.session.timeout = data.request.timeout;
48 cbresponse(data, errcode, headers, config);
51 handle.onerror (function(data, errcode, headers, config) {
52 if (cberror) cberror(data, errcode, headers, config);
53 else cbresponse(data, errcode, headers, config);