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>
</vn-autocomplete>
<vn-textfield
vn-auto
vn-two
margin-large-right
label="Description"
model="observation.description"
rule="addressObservation.description">
</vn-textfield>
<vn-one pad-medium-top>
<vn-auto pad-medium-top>
<vn-icon
pointer
medium-grey
vn-tooltip="Remove note"
tooltip-position = "left"
icon="remove_circle_outline"
ng-click="$ctrl.removeObservation($index)">
</vn-icon>
<vn-icon
pointer
margin-medium-left
orange
icon="add_circle"
ng-if="observation.showAddIcon && observationsTypes.model.length > $ctrl.observations.length"
ng-click="$ctrl.addObservation()">
</vn-icon>
</vn-one>
</vn-horizontal>
</vn-one>
<vn-one>
<vn-icon
pointer
margin-medium-left
vn-tooltip="Add note"
tooltip-position = "right"
orange
icon="add_circle"
ng-if="observationsTypes.model.length > $ctrl.observations.length"
ng-click="$ctrl.addObservation()">
</vn-icon>
</vn-one>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>

View File

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

View File

@ -2,4 +2,6 @@ Enabled: Activo
Is equalizated: Recargo de equivalencia
Observation type: Tipo de observació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