#1073 item.tags no busca tags cuando se añade una linea nueva

This commit is contained in:
Gerard 2019-01-29 14:38:31 +01:00
parent f6f1dba1d9
commit 94f19c2cb5
3 changed files with 15 additions and 9 deletions

View File

@ -145,8 +145,9 @@ export default class ModelProxy extends DataModel {
}); });
return new Proxy(obj, { return new Proxy(obj, {
set: (obj, prop, value) => { set: (obj, prop, value) => {
let changed = prop.charAt(0) !== '$' && value !== obj[prop] && !obj.$isNew; let changed = prop.charAt(0) !== '$' && value !== obj[prop];
if (changed) {
if (changed && !obj.$isNew) {
if (!obj.$oldData) if (!obj.$oldData)
obj.$oldData = {}; obj.$oldData = {};
if (!obj.$oldData[prop]) if (!obj.$oldData[prop])
@ -159,7 +160,8 @@ export default class ModelProxy extends DataModel {
if (changed) { if (changed) {
this.emit('rowChange', {obj, prop, value}); this.emit('rowChange', {obj, prop, value});
this.emit('dataUpdate'); this.emit('dataUpdate');
if (this.autoSave)
if (!obj.$isNew && this.autoSave)
this.save(); this.save();
} }
@ -173,10 +175,11 @@ export default class ModelProxy extends DataModel {
this.isChanged = false; this.isChanged = false;
let data = this.proxiedData; let data = this.proxiedData;
if (data) if (data) {
for (let row of data) for (let row of data)
row.$oldData = null; row.$oldData = null;
} }
}
/** /**
* Applies all changes made to the model into the original data source. * Applies all changes made to the model into the original data source.
@ -186,18 +189,21 @@ export default class ModelProxy extends DataModel {
let orgData = this.orgData; let orgData = this.orgData;
if (!data) return; if (!data) return;
for (let row of data) for (let row of data) {
if (row.$isNew) { if (row.$isNew) {
let orgRow = {}; let orgRow = {};
for (let prop in row) for (let prop in row) {
if (prop.charAt(0) !== '$') if (prop.charAt(0) !== '$')
orgRow[prop] = row[prop]; orgRow[prop] = row[prop];
}
row.$orgIndex = orgData.push(orgRow) - 1; row.$orgIndex = orgData.push(orgRow) - 1;
row.$orgRow = orgRow; row.$orgRow = orgRow;
row.$isNew = false; row.$isNew = false;
} else if (row.$oldData) } else if (row.$oldData) {
for (let prop in row.$oldData) for (let prop in row.$oldData)
row.$orgRow[prop] = row[prop]; row.$orgRow[prop] = row[prop];
}
}
let removed = this.removed; let removed = this.removed;

View File

@ -5,7 +5,6 @@
link="{itemFk: $ctrl.$stateParams.id}" link="{itemFk: $ctrl.$stateParams.id}"
include="$ctrl.include" include="$ctrl.include"
order="priority ASC" order="priority ASC"
on-row-change="$ctrl.getSourceTable(obj)"
data="$ctrl.itemTags" data="$ctrl.itemTags"
auto-load="true"> auto-load="true">
</vn-crud-model> </vn-crud-model>
@ -31,6 +30,7 @@
initial-data="itemTag.tag" initial-data="itemTag.tag"
field="itemTag.tagFk" field="itemTag.tagFk"
data="tags" data="tags"
on-change="$ctrl.getSourceTable(tag)"
show-field="name" show-field="name"
vn-acl="buyer" vn-acl="buyer"
vn-focus> vn-focus>

View File

@ -30,7 +30,7 @@ class Controller {
getSourceTable(obj) { getSourceTable(obj) {
let sourceTable; let sourceTable;
this.sourceTables[obj.id] = {}; this.sourceTables[obj.id] = {};
let tag = obj.tag; let tag = obj.tag || obj.selection;
if (!tag || !tag.sourceTable && (tag.isFree === true || tag.isFree === undefined)) if (!tag || !tag.sourceTable && (tag.isFree === true || tag.isFree === undefined))
sourceTable = null; sourceTable = null;