Add watcher on the calling scope in watchAndUpdateRevision. Fix #79.

This commit is contained in:
FelisCatus 2014-12-20 13:11:26 +08:00
parent a3df567b4d
commit 1a68f4c60d
2 changed files with 13 additions and 12 deletions

View File

@ -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

View File

@ -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'