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

23 lines
651 B
JavaScript
Raw Normal View History

import {module} from '../module';
2017-05-31 07:46:05 +00:00
import Dialog from '../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.
*/
2017-05-16 10:37:48 +00:00
export function directive() {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
2017-05-16 10:37:48 +00:00
let dialog = $scope[kebabToCamel($attrs.vnDialog)];
if (dialog instanceof Dialog)
2017-02-07 13:34:26 +00:00
dialog.show();
event.preventDefault();
});
}
2017-05-16 10:37:48 +00:00
};
}
module.directive('vnDialog', directive);