First pass at the v3 pref module

The UI needs to be styled. We also need to properly load "default"
values from the system/domain/user defaults and save them correctly
too.
This commit is contained in:
Ludovic Marcotte
2015-06-12 11:17:49 -04:00
committed by Francis Lachapelle
parent 575676deb8
commit 5c3f0138f5
15 changed files with 1792 additions and 712 deletions
@@ -42,7 +42,7 @@
$q: $q,
$timeout: $timeout,
$log: $log,
$$resource: new Resource(Settings.baseURL, Settings.activeUser),
$$resource: new Resource(Settings.activeUser.folderURL + 'Mail', Settings.activeUser),
$Message: Message,
PRELOAD: PRELOAD
});
@@ -0,0 +1,106 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* @name Preferences
* @constructor
*/
function Preferences() {
var _this = this;
this.defaults = {};
this.settings = {};
this.mailboxes = Preferences.$Mailbox.$find({ id: 0 });
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)
var labels = _.object(_.map(data.SOGoMailLabelsColors, function(value, key) {
if (key.charAt(0) == '$')
return ['_' + key, value];
return [key, value];
}));
data.SOGoMailLabelsColors = labels;
angular.extend(_this.defaults, data);
});
});
Preferences.$$resource.fetch("jsonSettings").then(function(data) {
Preferences.$timeout(function() {
angular.extend(_this.settings, data);
});
});
}
/**
* @memberof Preferences
* @desc The factory we'll use to register with Angular
* @returns the Preferences constructor
*/
Preferences.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'sgResource', 'sgMailbox', function($q, $timeout, $log, Settings, Resource, Mailbox) {
angular.extend(Preferences, {
$q: $q,
$timeout: $timeout,
$log: $log,
$$resource: new Resource(Settings.activeUser.folderURL, Settings.activeUser),
activeUser: Settings.activeUser,
$Mailbox: Mailbox
});
return Preferences; // return constructor
}];
/* Factory registration in Angular module */
angular.module('SOGo.PreferencesUI')
.factory('sgPreferences', Preferences.$factory);
/**
* @function $save
* @memberof Preferences.prototype
* @desc Save the preferences to the server.
*/
Preferences.prototype.$save = function() {
var _this = this;
console.debug("save in model...");
return Preferences.$$resource.save("Preferences",
this.$omit(),
undefined)
.then(function(data) {
// Make a copy of the data for an eventual reset
//_this.$shadowData = _this.$omit(true);
return data;
});
};
/**
* @function $omit
* @memberof Preferences.prototype
* @desc Return a sanitized object used to send to the server.
* @param {Boolean} [deep] - make a deep copy if true
* @return an object literal copy of the Preferences instance
*/
Preferences.prototype.$omit = function(deep) {
var preferences = {};
angular.forEach(this, function(value, key) {
if (key == 'refs') {
preferences.refs = _.map(value, function(o) {
return o.$omit(deep);
});
}
else if (key != 'constructor' && key[0] != '$') {
if (deep)
preferences[key] = angular.copy(value);
else
preferences[key] = value;
}
});
return preferences;
};
})();
+250
View File
@@ -0,0 +1,250 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* JavaScript for SOGoPreferences */
(function() {
'use strict';
angular.module('SOGo.Common', []);
angular.module('SOGo.MailerUI', []);
angular.module('SOGo.PreferencesUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.MailerUI', 'SOGo.UIDesktop', 'SOGo.UI'])
.constant('sgSettings', {
baseURL: ApplicationBaseURL,
activeUser: {
login: UserLogin,
identification: UserIdentification,
language: UserLanguage,
folderURL: UserFolderURL,
isSuperUser: IsSuperUser
}
})
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('preferences', {
abstract: true,
views: {
preferences: {
templateUrl: 'preferences.html',
controller: 'PreferencesCtrl'
}
},
resolve: {
statePreferences: ['sgPreferences', function(Preferences) {
return new Preferences();
}]
}
})
.state('preferences.general', {
url: '/general',
views: {
module: {
templateUrl: 'generalPreferences.html'
}
}
})
.state('preferences.calendars', {
url: '/calendars',
views: {
module: {
templateUrl: 'calendarsPreferences.html'
}
}
})
.state('preferences.addressbooks', {
url: '/addressbooks',
views: {
module: {
templateUrl: 'addressbooksPreferences.html'
}
}
})
.state('preferences.mailer', {
url: '/mailer',
views: {
module: {
templateUrl: 'mailerPreferences.html'
}
}
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/general');
}])
.controller('PreferencesCtrl', ['$scope', '$timeout', '$mdDialog', 'sgPreferences', 'statePreferences', function($scope, $timeout, $mdDialog, Preferences, statePreferences) {
$scope.preferences = statePreferences;
$scope.removeCalendarCategory = function(index) {
var key = $scope.preferences.defaults.SOGoCalendarCategories[index];
$scope.preferences.defaults.SOGoCalendarCategories.splice(index, 1);
delete $scope.preferences.defaults.SOGoCalendarCategoriesColors[key];
}
$scope.addContactCategory = function() {
$scope.preferences.defaults.SOGoContactsCategories.push("");
};
$scope.removeContactCategory = function(index) {
$scope.preferences.defaults.SOGoContactsCategories.splice(index, 1);
}
$scope.addMailAccount = function(ev) {
$scope.preferences.defaults.AuxiliaryMailAccounts.push({});
var account = _.last($scope.preferences.defaults.AuxiliaryMailAccounts);
$mdDialog.show({
controller: AccountDialogCtrl,
templateUrl: 'editAccount?account=new',
targetEvent: ev,
locals: { account: account }
});
};
$scope.editMailAccount = function(index) {
var account = $scope.preferences.defaults.AuxiliaryMailAccounts[index];
$mdDialog.show({
controller: AccountDialogCtrl,
templateUrl: 'editAccount?account=' + index,
targetEvent: null,
locals: { account: account }
}).then(function() {
$scope.preferences.defaults.AuxiliaryMailAccounts[index] = account;
});
};
$scope.removeMailAccount = function(index) {
$scope.preferences.defaults.AuxiliaryMailAccounts.splice(index, 1);
};
$scope.addMailLabel = function() {
$scope.preferences.defaults.SOGoMailLabelsColors["foo_bar"] = ["foo bar", "#FFFF00"];
};
$scope.removeMailLabel = function(key) {
delete $scope.preferences.defaults.SOGoMailLabelsColors[key];
};
$scope.addMailFilter = function(ev) {
$scope.preferences.defaults.SOGoSieveFilters.push({});
var filter = _.last($scope.preferences.defaults.SOGoSieveFilters);
$mdDialog.show({
controller: FiltersDialogCtrl,
templateUrl: 'editFilter?filter=new',
targetEvent: ev,
locals: { filter: filter,
mailboxes: $scope.preferences.mailboxes,
labels: $scope.preferences.defaults.SOGoMailLabelsColors}
});
};
$scope.editMailFilter = function(index) {
var filter = angular.copy($scope.preferences.defaults.SOGoSieveFilters[index]);
$mdDialog.show({
controller: FiltersDialogCtrl,
templateUrl: 'editFilter?filter=' + index,
targetEvent: null,
locals: { filter: filter,
mailboxes: $scope.preferences.mailboxes,
labels: $scope.preferences.defaults.SOGoMailLabelsColors }
}).then(function() {
$scope.preferences.defaults.SOGoSieveFilters[index] = filter;
});
};
$scope.removeMailFilter = function(index) {
$scope.preferences.defaults.SOGoSieveFilters.splice(index, 1);
};
$scope.addPreventInvitationsWhitelist = function() {
$scope.preferences.settings.Calendar.PreventInvitationsWhitelist.push("");
};
$scope.removePreventInvitationsWhitelist = function() {
$scope.preferences.settings.Calendar.PreventInvitationsWhitelist.pop();
};
$scope.save = function() {
console.debug("save");
$scope.preferences.$save();
};
$scope.changePassword = function() {
console.debug("change password");
};
}]);
function FiltersDialogCtrl($scope, $mdDialog, filter, mailboxes, labels) {
$scope.filter = filter;
$scope.mailboxes = mailboxes;
$scope.labels = labels;
$scope.fieldLabels = { "subject": l("Subject"),
"from": l("From"),
"to": l("To"),
"cc": l("Cc"),
"to_or_cc": l("To or Cc"),
"size": l("Size (Kb)"),
"header": l("Header"),
"body": l("Body") };
$scope.methodLabels = { "addflag": l("Flag the message with:"),
"discard": l("Discard the message"),
"fileinto": l("File the message in:"),
"keep": l("Keep the message"),
"redirect": l("Forward the message to:"),
"reject": l("Send a reject message:"),
"vacation": l("Send a vacation message"),
"stop": l("Stop processing filter rules") };
$scope.numberOperatorLabels = { "under": l("is under"),
"over": l("is over") };
$scope.textOperatorLabels = { "is": l("is"),
"is_not": l("is not"),
"contains": l("contains"),
"contains_not": l("does not contain"),
"matches": l("matches"),
"matches_not": l("does not match"),
"regex": l("matches regex"),
"regex_not": l("does not match regex") };
$scope.flagLabels = { "seen": l("Seen"),
"deleted": l("Deleted"),
"answered": l("Answered"),
"flagged": l("Flagged"),
"junk": l("Junk"),
"not_junk": l("Not Junk") };
$scope.cancel = function() {
$mdDialog.cancel();
};
$scope.save = function() {
$mdDialog.hide();
};
$scope.addMailFilterRule = function(event) {
$scope.filter.rules.push({});
}
$scope.removeMailFilterRule = function(index) {
$scope.filter.rules.splice(index, 1);
};
$scope.addMailFilterAction = function(event) {
$scope.filter.actions.push({});
}
$scope.removeMailFilterAction = function(index) {
$scope.filter.actions.splice(index, 1);
};
}
function AccountDialogCtrl($scope, $mdDialog, account) {
$scope.account = account;
$scope.cancel = function() {
$mdDialog.cancel();
};
$scope.save = function() {
$mdDialog.hide();
};
}
})();