From 9fa9b7acab8cf6690fd87ef7527498e6fcd09980 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 5 Oct 2015 10:45:30 -0400 Subject: [PATCH] Improve mail (Sieve) filter editor - Used 'controller as' syntax; - Don't create new filter if user cancels the edition; - Set default values for new filter. --- .../English.lproj/Localizable.strings | 3 + .../PreferencesUI/UIxFilterEditor.wox | 38 +++++----- UI/Templates/PreferencesUI/UIxPreferences.wox | 2 +- .../js/Preferences/FiltersDialogController.js | 76 ++++++++++--------- .../js/Preferences/PreferencesController.js | 18 +++-- 5 files changed, 75 insertions(+), 62 deletions(-) diff --git a/UI/PreferencesUI/English.lproj/Localizable.strings b/UI/PreferencesUI/English.lproj/Localizable.strings index 3279a7771..cb501daa0 100644 --- a/UI/PreferencesUI/English.lproj/Localizable.strings +++ b/UI/PreferencesUI/English.lproj/Localizable.strings @@ -318,6 +318,9 @@ "matches regex" = "matches regex"; "does not match regex" = "does not match regex"; +/* Placeholder for the value field of a condition */ +"Value" = "Value"; + "Seen" = "Seen"; "Deleted" = "Deleted"; "Answered" = "Answered"; diff --git a/UI/Templates/PreferencesUI/UIxFilterEditor.wox b/UI/Templates/PreferencesUI/UIxFilterEditor.wox index 644299e22..02e1ba772 100644 --- a/UI/Templates/PreferencesUI/UIxFilterEditor.wox +++ b/UI/Templates/PreferencesUI/UIxFilterEditor.wox @@ -8,15 +8,15 @@ xmlns:rsrc="OGo:url" xmlns:uix="OGo:uix"> -
+
filter_list - + - + close
@@ -29,9 +29,9 @@
-
+ - + @@ -49,10 +49,10 @@
- + - {{ value }} + {{ value }} @@ -62,7 +62,7 @@ - + {{ value }} @@ -70,18 +70,18 @@ - + {{ value }} - - + + + ng-click="filterEditor.removeMailFilterRule($index)"> remove_circle @@ -91,7 +91,7 @@
+ ng-click="filterEditor.addMailFilterRule($event)"> add_circle
@@ -104,10 +104,10 @@ + ng-repeat="action in filterEditor.filter.actions"> - {{ value }} + {{ value }} @@ -130,7 +130,7 @@ - + {{ item.name }} @@ -153,7 +153,7 @@ + ng-click="filterEditor.removeMailFilterAction($index)"> remove_circle @@ -162,14 +162,14 @@
+ ng-click="filterEditor.addMailFilterAction($event)"> add_circle
- +
diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index 66ecca1c7..a9f55a597 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -604,7 +604,7 @@ edit diff --git a/UI/WebServerResources/js/Preferences/FiltersDialogController.js b/UI/WebServerResources/js/Preferences/FiltersDialogController.js index ecafae7ec..00761b56a 100644 --- a/UI/WebServerResources/js/Preferences/FiltersDialogController.js +++ b/UI/WebServerResources/js/Preferences/FiltersDialogController.js @@ -9,11 +9,19 @@ */ FiltersDialogController.$inject = ['$scope', '$mdDialog', 'filter', 'mailboxes', 'labels', 'sieveCapabilities']; function FiltersDialogController($scope, $mdDialog, filter, mailboxes, labels, sieveCapabilities) { - $scope.filter = filter; - $scope.mailboxes = mailboxes; - $scope.labels = labels; + var vm = this; - $scope.fieldLabels = { + vm.filter = filter; + vm.mailboxes = mailboxes; + vm.labels = labels; + vm.cancel = cancel; + vm.save = save; + vm.addMailFilterRule = addMailFilterRule; + vm.removeMailFilterRule = removeMailFilterRule; + vm.addMailFilterAction = addMailFilterAction; + vm.removeMailFilterAction = removeMailFilterAction; + + vm.fieldLabels = { "subject": l("Subject"), "from": l("From"), "to": l("To"), @@ -24,9 +32,9 @@ }; if (sieveCapabilities.indexOf("body") > -1) - $scope.fieldLabels.body = l("Body"); + vm.fieldLabels.body = l("Body"); - $scope.methodLabels = { + vm.methodLabels = { "discard": l("Discard the message"), "keep": l("Keep the message"), "redirect": l("Forward the message to:"), @@ -35,20 +43,20 @@ }; if (sieveCapabilities.indexOf("reject") > -1) - $scope.methodLabels.reject = l("Send a reject message:"); + vm.methodLabels.reject = l("Send a reject message:"); if (sieveCapabilities.indexOf("fileinto") > -1) - $scope.methodLabels.fileinto = l("File the message in:"); + vm.methodLabels.fileinto = l("File the message in:"); if (sieveCapabilities.indexOf("imapflags") > -1 || sieveCapabilities.indexOf("imap4flags") > -1) - $scope.methodLabels.addflag = l("Flag the message with:"); + vm.methodLabels.addflag = l("Flag the message with:"); - $scope.numberOperatorLabels = { + vm.numberOperatorLabels = { "under": l("is under"), "over": l("is over") }; - $scope.textOperatorLabels = { + vm.textOperatorLabels = { "is": l("is"), "is_not": l("is not"), "contains": l("contains"), @@ -58,11 +66,11 @@ }; if (sieveCapabilities.indexOf("regex") > -1) { - $scope.textOperatorLabels.regex = l("matches regex"); - $scope.textOperatorLabels.regex_not = l("does not match regex"); + vm.textOperatorLabels.regex = l("matches regex"); + vm.textOperatorLabels.regex_not = l("does not match regex"); } - $scope.flagLabels = { + vm.flagLabels = { "seen": l("Seen"), "deleted": l("Deleted"), "answered": l("Answered"), @@ -71,35 +79,35 @@ "not_junk": l("Not Junk") }; - $scope.cancel = function() { + function cancel() { $mdDialog.cancel(); - }; + } - $scope.save = function() { + function save(form) { $mdDialog.hide(); - }; + } - $scope.addMailFilterRule = function(event) { - if (!$scope.filter.rules) - $scope.filter.rules = []; + function addMailFilterRule(event) { + if (!vm.filter.rules) + vm.filter.rules = []; - $scope.filter.rules.push({}); - }; + vm.filter.rules.push({ field: 'subject', operator: 'contains' }); + } - $scope.removeMailFilterRule = function(index) { - $scope.filter.rules.splice(index, 1); - }; + function removeMailFilterRule(index) { + vm.filter.rules.splice(index, 1); + } - $scope.addMailFilterAction = function(event) { - if (!$scope.filter.actions) - $scope.filter.actions = []; + function addMailFilterAction(event) { + if (!vm.filter.actions) + vm.filter.actions = []; - $scope.filter.actions.push({}); - }; + vm.filter.actions.push({ method: 'discard' }); + } - $scope.removeMailFilterAction = function(index) { - $scope.filter.actions.splice(index, 1); - }; + function removeMailFilterAction(index) { + vm.filter.actions.splice(index, 1); + } } angular diff --git a/UI/WebServerResources/js/Preferences/PreferencesController.js b/UI/WebServerResources/js/Preferences/PreferencesController.js index b79bf5134..a72b7212c 100644 --- a/UI/WebServerResources/js/Preferences/PreferencesController.js +++ b/UI/WebServerResources/js/Preferences/PreferencesController.js @@ -125,14 +125,11 @@ } function addMailFilter(ev) { - if (!vm.preferences.defaults.SOGoSieveFilters) - vm.preferences.defaults.SOGoSieveFilters = []; - - vm.preferences.defaults.SOGoSieveFilters.push({}); - var filter = _.last(vm.preferences.defaults.SOGoSieveFilters); + var filter = { match: 'all' }; $mdDialog.show({ - controller: 'FiltersDialogController', templateUrl: 'editFilter?filter=new', + controller: 'FiltersDialogController', + controllerAs: 'filterEditor', targetEvent: ev, locals: { filter: filter, @@ -140,15 +137,20 @@ labels: vm.preferences.defaults.SOGoMailLabelsColors, sieveCapabilities: window.sieveCapabilities } + }).then(function() { + if (!vm.preferences.defaults.SOGoSieveFilters) + vm.preferences.defaults.SOGoSieveFilters = []; + vm.preferences.defaults.SOGoSieveFilters.push(filter); }); } - function editMailFilter(index) { + function editMailFilter(ev, index) { var filter = angular.copy(vm.preferences.defaults.SOGoSieveFilters[index]); $mdDialog.show({ - controller: 'FiltersDialogController', templateUrl: 'editFilter?filter=' + index, + controller: 'FiltersDialogController', + controllerAs: 'filterEditor', targetEvent: null, locals: { filter: filter,