From db9e3a54018c6e9ea9864eeb1f629e1e43507442 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 18 Mar 2015 14:59:06 -0400 Subject: [PATCH] Use sgSearch directive in Webmail module --- UI/Templates/MailerUI/UIxMailMainFrame.wox | 18 +++++--- .../js/Mailer/mailbox-model.js | 43 ++++++++++++++++--- UI/WebServerResources/js/MailerUI.js | 4 +- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox index 10d151060..da243c45f 100644 --- a/UI/Templates/MailerUI/UIxMailMainFrame.wox +++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox @@ -4,6 +4,7 @@ xmlns="http://www.w3.org/1999/xhtml" xmlns:var="http://www.skyrix.com/od/binding" xmlns:const="http://www.skyrix.com/od/constant" + xmlns:label="OGo:label" className="UIxPageFrame" title="title" const:userDefaultsKeys="SOGoMailMessageCheck,SOGoRefreshViewCheck,SOGoMailSortByThreads,SOGoMailListViewColumnsOrder,SOGoMailDisplayRemoteInlineImages,SOGoMailComposeMessageType,SOGoMailReplyPlacement" @@ -323,17 +324,20 @@
-
+
- - + +
- - ALL + + + + + + diff --git a/UI/WebServerResources/js/Mailer/mailbox-model.js b/UI/WebServerResources/js/Mailer/mailbox-model.js index 52f96cff0..f9e1c8169 100644 --- a/UI/WebServerResources/js/Mailer/mailbox-model.js +++ b/UI/WebServerResources/js/Mailer/mailbox-model.js @@ -73,7 +73,7 @@ Mailbox.$find = function(account) { var path, futureMailboxData; - futureMailboxData = this.$$resource.post(account.id, 'view', {sortingAttributes: {sort: 'date', asc: false}}); + futureMailboxData = this.$$resource.fetch(account.id.toString(), 'view'); return Mailbox.$unwrapCollection(account, futureMailboxData); // a collection of mailboxes }; @@ -113,7 +113,7 @@ * @memberof Mailbox * @desc Build the path of the mailbox (or account only). * @param {string} accountId - the account ID - * @param {string} [mailboxPath] - an array of the mailbox path components + * @param {string} [mailboxPath] - the mailbox path * @returns a string representing the path relative to the mail module */ Mailbox.$absolutePath = function(accountId, mailboxPath) { @@ -141,15 +141,44 @@ }; /** - * @function $reload + * @function $filter * @memberof Mailbox.prototype - * @desc Fetch the messages metadata of the mailbox. + * @desc Fetch the messages metadata of the mailbox + * @param {object} [sort] - sort preferences. Defaults to descendent by date. + * @param {string} sort.match - either AND or OR + * @param {string} sort.sort - either arrival, subject, from, to, date, or size + * @param {boolean} sort.asc - sort is ascendant if true + * @param {object[]} [filers] - list of filters for the query + * @param {string} filers.searchBy - either subject, from, to, cc, or body + * @param {string} filers.searchInput - the search string to match + * @param {boolean} filers.negative - negate the condition * @returns a promise of the HTTP operation */ - Mailbox.prototype.$reload = function() { - var futureMailboxData; + Mailbox.prototype.$filter = function(sort, filters) { + var futureMailboxData, options; - futureMailboxData = Mailbox.$$resource.post(this.id, 'view', {sortingAttributes: {sort: 'date', asc: false}}); + if (!angular.isDefined(sort)) { + sort = { sortingAttributes: { match: 'OR', sort: 'date', asc: false } }; + } + options = { sortingAttributes: sort }; + if (angular.isDefined(filters)) { + options.filters = _.reject(filters, function(filter) { + return angular.isUndefined(filter.searchInput) || filter.searchInput.length == 0; + }); + _.each(options.filters, function(filter) { + var secondFilter, + match = filter.searchBy.match(/(\w+)_or_(\w+)/); + if (match) { + options.sortingAttributes.match = 'OR'; + filter.searchBy = match[1]; + secondFilter = angular.copy(filter); + secondFilter.searchBy = match[2]; + options.filters.push(secondFilter); + } + }); + } + + futureMailboxData = Mailbox.$$resource.post(this.id, 'view', options); return this.$unwrap(futureMailboxData); }; diff --git a/UI/WebServerResources/js/MailerUI.js b/UI/WebServerResources/js/MailerUI.js index 7a93bc4cb..ad111caf4 100644 --- a/UI/WebServerResources/js/MailerUI.js +++ b/UI/WebServerResources/js/MailerUI.js @@ -89,7 +89,7 @@ return _find(stateAccount.$mailboxes); }], stateMessages: ['stateMailbox', function(stateMailbox) { - return stateMailbox.$reload(); + return stateMailbox.$filter(); }] } }) @@ -235,7 +235,7 @@ .controller('MailboxCtrl', ['$scope', '$rootScope', '$stateParams', 'stateAccount', 'stateMailbox', '$timeout', 'sgFocus', 'sgDialog', 'sgAccount', 'sgMailbox', function($scope, $rootScope, $stateParams, stateAccount, stateMailbox, $timeout, focus, Dialog, Account, Mailbox) { $scope.account = stateAccount; - $scope.mailbox = stateMailbox; + $rootScope.mailbox = stateMailbox; $rootScope.currentFolder = stateMailbox; $timeout(function() { $rootScope.$broadcast('sgSelectFolder', stateMailbox.id);