From 1a68f4c60ddd4ec104d27ae933a3844175d6c5fb Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Sat, 20 Dec 2014 13:11:26 +0800 Subject: [PATCH] Add watcher on the calling scope in watchAndUpdateRevision. Fix #79. --- omega-web/src/omega/controllers/master.coffee | 1 - .../src/omega/controllers/profile.coffee | 24 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/omega-web/src/omega/controllers/master.coffee b/omega-web/src/omega/controllers/master.coffee index 0a51aec..3e710df 100644 --- a/omega-web/src/omega/controllers/master.coffee +++ b/omega-web/src/omega/controllers/master.coffee @@ -238,7 +238,6 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window, onOptionChange = (options, oldOptions) -> return if options == oldOptions or not oldOptions? - plainOptions = angular.fromJson(angular.toJson(options)) $rootScope.optionsDirty = true $rootScope.$watch 'options', onOptionChange, true diff --git a/omega-web/src/omega/controllers/profile.coffee b/omega-web/src/omega/controllers/profile.coffee index 9a71f04..f15f9c7 100644 --- a/omega-web/src/omega/controllers/profile.coffee +++ b/omega-web/src/omega/controllers/profile.coffee @@ -70,6 +70,19 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams, break $state.go('ui') + # The watcher should be applied on the calling scope. + # coffeelint: disable=missing_fat_arrows + $scope.watchAndUpdateRevision = (expression) -> + revisionChanged = false + onChange = (profile, oldProfile) -> + return profile if profile == oldProfile or not profile or not oldProfile + if revisionChanged and profile.revision != oldProfile.revision + revisionChanged = false + else + OmegaPac.Profiles.updateRevision(profile) + revisionChanged = true + this.$watch expression, onChange, true + unwatch = $scope.$watch (-> $scope.options?['+' + name]), (profile) -> if not profile if $scope.options @@ -92,15 +105,4 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams, $scope.profileTemplate = 'partials/' + templ $scope.scriptable = true - $scope.watchAndUpdateRevision = (expression) -> - revisionChanged = false - onChange = (profile, oldProfile) -> - return profile if profile == oldProfile or not profile or not oldProfile - if revisionChanged and profile.revision != oldProfile.revision - revisionChanged = false - else - OmegaPac.Profiles.updateRevision(profile) - revisionChanged = true - $scope.$watch expression, onChange, true - $scope.watchAndUpdateRevision 'profile'