salix/client/core/src/directives/dialog.js

26 lines
744 B
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../module';
import Dialog from '../components/dialog/dialog';
2017-02-07 13:34:26 +00:00
import {kebabToCamel} from '../lib/string';
/**
* Registers a click handler on the element that opens the dialog id
* specified as value.
2018-02-10 15:18:01 +00:00
*
* @return {Object} The directive
*/
2017-05-16 10:37:48 +00:00
export function directive() {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
let dialogKey = kebabToCamel($attrs.vnDialog);
let dialog = $scope[dialogKey];
2017-05-16 10:37:48 +00:00
if (dialog instanceof Dialog)
2017-02-07 13:34:26 +00:00
dialog.show();
event.preventDefault();
});
}
2017-05-16 10:37:48 +00:00
};
}
2018-02-10 15:18:01 +00:00
ngModule.directive('vnDialog', directive);