salix/front/core/directives/dialog.js

26 lines
752 B
JavaScript

import ngModule from '../module';
import Dialog from '../components/dialog/dialog';
import {kebabToCamel} from '../lib/string';
/**
* Registers a click handler on the element that opens the dialog id
* specified as value.
*
* @return {Object} The directive
*/
export default function directive() {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
let dialogKey = kebabToCamel($attrs.vnDialog);
let dialog = $scope[dialogKey];
if (dialog instanceof Dialog)
dialog.show();
event.preventDefault();
});
}
};
}
ngModule.directive('vnDialog', directive);