diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 9201c90ec..470d2152f 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -90,7 +90,7 @@ export default { newBankEntityButton: 'vn-client-billing-data vn-icon-button[vn-tooltip="New bank entity"] > button', newBankEntityName: 'vn-client-billing-data > vn-dialog vn-textfield[label="Name"] input', newBankEntityBIC: 'vn-client-billing-data > vn-dialog vn-textfield[label="Swift / BIC"] input', - newBankEntityCode: 'vn-client-billing-data > vn-dialog vn-textfield[label="Code"] input', + newBankEntityCode: 'vn-client-billing-data > vn-dialog vn-textfield[label="Entity Code"] input', acceptBankEntityButton: 'vn-client-billing-data > vn-dialog button[response="ACCEPT"]', saveButton: `${components.vnSubmit}` }, diff --git a/front/core/components/submit/submit.js b/front/core/components/submit/submit.js index c1199d033..41d63cf1d 100644 --- a/front/core/components/submit/submit.js +++ b/front/core/components/submit/submit.js @@ -1,7 +1,9 @@ import ngModule from '../../module'; +import Input from '../../lib/input'; -export default class Controller { - constructor($element) { +export default class Controller extends Input { + constructor($element, $scope) { + super($element, $scope); this.$element = $element; this.input = $element[0].querySelector('input'); } @@ -11,7 +13,7 @@ export default class Controller { } } -Controller.$inject = ['$element']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnSubmit', { template: require('./submit.html'), diff --git a/front/core/directives/http-click.js b/front/core/directives/http-click.js new file mode 100644 index 000000000..5e69d81d1 --- /dev/null +++ b/front/core/directives/http-click.js @@ -0,0 +1,29 @@ +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); diff --git a/front/core/directives/http-submit.js b/front/core/directives/http-submit.js new file mode 100644 index 000000000..0cf17866e --- /dev/null +++ b/front/core/directives/http-submit.js @@ -0,0 +1,37 @@ +import ngModule from '../module'; + +/** + * Disables a submitted form 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.vnHttpSubmit); + const element = $element[0]; + $element.on('submit', () => { + const selector = 'vn-textfield, vn-autocomplete, vn-submit'; + const elements = element.querySelectorAll(selector); + const fields = angular.element(elements); + + angular.forEach(fields, field => { + field.$ctrl.disabled = true; + }); + + cb($scope).finally(() => { + angular.forEach(fields, field => { + field.$ctrl.disabled = false; + }); + }); + }); + } + }; +} + +directive.$inject = ['$parse']; + +ngModule.directive('vnHttpSubmit', directive); diff --git a/front/core/directives/index.js b/front/core/directives/index.js index 7db806caf..08adfac07 100644 --- a/front/core/directives/index.js +++ b/front/core/directives/index.js @@ -13,3 +13,5 @@ import './title'; import './uvc'; import './draggable'; import './droppable'; +import './http-click'; +import './http-submit'; diff --git a/modules/agency/front/create/index.html b/modules/agency/front/create/index.html index d25c91219..461829259 100644 --- a/modules/agency/front/create/index.html +++ b/modules/agency/front/create/index.html @@ -6,7 +6,7 @@ save="post">