From 6395d7cd6a53392ec2b14f7863a43f0f82171fb6 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 10 Nov 2014 15:17:36 -0500 Subject: [PATCH] New Resource.prototype.userResource function --- UI/WebServerResources/js/Common/resource.js | 25 +++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/UI/WebServerResources/js/Common/resource.js b/UI/WebServerResources/js/Common/resource.js index 461b8904a..b6fd45125 100644 --- a/UI/WebServerResources/js/Common/resource.js +++ b/UI/WebServerResources/js/Common/resource.js @@ -11,11 +11,12 @@ * @param {String} path - the base path of the external resource * @param {Object} options - extra attributes to be associated to the object */ - function Resource($http, $q, path, options) { + function Resource($http, $q, path, activeUser, options) { angular.extend(this, { _http: $http, _q: $q, - _path: path + _path: path, + _activeUser: activeUser }); angular.extend(this, options); } @@ -37,6 +38,20 @@ */ angular.module('SOGo.Common').factory('sgResource', Resource.$factory); + /** + * @function userResource + * @memberof Resource.prototype + * @desc Create a new Resource object associated to a username different than the active user. + * @param {String} uid - the user UID + * @return a new Resource object + */ + Resource.prototype.userResource = function(uid) { + var path = _.compact(this._activeUser.folderURL.split('/')); + path.splice(path.length - 1, 1, escape(uid)); + + return new Resource(this._http, this._q, '/' + path.join('/'), this._activeUser); + }; + /** * @function fetch * @memberof Resource.prototype @@ -48,8 +63,10 @@ */ Resource.prototype.fetch = function(folderId, action, params) { var deferred = this._q.defer(), - path = [this._path, (folderId ? folderId : ''), (action ? action : '')]; - path = _.compact(path).join('/'); + path = [this._path]; + if (folderId) path.push(folderId.split('/')); + if (action) path.push(action); + path = _.compact(_.flatten(path)).join('/'); this._http({ method: 'GET',