2019-06-20 11:50:58 +00:00
|
|
|
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', () => {
|
2020-02-20 08:32:47 +00:00
|
|
|
const controller = element.$ctrl;
|
|
|
|
controller.$oldDisabled = field.$ctrl.disabled;
|
|
|
|
controller.disabled = true;
|
2019-06-20 11:50:58 +00:00
|
|
|
|
|
|
|
cb($scope).finally(() => {
|
2020-02-20 08:32:47 +00:00
|
|
|
if (!controller.$oldDisabled)
|
|
|
|
controller.disabled = false;
|
2019-06-20 11:50:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
directive.$inject = ['$parse'];
|
|
|
|
|
|
|
|
ngModule.directive('vnHttpClick', directive);
|