mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 03:45:01 -02:30
Watch model param for changes in link-to directive
This commit is contained in:
@@ -53,6 +53,11 @@ export default
|
|||||||
'transitionTo',
|
'transitionTo',
|
||||||
function($routeProvider, $location, transitionTo) {
|
function($routeProvider, $location, transitionTo) {
|
||||||
|
|
||||||
|
function transitionListener(routeName, model, e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
transitionTo(routeName, model);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope: {
|
scope: {
|
||||||
@@ -60,16 +65,25 @@ export default
|
|||||||
model: '&'
|
model: '&'
|
||||||
},
|
},
|
||||||
link: function (scope, element, attrs) {
|
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) {
|
var listener;
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
scope.$watch(function() {
|
||||||
transitionTo(scope.routeName, model);
|
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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user