corrected bug on all htmls using crud
This commit is contained in:
parent
ece2fd384d
commit
945a1b3049
|
@ -54,6 +54,7 @@
|
|||
<mg-ajax path="/client/api/ObservationTypes" options="mgIndex as observationsTypes"></mg-ajax>
|
||||
<vn-horizontal ng-repeat="observation in $ctrl.observations track by $index">
|
||||
<vn-autocomplete
|
||||
ng-if="!observation.id"
|
||||
vn-one
|
||||
initial-data="observation.observationType"
|
||||
field="observation.observationTypeFk"
|
||||
|
@ -61,6 +62,13 @@
|
|||
show-field="description"
|
||||
label="Observation type">
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
ng-if="observation.id"
|
||||
vn-one
|
||||
label="Observation type"
|
||||
model="observation.observationType.description"
|
||||
disabled="true">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-two
|
||||
margin-large-right
|
||||
|
|
|
@ -13,8 +13,8 @@ export default class Controller {
|
|||
id: parseInt($state.params.addressId)
|
||||
};
|
||||
this.observations = [];
|
||||
this.observationsOld = {};
|
||||
this.observationsRemoved = [];
|
||||
this.oldObservations = {};
|
||||
this.removedObservations = [];
|
||||
}
|
||||
|
||||
_setDirtyForm() {
|
||||
|
@ -22,6 +22,7 @@ export default class Controller {
|
|||
this.$scope.form.$setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
_unsetDirtyForm() {
|
||||
if (this.$scope.form) {
|
||||
this.$scope.form.$setPristine();
|
||||
|
@ -37,16 +38,17 @@ export default class Controller {
|
|||
if (item) {
|
||||
this.observations.splice(index, 1);
|
||||
if (item.id) {
|
||||
this.observationsRemoved.push(item.id);
|
||||
this.removedObservations.push(item.id);
|
||||
this._setDirtyForm();
|
||||
}
|
||||
}
|
||||
if (this.observations.length === 0 && Object.keys(this.observationsOld).length === 0) {
|
||||
if (this.observations.length === 0 && Object.keys(this.oldObservations).length === 0) {
|
||||
this._unsetDirtyForm();
|
||||
}
|
||||
}
|
||||
_submitObservations(objectObservations) {
|
||||
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, objectObservations);
|
||||
|
||||
_submitObservations(observationsObject) {
|
||||
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, observationsObject);
|
||||
}
|
||||
|
||||
_observationsEquals(ob1, ob2) {
|
||||
|
@ -58,12 +60,12 @@ export default class Controller {
|
|||
return false;
|
||||
}
|
||||
|
||||
let canWatcherSubmit = this.$scope.watcher.dataChanged();
|
||||
let canObservationsSubmit;
|
||||
let canSubmitWatcher = this.$scope.watcher.dataChanged();
|
||||
let canSubmitObservations;
|
||||
let repeatedTypes = false;
|
||||
let types = [];
|
||||
let observationsObj = {
|
||||
delete: this.observationsRemoved,
|
||||
delete: this.removedObservations,
|
||||
create: [],
|
||||
update: []
|
||||
};
|
||||
|
@ -82,26 +84,26 @@ export default class Controller {
|
|||
|
||||
if (isNewObservation && observation.observationTypeFk && observation.description) {
|
||||
observationsObj.create.push(observation);
|
||||
} else if (!isNewObservation && !this._observationsEquals(this.observationsOld[observation.id], observation)) {
|
||||
} else if (!isNewObservation && !this._observationsEquals(this.oldObservations[observation.id], observation)) {
|
||||
observationsObj.update.push(observation);
|
||||
}
|
||||
}
|
||||
|
||||
canObservationsSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
||||
canSubmitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
||||
|
||||
if (repeatedTypes) {
|
||||
this.vnApp.showMessage(
|
||||
this.$translate.instant('The observation type must be unique')
|
||||
);
|
||||
} else if (canWatcherSubmit && !canObservationsSubmit) {
|
||||
} else if (canSubmitWatcher && !canSubmitObservations) {
|
||||
this.$scope.watcher.submit().then(() => {
|
||||
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
||||
});
|
||||
} else if (!canWatcherSubmit && canObservationsSubmit) {
|
||||
} else if (!canSubmitWatcher && canSubmitObservations) {
|
||||
this._submitObservations(observationsObj).then(() => {
|
||||
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
||||
});
|
||||
} else if (canWatcherSubmit && canObservationsSubmit) {
|
||||
} else if (canSubmitWatcher && canSubmitObservations) {
|
||||
this.$q.all([this.$scope.watcher.submit(), this._submitObservations(observationsObj)]).then(() => {
|
||||
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
||||
});
|
||||
|
@ -113,7 +115,7 @@ export default class Controller {
|
|||
this._unsetDirtyForm();
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
_getAddressNotes() {
|
||||
let filter = {
|
||||
where: {addressFk: this.address.id},
|
||||
include: {relation: 'observationType'}
|
||||
|
@ -121,10 +123,14 @@ export default class Controller {
|
|||
this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => {
|
||||
this.observations = res.data;
|
||||
res.data.forEach(item => {
|
||||
this.observationsOld[item.id] = Object.assign({}, item);
|
||||
this.oldObservations[item.id] = Object.assign({}, item);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this._getAddressNotes();
|
||||
}
|
||||
}
|
||||
Controller.$inject = ['$state', '$scope', '$http', '$q', '$translate', 'vnApp'];
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<div
|
||||
<div
|
||||
class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"
|
||||
ng-mouseenter="$ctrl.hasMouseIn = true"
|
||||
ng-mouseleave="$ctrl.hasMouseIn = false">
|
||||
<input
|
||||
<input
|
||||
class="mdl-textfield__input"
|
||||
type="{{$ctrl.type}}"
|
||||
name="{{$ctrl.name}}"
|
||||
|
@ -11,7 +11,7 @@
|
|||
ng-disabled="$ctrl.disabled"
|
||||
ng-readonly="$ctrl.readonly"
|
||||
ng-focus="$ctrl.hasFocus = true"
|
||||
ng-blur="$ctrl.hasFocus = false"/>
|
||||
ng-blur="$ctrl.hasFocus = false"/>
|
||||
<div class="mdl-chip__action">
|
||||
<i class="material-icons"
|
||||
ng-if="$ctrl.hasInfo"
|
||||
|
|
|
@ -13,6 +13,7 @@ export default class Controller {
|
|||
this.removedBarcodes = [];
|
||||
this.oldBarcodes = {};
|
||||
}
|
||||
|
||||
_setIconAdd() {
|
||||
if (this.barcodes.length) {
|
||||
this.barcodes.map(element => {
|
||||
|
@ -30,11 +31,13 @@ export default class Controller {
|
|||
this.$scope.form.$setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
_unsetDirtyForm() {
|
||||
if (this.$scope.form) {
|
||||
this.$scope.form.$setPristine();
|
||||
}
|
||||
}
|
||||
|
||||
_equalBarcodes(oldBarcode, newBarcode) {
|
||||
return oldBarcode.id === newBarcode.id && oldBarcode.code === newBarcode.code;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
<vn-title>Item Niches</vn-title>
|
||||
<vn-horizontal ng-repeat="itemNiche in $ctrl.niches track by $index">
|
||||
<vn-autocomplete
|
||||
vn-three
|
||||
ng-if="!itemNiche.id"
|
||||
vn-one
|
||||
data="$ctrl.warehouses"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
|
@ -17,8 +18,15 @@
|
|||
label="Warehouse"
|
||||
vn-acl="buyer,replenisher">
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
ng-if="itemNiche.id"
|
||||
vn-one
|
||||
label="Warehouse"
|
||||
model="itemNiche.warehouse.name"
|
||||
disabled="true">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-three
|
||||
vn-two
|
||||
label="code"
|
||||
model="itemNiche.code"
|
||||
rule="itemNiche.code"
|
||||
|
|
|
@ -31,6 +31,7 @@ export default class Controller {
|
|||
this.$scope.form.$setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
_unsetDirtyForm() {
|
||||
if (this.$scope.form) {
|
||||
this.$scope.form.$setPristine();
|
||||
|
@ -70,6 +71,7 @@ export default class Controller {
|
|||
where: {itemFk: this.params.id},
|
||||
include: {relation: 'warehouse'}
|
||||
};
|
||||
|
||||
this.$http.get(`/item/api/ItemNiches?filter=${JSON.stringify(filter)}`).then(response => {
|
||||
this.niches = response.data;
|
||||
this.setOldNiches(response);
|
||||
|
@ -95,6 +97,7 @@ export default class Controller {
|
|||
create: [],
|
||||
update: []
|
||||
};
|
||||
|
||||
this.niches.forEach(niche => {
|
||||
let isNewNiche = !niche.id;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<vn-title>Item tags</vn-title>
|
||||
<vn-horizontal ng-repeat="itemTag in $ctrl.instancedItemTags track by $index">
|
||||
<vn-autocomplete
|
||||
ng-if="!itemTag.id"
|
||||
vn-one
|
||||
initial-data="itemTag.tag"
|
||||
field="itemTag.tagFk"
|
||||
|
@ -16,6 +17,13 @@
|
|||
label="Tag"
|
||||
vn-acl="buyer">
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
ng-if="itemTag.id"
|
||||
vn-one
|
||||
label="Tag"
|
||||
model="itemTag.tag.name"
|
||||
disabled="true">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-three
|
||||
label="Value"
|
||||
|
|
Loading…
Reference in New Issue