Merge pull request #288 from negue/apiUrlService

ApiUrlService as preparation for custom endpoints
This commit is contained in:
negue 2014-10-01 19:57:33 +02:00
commit 57ef833aea

View file

@ -1,12 +1,21 @@
'use strict';
angular.module('userServices', [])
.service('ApiUrlService', ['API_URL', function(currentApiUrl){
this.setApiUrl = function(newUrl){
currentApiUrl = newUrl;
};
this.get = function(){
return currentApiUrl;
};
}])
/**
* Services that persists and retrieves user from localStorage.
*/
angular.module('userServices', []).
factory('User', ['$rootScope', '$http', '$location', '$window', 'API_URL', 'STORAGE_USER_ID', 'STORAGE_SETTINGS_ID', 'MOBILE_APP', 'Notification',
function($rootScope, $http, $location, $window, API_URL, STORAGE_USER_ID, STORAGE_SETTINGS_ID, MOBILE_APP, Notification) {
.factory('User', ['$rootScope', '$http', '$location', '$window', 'STORAGE_USER_ID', 'STORAGE_SETTINGS_ID', 'MOBILE_APP', 'Notification', 'ApiUrlService',
function($rootScope, $http, $location, $window, STORAGE_USER_ID, STORAGE_SETTINGS_ID, MOBILE_APP, Notification, ApiUrlService) {
var authenticated = false;
var defaultSettings = {
auth: { apiId: '', apiToken: ''},
@ -59,7 +68,7 @@ angular.module('userServices', []).
// Save the current filters
var current_filters = user.filters;
$http.post(API_URL + '/api/v2/user/batch-update', sent, {params: {data:+new Date, _v:user._v, siteVersion: $window.env && $window.env.siteVersion}})
$http.post(ApiUrlService.get() + '/api/v2/user/batch-update', sent, {params: {data:+new Date, _v:user._v, siteVersion: $window.env && $window.env.siteVersion}})
.success(function (data, status, heacreatingders, config) {
//make sure there are no pending actions to sync. If there are any it is not safe to apply model from server as we may overwrite user data.
if (!queue.length) {