salix/front/core/directives/dialog.js

26 lines
757 B
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../module';
2019-10-26 23:30:01 +00:00
import Dialog from '../components/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
*/
export default function directive() {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
2019-10-24 08:17:32 +00:00
if (event.defaultPrevented) return;
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();
});
}
2017-05-16 10:37:48 +00:00
};
}
2018-02-10 15:18:01 +00:00
ngModule.directive('vnDialog', directive);