From 77ce13967c7d66ac6501d95522375c87542813e7 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 7 Jun 2016 11:08:06 -0400 Subject: [PATCH] (js) Improve $scope.$watch --- UI/WebServerResources/js/Common/sgAvatarImage.directive.js | 4 ++-- UI/WebServerResources/js/Mailer/MessageController.js | 7 ++++--- UI/WebServerResources/js/Scheduler/CalendarsController.js | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/UI/WebServerResources/js/Common/sgAvatarImage.directive.js b/UI/WebServerResources/js/Common/sgAvatarImage.directive.js index 1c568b232..5bfecd038 100644 --- a/UI/WebServerResources/js/Common/sgAvatarImage.directive.js +++ b/UI/WebServerResources/js/Common/sgAvatarImage.directive.js @@ -56,7 +56,7 @@ // Wait on user's defaults Preferences.ready().then(function() { - $scope.$watch('vm.email', function(email, old) { + $scope.$watch(function() { return vm.email; }, function(email, old) { if (email && vm.urlEmail != email) { // Email has changed or doesn't match the current URL (this happens when using md-virtual-repeat) showGenericAvatar(); @@ -70,7 +70,7 @@ // If sg-src is defined, watch the expression for the URL of a local image if ('sg-src' in $element[0].attributes) { - $scope.$watch('vm.src', function(src) { + $scope.$watch(function() { return vm.src; }, function(src) { if (src) { // Set image URL and save the associated email address vm.url = src; diff --git a/UI/WebServerResources/js/Mailer/MessageController.js b/UI/WebServerResources/js/Mailer/MessageController.js index 43cfa622f..2904cf394 100644 --- a/UI/WebServerResources/js/Mailer/MessageController.js +++ b/UI/WebServerResources/js/Mailer/MessageController.js @@ -42,19 +42,20 @@ // One-way refresh of the parent window when modifying the message from a popup window. if ($window.opener) { // Update the message flags. The message must be displayed in the parent window. - $scope.$watchCollection('viewer.message.flags', function(newTags, oldTags) { + $scope.$watchCollection(function() { return vm.message.flags; }, function(newTags, oldTags) { var ctrls; if (newTags || oldTags) { ctrls = $parentControllers(); if (ctrls.messageCtrl) { ctrls.messageCtrl.service.$timeout(function() { + ctrls.messageCtrl.showFlags = true; ctrls.messageCtrl.message.flags = newTags; }); } } }); // Update the "isflagged" (star icon) of the message. The mailbox must be displayed in the parent window. - $scope.$watch('viewer.message.isflagged', function(isflagged, wasflagged) { + $scope.$watch(function() { return vm.message.isflagged; }, function(isflagged, wasflagged) { var ctrls = $parentControllers(); if (ctrls.mailboxCtrl) { ctrls.mailboxCtrl.service.$timeout(function() { @@ -67,7 +68,7 @@ else { // Flatten new tags when coming from the predefined list of tags (Message.$tags) and // sync tags with server when adding or removing a tag. - $scope.$watchCollection('viewer.message.flags', function(_newTags, _oldTags) { + $scope.$watchCollection(function() { return vm.message.flags; }, function(_newTags, _oldTags) { var newTags, oldTags, tags; if (_newTags || _oldTags) { newTags = _newTags || []; diff --git a/UI/WebServerResources/js/Scheduler/CalendarsController.js b/UI/WebServerResources/js/Scheduler/CalendarsController.js index ea9cb745f..680fe36d1 100644 --- a/UI/WebServerResources/js/Scheduler/CalendarsController.js +++ b/UI/WebServerResources/js/Scheduler/CalendarsController.js @@ -348,7 +348,7 @@ vm.saveProperties = saveProperties; vm.close = close; - $scope.$watch('properties.calendar.color', function() { + $scope.$watch(function() { return vm.calendar.color; }, function() { srcCalendar.color = vm.calendar.color; });