From 7fd6c850d7616da1460cd2fca8f0a72ea641c66f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 20 Jun 2019 13:50:58 +0200 Subject: [PATCH 1/2] lock controls #1533 --- e2e/helpers/selectors.js | 2 +- front/core/components/submit/submit.js | 8 +- front/core/directives/http-click.js | 29 +++++ front/core/directives/http-submit.js | 37 +++++++ front/core/directives/index.js | 2 + modules/agency/front/create/index.html | 2 +- modules/agency/front/create/index.js | 2 +- modules/claim/front/action/index.html | 7 +- modules/claim/front/action/index.js | 4 +- modules/claim/front/development/index.html | 2 +- modules/client/front/basic-data/index.html | 120 +++++++++++---------- modules/ticket/front/sale/index.html | 2 +- modules/ticket/front/sale/index.js | 2 +- 13 files changed, 145 insertions(+), 74 deletions(-) create mode 100644 front/core/directives/http-click.js create mode 100644 front/core/directives/http-submit.js 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">
-
+ { + return this.$scope.watcher.submit().then(res => { this.$state.go('zone.card.location', {id: res.data.id}); }); } diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 4d0de4d1d..acee9b3e6 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -18,7 +18,7 @@ - {{$ctrl.resolvedStateText}} + disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedState" + vn-http-click="$ctrl.regularize()">