corrected bug on all htmls using crud

This commit is contained in:
Carlos Jimenez 2018-03-16 15:08:36 +01:00
parent ece2fd384d
commit 945a1b3049
7 changed files with 57 additions and 21 deletions

View File

@ -54,6 +54,7 @@
<mg-ajax path="/client/api/ObservationTypes" options="mgIndex as observationsTypes"></mg-ajax> <mg-ajax path="/client/api/ObservationTypes" options="mgIndex as observationsTypes"></mg-ajax>
<vn-horizontal ng-repeat="observation in $ctrl.observations track by $index"> <vn-horizontal ng-repeat="observation in $ctrl.observations track by $index">
<vn-autocomplete <vn-autocomplete
ng-if="!observation.id"
vn-one vn-one
initial-data="observation.observationType" initial-data="observation.observationType"
field="observation.observationTypeFk" field="observation.observationTypeFk"
@ -61,6 +62,13 @@
show-field="description" show-field="description"
label="Observation type"> label="Observation type">
</vn-autocomplete> </vn-autocomplete>
<vn-textfield
ng-if="observation.id"
vn-one
label="Observation type"
model="observation.observationType.description"
disabled="true">
</vn-textfield>
<vn-textfield <vn-textfield
vn-two vn-two
margin-large-right margin-large-right

View File

@ -13,8 +13,8 @@ export default class Controller {
id: parseInt($state.params.addressId) id: parseInt($state.params.addressId)
}; };
this.observations = []; this.observations = [];
this.observationsOld = {}; this.oldObservations = {};
this.observationsRemoved = []; this.removedObservations = [];
} }
_setDirtyForm() { _setDirtyForm() {
@ -22,6 +22,7 @@ export default class Controller {
this.$scope.form.$setDirty(); this.$scope.form.$setDirty();
} }
} }
_unsetDirtyForm() { _unsetDirtyForm() {
if (this.$scope.form) { if (this.$scope.form) {
this.$scope.form.$setPristine(); this.$scope.form.$setPristine();
@ -37,16 +38,17 @@ export default class Controller {
if (item) { if (item) {
this.observations.splice(index, 1); this.observations.splice(index, 1);
if (item.id) { if (item.id) {
this.observationsRemoved.push(item.id); this.removedObservations.push(item.id);
this._setDirtyForm(); 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(); 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) { _observationsEquals(ob1, ob2) {
@ -58,12 +60,12 @@ export default class Controller {
return false; return false;
} }
let canWatcherSubmit = this.$scope.watcher.dataChanged(); let canSubmitWatcher = this.$scope.watcher.dataChanged();
let canObservationsSubmit; let canSubmitObservations;
let repeatedTypes = false; let repeatedTypes = false;
let types = []; let types = [];
let observationsObj = { let observationsObj = {
delete: this.observationsRemoved, delete: this.removedObservations,
create: [], create: [],
update: [] update: []
}; };
@ -82,26 +84,26 @@ export default class Controller {
if (isNewObservation && observation.observationTypeFk && observation.description) { if (isNewObservation && observation.observationTypeFk && observation.description) {
observationsObj.create.push(observation); 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); 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) { if (repeatedTypes) {
this.vnApp.showMessage( this.vnApp.showMessage(
this.$translate.instant('The observation type must be unique') this.$translate.instant('The observation type must be unique')
); );
} else if (canWatcherSubmit && !canObservationsSubmit) { } else if (canSubmitWatcher && !canSubmitObservations) {
this.$scope.watcher.submit().then(() => { this.$scope.watcher.submit().then(() => {
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id}); this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
}); });
} else if (!canWatcherSubmit && canObservationsSubmit) { } else if (!canSubmitWatcher && canSubmitObservations) {
this._submitObservations(observationsObj).then(() => { this._submitObservations(observationsObj).then(() => {
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id}); 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.$q.all([this.$scope.watcher.submit(), this._submitObservations(observationsObj)]).then(() => {
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id}); this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
}); });
@ -113,7 +115,7 @@ export default class Controller {
this._unsetDirtyForm(); this._unsetDirtyForm();
} }
$onInit() { _getAddressNotes() {
let filter = { let filter = {
where: {addressFk: this.address.id}, where: {addressFk: this.address.id},
include: {relation: 'observationType'} include: {relation: 'observationType'}
@ -121,10 +123,14 @@ export default class Controller {
this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => { this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => {
this.observations = res.data; this.observations = res.data;
res.data.forEach(item => { 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']; Controller.$inject = ['$state', '$scope', '$http', '$q', '$translate', 'vnApp'];

View File

@ -1,8 +1,8 @@
<div <div
class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label" class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"
ng-mouseenter="$ctrl.hasMouseIn = true" ng-mouseenter="$ctrl.hasMouseIn = true"
ng-mouseleave="$ctrl.hasMouseIn = false"> ng-mouseleave="$ctrl.hasMouseIn = false">
<input <input
class="mdl-textfield__input" class="mdl-textfield__input"
type="{{$ctrl.type}}" type="{{$ctrl.type}}"
name="{{$ctrl.name}}" name="{{$ctrl.name}}"
@ -11,7 +11,7 @@
ng-disabled="$ctrl.disabled" ng-disabled="$ctrl.disabled"
ng-readonly="$ctrl.readonly" ng-readonly="$ctrl.readonly"
ng-focus="$ctrl.hasFocus = true" ng-focus="$ctrl.hasFocus = true"
ng-blur="$ctrl.hasFocus = false"/> ng-blur="$ctrl.hasFocus = false"/>
<div class="mdl-chip__action"> <div class="mdl-chip__action">
<i class="material-icons" <i class="material-icons"
ng-if="$ctrl.hasInfo" ng-if="$ctrl.hasInfo"

View File

@ -13,6 +13,7 @@ export default class Controller {
this.removedBarcodes = []; this.removedBarcodes = [];
this.oldBarcodes = {}; this.oldBarcodes = {};
} }
_setIconAdd() { _setIconAdd() {
if (this.barcodes.length) { if (this.barcodes.length) {
this.barcodes.map(element => { this.barcodes.map(element => {
@ -30,11 +31,13 @@ export default class Controller {
this.$scope.form.$setDirty(); this.$scope.form.$setDirty();
} }
} }
_unsetDirtyForm() { _unsetDirtyForm() {
if (this.$scope.form) { if (this.$scope.form) {
this.$scope.form.$setPristine(); this.$scope.form.$setPristine();
} }
} }
_equalBarcodes(oldBarcode, newBarcode) { _equalBarcodes(oldBarcode, newBarcode) {
return oldBarcode.id === newBarcode.id && oldBarcode.code === newBarcode.code; return oldBarcode.id === newBarcode.id && oldBarcode.code === newBarcode.code;
} }

View File

@ -8,7 +8,8 @@
<vn-title>Item Niches</vn-title> <vn-title>Item Niches</vn-title>
<vn-horizontal ng-repeat="itemNiche in $ctrl.niches track by $index"> <vn-horizontal ng-repeat="itemNiche in $ctrl.niches track by $index">
<vn-autocomplete <vn-autocomplete
vn-three ng-if="!itemNiche.id"
vn-one
data="$ctrl.warehouses" data="$ctrl.warehouses"
show-field="name" show-field="name"
value-field="id" value-field="id"
@ -17,8 +18,15 @@
label="Warehouse" label="Warehouse"
vn-acl="buyer,replenisher"> vn-acl="buyer,replenisher">
</vn-autocomplete> </vn-autocomplete>
<vn-textfield
ng-if="itemNiche.id"
vn-one
label="Warehouse"
model="itemNiche.warehouse.name"
disabled="true">
</vn-textfield>
<vn-textfield <vn-textfield
vn-three vn-two
label="code" label="code"
model="itemNiche.code" model="itemNiche.code"
rule="itemNiche.code" rule="itemNiche.code"

View File

@ -31,6 +31,7 @@ export default class Controller {
this.$scope.form.$setDirty(); this.$scope.form.$setDirty();
} }
} }
_unsetDirtyForm() { _unsetDirtyForm() {
if (this.$scope.form) { if (this.$scope.form) {
this.$scope.form.$setPristine(); this.$scope.form.$setPristine();
@ -70,6 +71,7 @@ export default class Controller {
where: {itemFk: this.params.id}, where: {itemFk: this.params.id},
include: {relation: 'warehouse'} include: {relation: 'warehouse'}
}; };
this.$http.get(`/item/api/ItemNiches?filter=${JSON.stringify(filter)}`).then(response => { this.$http.get(`/item/api/ItemNiches?filter=${JSON.stringify(filter)}`).then(response => {
this.niches = response.data; this.niches = response.data;
this.setOldNiches(response); this.setOldNiches(response);
@ -95,6 +97,7 @@ export default class Controller {
create: [], create: [],
update: [] update: []
}; };
this.niches.forEach(niche => { this.niches.forEach(niche => {
let isNewNiche = !niche.id; let isNewNiche = !niche.id;

View File

@ -8,6 +8,7 @@
<vn-title>Item tags</vn-title> <vn-title>Item tags</vn-title>
<vn-horizontal ng-repeat="itemTag in $ctrl.instancedItemTags track by $index"> <vn-horizontal ng-repeat="itemTag in $ctrl.instancedItemTags track by $index">
<vn-autocomplete <vn-autocomplete
ng-if="!itemTag.id"
vn-one vn-one
initial-data="itemTag.tag" initial-data="itemTag.tag"
field="itemTag.tagFk" field="itemTag.tagFk"
@ -16,6 +17,13 @@
label="Tag" label="Tag"
vn-acl="buyer"> vn-acl="buyer">
</vn-autocomplete> </vn-autocomplete>
<vn-textfield
ng-if="itemTag.id"
vn-one
label="Tag"
model="itemTag.tag.name"
disabled="true">
</vn-textfield>
<vn-textfield <vn-textfield
vn-three vn-three
label="Value" label="Value"