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) {
10 // console.log ("URL="+ $location.url() + " Query=" + location.href+ " window=" + document.referrer);
14 paths: { // Warning paths should end with /
17 avatar: 'images/avatars/',
18 audio : 'images/audio/',
19 appli : 'images/appli/'
22 session: { // Those data are updated by session service
23 initial : urlquery.token || '123456789', // typical dev initial token
24 timeout : 3600, // timeout is updated client sessin context creation
25 pingrate: 15, // Ping rate to check if server is still alive
26 uuid : '', // uuid map with cookie or long term session access key
27 token : '' // will be returned from authentication
34 // Factory is a singleton and share its context within all instances.
35 .factory('AppCall', function ($http, AppConfig, $log) {
38 get : function(plugin, action, query, cbresponse, cberror) {
40 var onerror = function(response) {
41 if (cberror) cberror(response.data, response.status, response.config);
42 else cbresponse(response.data, response.status, response.config);
45 var onsuccess =function(response) {
46 if (!response.data || !response.data.request) {
51 var request=response.data.request;
53 // if token was updated keep it within application cache
54 if (request.token) AppConfig.session.token = request.token;
55 if (request.uuid) AppConfig.session.uuid = request.uuid;
56 if (request.timeout) AppConfig.session.timeout = request.timeout;
58 cbresponse(response.data, response.status, response.config);
62 if (!query.token) query.token = AppConfig.session.token; // add token to provided query
63 if (!query.reqid) query.reqid = action; // use action as default requestID
64 var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then(onsuccess, onerror);