Bug #124 address observations validations

This commit is contained in:
Daniel Herrero 2018-03-07 13:34:34 +01:00
parent 0bf4e292a1
commit 78f893b811
3 changed files with 26 additions and 27 deletions

View File

@ -61,29 +61,36 @@
<tpl-item>{{$parent.$parent.item.description}}</tpl-item> <tpl-item>{{$parent.$parent.item.description}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
<vn-textfield <vn-textfield
vn-auto vn-two
margin-large-right
label="Description" label="Description"
model="observation.description" model="observation.description"
rule="addressObservation.description"> rule="addressObservation.description">
</vn-textfield> </vn-textfield>
<vn-one pad-medium-top> <vn-auto pad-medium-top>
<vn-icon <vn-icon
pointer pointer
medium-grey medium-grey
vn-tooltip="Remove note"
tooltip-position = "left"
icon="remove_circle_outline" icon="remove_circle_outline"
ng-click="$ctrl.removeObservation($index)"> ng-click="$ctrl.removeObservation($index)">
</vn-icon> </vn-icon>
</vn-one>
</vn-horizontal>
</vn-one>
<vn-one>
<vn-icon <vn-icon
pointer pointer
margin-medium-left margin-medium-left
vn-tooltip="Add note"
tooltip-position = "right"
orange orange
icon="add_circle" icon="add_circle"
ng-if="observation.showAddIcon && observationsTypes.model.length > $ctrl.observations.length" ng-if="observationsTypes.model.length > $ctrl.observations.length"
ng-click="$ctrl.addObservation()"> ng-click="$ctrl.addObservation()">
</vn-icon> </vn-icon>
</vn-one> </vn-one>
</vn-horizontal>
</vn-one>
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>
<vn-submit label="Save"></vn-submit> <vn-submit label="Save"></vn-submit>

View File

@ -17,18 +17,6 @@ export default class Controller {
this.observationsRemoved = []; this.observationsRemoved = [];
} }
_setIconAdd() {
if (this.observations.length) {
this.observations.map(element => {
element.showAddIcon = false;
return true;
});
this.observations[this.observations.length - 1].showAddIcon = true;
} else {
this.addObservation();
}
}
_setDirtyForm() { _setDirtyForm() {
if (this.$scope.form) { if (this.$scope.form) {
this.$scope.form.$setDirty(); this.$scope.form.$setDirty();
@ -41,15 +29,13 @@ export default class Controller {
} }
addObservation() { addObservation() {
this.observations.push({observationTypeFk: null, addressFk: this.address.id, description: null, showAddIcon: true}); this.observations.push({observationTypeFk: null, addressFk: this.address.id, description: null});
this._setIconAdd();
} }
removeObservation(index) { removeObservation(index) {
let item = this.observations[index]; let item = this.observations[index];
if (item) { if (item) {
this.observations.splice(index, 1); this.observations.splice(index, 1);
this._setIconAdd();
if (item.id) { if (item.id) {
this.observationsRemoved.push(item.id); this.observationsRemoved.push(item.id);
this._setDirtyForm(); this._setDirtyForm();
@ -65,7 +51,10 @@ export default class Controller {
} }
submit() { submit() {
this._unsetDirtyForm(); if (this.$scope.form.$invalid) {
return false;
}
let canWatcherSubmit = this.$scope.watcher.dataChanged(); let canWatcherSubmit = this.$scope.watcher.dataChanged();
let canObservationsSubmit; let canObservationsSubmit;
let repeatedTypes = false; let repeatedTypes = false;
@ -118,6 +107,7 @@ export default class Controller {
this.$translate.instant('No changes to save') this.$translate.instant('No changes to save')
); );
} }
this._unsetDirtyForm();
} }
$onInit() { $onInit() {

View File

@ -3,3 +3,5 @@ Is equalizated: Recargo de equivalencia
Observation type: Tipo de observación Observation type: Tipo de observación
Description: Descripción Description: Descripción
The observation type must be unique: El tipo de observación ha de ser único The observation type must be unique: El tipo de observación ha de ser único
Add note: Añadir nota
Remove note: Quitar nota