33 lines
899 B
JavaScript
33 lines
899 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', () => {
|
|
const controller = element.$ctrl;
|
|
controller.$oldDisabled = controller.disabled;
|
|
controller.disabled = true;
|
|
|
|
cb($scope).finally(() => {
|
|
if (!controller.$oldDisabled)
|
|
controller.disabled = false;
|
|
});
|
|
});
|
|
}
|
|
};
|
|
}
|
|
|
|
directive.$inject = ['$parse'];
|
|
|
|
ngModule.directive('vnHttpClick', directive);
|