refactor(newbankentity): the component now extends from Dialog
This commit is contained in:
parent
e81c1046f6
commit
47e70f7c3c
|
@ -1,49 +1,46 @@
|
|||
<vn-dialog class="edit"
|
||||
vn-id="bankEntityDialog"
|
||||
on-open="$ctrl.resetData()"
|
||||
on-accept="$ctrl.onAccept()"
|
||||
message="New bank entity">
|
||||
<tpl-body>
|
||||
<p translate>Please, ensure you put the correct data!</p>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
vn-focus
|
||||
vn-id="entityName"
|
||||
label="Name"
|
||||
ng-model="$ctrl.data.name"
|
||||
required="true">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
vn-focus
|
||||
vn-id="bic"
|
||||
label="Swift"
|
||||
ng-model="$ctrl.data.bic"
|
||||
required="true">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
vn-id="country"
|
||||
ng-model="$ctrl.data.countryFk"
|
||||
url="Countries"
|
||||
fields="['id', 'country', 'code']"
|
||||
show-field="country"
|
||||
value-field="id"
|
||||
label="Country">
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
ng-show="country.selection.code === 'ES'"
|
||||
label="Entity code"
|
||||
ng-model="$ctrl.data.id">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button id="saveBankEntity" response="accept" translate>Save</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
||||
<tpl-title translate>
|
||||
New bank entity
|
||||
</tpl-title>
|
||||
<tpl-body>
|
||||
<p translate>Please, ensure you put the correct data!</p>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
vn-focus
|
||||
vn-id="entityName"
|
||||
label="Name"
|
||||
ng-model="$ctrl.data.name"
|
||||
required="true">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
vn-focus
|
||||
vn-id="bic"
|
||||
label="Swift"
|
||||
ng-model="$ctrl.data.bic"
|
||||
required="true">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
vn-id="country"
|
||||
ng-model="$ctrl.data.countryFk"
|
||||
url="Countries"
|
||||
fields="['id', 'country', 'code']"
|
||||
show-field="country"
|
||||
value-field="id"
|
||||
label="Country">
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
ng-show="country.selection.code === 'ES'"
|
||||
label="Entity code"
|
||||
ng-model="$ctrl.data.id">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Accept</button>
|
||||
</tpl-buttons>
|
|
@ -1,35 +1,23 @@
|
|||
import ngModule from '../../module';
|
||||
import Component from 'core/lib/component';
|
||||
import Dialog from 'core/components/dialog';
|
||||
import './style.scss';
|
||||
|
||||
class Controller extends Component {
|
||||
open() {
|
||||
this.$.bankEntityDialog.show();
|
||||
}
|
||||
class Controller extends Dialog {
|
||||
responseHandler(response) {
|
||||
if (response !== 'accept')
|
||||
return super.responseHandler(response);
|
||||
|
||||
resetData() {
|
||||
this.data = {};
|
||||
}
|
||||
if (!this.data.countryFk)
|
||||
throw new Error(`The country can't be empty`);
|
||||
|
||||
onAccept() {
|
||||
try {
|
||||
if (!this.data.countryFk)
|
||||
throw new Error(`The country can't be empty`);
|
||||
|
||||
this.$http.post(`bankEntities`, this.data).then(res => {
|
||||
this.vnApp.showMessage(this.$t('The bank entity has been created. You can save the data now'));
|
||||
this.emit('response', {$response: res.data});
|
||||
});
|
||||
} catch (e) {
|
||||
this.vnApp.showError(this.$t(e.message));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return this.$http.post(`bankEntities`, this.data)
|
||||
.then(res => super.responseHandler(response))
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnNewBankEntity', {
|
||||
template: require('./index.html'),
|
||||
slotTemplate: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
data: '<',
|
||||
|
|
Loading…
Reference in New Issue