mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
Watch model param for changes in link-to directive
This commit is contained in:
parent
9d95020bf5
commit
66cb2aaec0
@ -53,6 +53,11 @@ export default
|
||||
'transitionTo',
|
||||
function($routeProvider, $location, transitionTo) {
|
||||
|
||||
function transitionListener(routeName, model, e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
transitionTo(routeName, model);
|
||||
}
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
@ -60,16 +65,25 @@ export default
|
||||
model: '&'
|
||||
},
|
||||
link: function (scope, element, attrs) {
|
||||
var model = scope.$eval(scope.model);
|
||||
scope.url = lookupRouteUrl(scope.routeName, $routeProvider.routes, model, $location.$$html5);
|
||||
|
||||
element.find('[data-transition-to]').on('click', function(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
transitionTo(scope.routeName, model);
|
||||
});
|
||||
var listener;
|
||||
|
||||
scope.$watch(function() {
|
||||
var model = scope.$eval(scope.model);
|
||||
return model;
|
||||
}, function(newValue) {
|
||||
|
||||
var model = scope.$eval(scope.model);
|
||||
scope.url = lookupRouteUrl(scope.routeName, $routeProvider.routes, model, $location.$$html5);
|
||||
element.off('click', listener);
|
||||
|
||||
listener = _.partial(transitionListener, scope.routeName, model);
|
||||
|
||||
element.on('click', listener);
|
||||
|
||||
element.attr('href', scope.url);
|
||||
}, true);
|
||||
|
||||
element.attr('href', scope.url);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user