From e8e69ad32d6d4962aba12067488045c07ca9fa24 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 1 Dec 2014 17:33:09 +0100 Subject: [PATCH] Broadcast search event from action bar to filter mail-list --- src/js/controller/app/action-bar.js | 7 +++++++ src/js/controller/app/mail-list.js | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/js/controller/app/action-bar.js b/src/js/controller/app/action-bar.js index 79a377d..b997975 100644 --- a/src/js/controller/app/action-bar.js +++ b/src/js/controller/app/action-bar.js @@ -156,6 +156,13 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) { return message.checked; }); } + + /** + * This method is called when the user changes the searchText + */ + $scope.displaySearchResults = function(searchText) { + $scope.$root.$broadcast('search', searchText); + }; }; module.exports = ActionBarCtrl; \ No newline at end of file diff --git a/src/js/controller/app/mail-list.js b/src/js/controller/app/mail-list.js index 562ee38..5010981 100644 --- a/src/js/controller/app/mail-list.js +++ b/src/js/controller/app/mail-list.js @@ -105,7 +105,7 @@ var MailListCtrl = function($scope, $timeout, $routeParams, $filter, statusDispl var now = new Date(); // return time if mail is from today - if(now.getDay() === date.getDay() && now.getMonth() === date.getMonth() && now.getFullYear() === date.getFullYear()) { + if (now.getDay() === date.getDay() && now.getMonth() === date.getMonth() && now.getFullYear() === date.getFullYear()) { return $filter('date')(date, 'shortTime'); } @@ -177,6 +177,13 @@ var MailListCtrl = function($scope, $timeout, $routeParams, $filter, statusDispl Array.prototype.push.apply($scope.displayMessages, next); }; + /** + * Handle search event in other parts of the app by filtering messages in the mail-list + */ + $scope.$on('search', function(e, query) { + $scope.displaySearchResults(query); + }); + /** * This method is called when the user changes the searchText */