(js) New 'ready' method for Preferences service
This method returns a promise that succeeds when the user's defaults and settings have been received from the server.
This commit is contained in:
parent
396892b0e1
commit
066bdc5f3f
|
@ -82,7 +82,7 @@
|
||||||
*/
|
*/
|
||||||
statePreferences.$inject = ['Preferences'];
|
statePreferences.$inject = ['Preferences'];
|
||||||
function statePreferences(Preferences) {
|
function statePreferences(Preferences) {
|
||||||
return new Preferences();
|
return Preferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -15,9 +15,7 @@
|
||||||
|
|
||||||
this.mailboxes = Preferences.$Mailbox.$find({ id: 0 });
|
this.mailboxes = Preferences.$Mailbox.$find({ id: 0 });
|
||||||
|
|
||||||
Preferences.$$resource.fetch("jsonDefaults").then(function(data) {
|
this.defaultsPromise = Preferences.$$resource.fetch("jsonDefaults").then(function(data) {
|
||||||
Preferences.$timeout(function() {
|
|
||||||
|
|
||||||
// We swap $key -> _$key to avoid an Angular bug (https://github.com/angular/angular.js/issues/6266)
|
// We swap $key -> _$key to avoid an Angular bug (https://github.com/angular/angular.js/issues/6266)
|
||||||
var labels = _.object(_.map(data.SOGoMailLabelsColors, function(value, key) {
|
var labels = _.object(_.map(data.SOGoMailLabelsColors, function(value, key) {
|
||||||
if (key.charAt(0) == '$')
|
if (key.charAt(0) == '$')
|
||||||
|
@ -35,11 +33,11 @@
|
||||||
data.Forward.forwardAddress = data.Forward.forwardAddress.join(",");
|
data.Forward.forwardAddress = data.Forward.forwardAddress.join(",");
|
||||||
|
|
||||||
angular.extend(_this.defaults, data);
|
angular.extend(_this.defaults, data);
|
||||||
});
|
|
||||||
|
return _this.defaults;
|
||||||
});
|
});
|
||||||
|
|
||||||
Preferences.$$resource.fetch("jsonSettings").then(function(data) {
|
this.settingsPromise = Preferences.$$resource.fetch("jsonSettings").then(function(data) {
|
||||||
Preferences.$timeout(function() {
|
|
||||||
// We convert our PreventInvitationsWhitelist hash into a array of user
|
// We convert our PreventInvitationsWhitelist hash into a array of user
|
||||||
if (data.Calendar && data.Calendar.PreventInvitationsWhitelist)
|
if (data.Calendar && data.Calendar.PreventInvitationsWhitelist)
|
||||||
data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) {
|
data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) {
|
||||||
|
@ -49,8 +47,9 @@
|
||||||
else
|
else
|
||||||
data.Calendar.PreventInvitationsWhitelist = [];
|
data.Calendar.PreventInvitationsWhitelist = [];
|
||||||
|
|
||||||
angular.extend(_this.settings, data);
|
angular.extend(_this.settings, data);
|
||||||
});
|
|
||||||
|
return _this.settings;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,13 +69,23 @@
|
||||||
$User: User
|
$User: User
|
||||||
});
|
});
|
||||||
|
|
||||||
return Preferences; // return constructor
|
return new Preferences(); // return unique instance
|
||||||
}];
|
}];
|
||||||
|
|
||||||
/* Factory registration in Angular module */
|
/* Factory registration in Angular module */
|
||||||
angular.module('SOGo.PreferencesUI')
|
angular.module('SOGo.PreferencesUI')
|
||||||
.factory('Preferences', Preferences.$factory);
|
.factory('Preferences', Preferences.$factory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function ready
|
||||||
|
* @memberof Preferences.prototype
|
||||||
|
* @desc Combine promises used to load user's defaults and settings.
|
||||||
|
* @return a combined promise
|
||||||
|
*/
|
||||||
|
Preferences.prototype.ready = function() {
|
||||||
|
return Preferences.$q.all([this.defaultsPromise, this.settingsPromise]);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function $save
|
* @function $save
|
||||||
* @memberof Preferences.prototype
|
* @memberof Preferences.prototype
|
||||||
|
|
Loading…
Reference in a new issue