30 lines
738 B
JavaScript
30 lines
738 B
JavaScript
|
import ngModule from '../module';
|
||
|
|
||
|
/**
|
||
|
* Disables a clicked element while request is being processed
|
||
|
* Enables again when promise ends
|
||
|
*
|
||
|
* @param {Object} $parse
|
||
|
* @return {Object} The directive
|
||
|
*/
|
||
|
export function directive($parse) {
|
||
|
return {
|
||
|
restrict: 'A',
|
||
|
link: function($scope, $element, $attrs) {
|
||
|
const cb = $parse($attrs.vnHttpClick);
|
||
|
const element = $element[0];
|
||
|
$element.on('click', () => {
|
||
|
element.$ctrl.disabled = true;
|
||
|
|
||
|
cb($scope).finally(() => {
|
||
|
element.$ctrl.disabled = false;
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
directive.$inject = ['$parse'];
|
||
|
|
||
|
ngModule.directive('vnHttpClick', directive);
|