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';
|
2017-02-06 17:01:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-02-06 17:01:04 +00:00
|
|
|
*/
|
2018-05-22 09:44:24 +00:00
|
|
|
export default function directive() {
|
2017-02-06 17:01:04 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function($scope, $element, $attrs) {
|
|
|
|
$element.on('click', function(event) {
|
2017-10-23 08:47:56 +00:00
|
|
|
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-02-06 17:01:04 +00:00
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
2017-05-16 10:37:48 +00:00
|
|
|
};
|
2017-02-06 17:01:04 +00:00
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.directive('vnDialog', directive);
|