backend-plus 1.16.20 → 1.16.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/for-client/my-tables.js +48 -35
- package/lib/backend-plus.d.ts +2 -0
- package/package.json +1 -1
package/for-client/my-tables.js
CHANGED
|
@@ -1001,45 +1001,17 @@ myOwn.DataColumnGrid.prototype.td = function td(depot, iColumn, tr, saveRow){
|
|
|
1001
1001
|
if(grid.modes.saveByField){
|
|
1002
1002
|
saveRow(depot,{visiblyLogErrors:false});
|
|
1003
1003
|
}
|
|
1004
|
-
var
|
|
1005
|
-
if(fieldDef.references){
|
|
1006
|
-
|
|
1007
|
-
grid.def.foreignKeys.filter(function(fkDef){
|
|
1004
|
+
var promiseChain = Promise.resolve();
|
|
1005
|
+
if (fieldDef.references) {
|
|
1006
|
+
promiseChain.then(grid.setInheritedFields(depot, function(fkDef){
|
|
1008
1007
|
return fkDef.references == fieldDef.references &&
|
|
1009
1008
|
fkDef.fields.find(function(field){
|
|
1010
1009
|
return field.source == fieldDef.name
|
|
1011
1010
|
}) &&
|
|
1012
|
-
fkDef.displayFields.length
|
|
1013
|
-
})
|
|
1014
|
-
var fixedFields = fkDef.fields.map(function(field){
|
|
1015
|
-
return {fieldName: field.target, value: depot.row[field.source]};
|
|
1016
|
-
})
|
|
1017
|
-
var dummyElement = html.div().create();
|
|
1018
|
-
var Connector = my.offline.mode?my.TableConnectorLocal:my.TableConnector;
|
|
1019
|
-
var myConnector = new Connector({
|
|
1020
|
-
my:my,
|
|
1021
|
-
tableName: fieldDef.references,
|
|
1022
|
-
getElementToDisplayCount:function(){ return dummyElement }
|
|
1023
|
-
}, {fixedFields: fixedFields});
|
|
1024
|
-
myConnector.getStructure();
|
|
1025
|
-
//cargo registro y actualizo displayFields
|
|
1026
|
-
promiseArray.push(
|
|
1027
|
-
myConnector.getData().then(function(data){
|
|
1028
|
-
var referencedRow = data[0];
|
|
1029
|
-
fkDef.displayFields.forEach(function(displayFieldName){
|
|
1030
|
-
var lookupValue=referencedRow?referencedRow[displayFieldName]:null;
|
|
1031
|
-
var fieldName = fkDef.alias + '__' + displayFieldName;
|
|
1032
|
-
depot.row[fieldName]=lookupValue;
|
|
1033
|
-
if(depot.rowControls[fieldName]){
|
|
1034
|
-
depot.rowControls[fieldName].setTypedValue(lookupValue);
|
|
1035
|
-
}
|
|
1036
|
-
})
|
|
1037
|
-
|
|
1038
|
-
})
|
|
1039
|
-
)
|
|
1040
|
-
});
|
|
1011
|
+
fkDef.displayFields.length >= 0
|
|
1012
|
+
}));
|
|
1041
1013
|
}
|
|
1042
|
-
|
|
1014
|
+
promiseChain.then(function(){
|
|
1043
1015
|
grid.updateRowData(depot,true);
|
|
1044
1016
|
});
|
|
1045
1017
|
}
|
|
@@ -2061,6 +2033,43 @@ myOwn.TableGrid.prototype.prepareGrid = function prepareGrid(){
|
|
|
2061
2033
|
// [html.tr([html.th([buttonInsert]),grid.dom.footInfo])]
|
|
2062
2034
|
]).create();
|
|
2063
2035
|
}
|
|
2036
|
+
grid.setInheritedFields = function(depot, filterFun){
|
|
2037
|
+
var promiseArray = [];
|
|
2038
|
+
grid.def.foreignKeys.filter(filterFun||(x=>x)).forEach(function(fkDef){
|
|
2039
|
+
var fixedFields = fkDef.fields.map(function(field){
|
|
2040
|
+
return {fieldName: field.target, value: depot.row[field.source]};
|
|
2041
|
+
})
|
|
2042
|
+
var dummyElement = html.div().create();
|
|
2043
|
+
var Connector = my.offline.mode?my.TableConnectorLocal:my.TableConnector;
|
|
2044
|
+
var myConnector = new Connector({
|
|
2045
|
+
my:my,
|
|
2046
|
+
tableName: fkDef.references,
|
|
2047
|
+
getElementToDisplayCount:function(){ return dummyElement }
|
|
2048
|
+
}, {fixedFields: fixedFields});
|
|
2049
|
+
myConnector.getStructure();
|
|
2050
|
+
//cargo registro y actualizo displayFields
|
|
2051
|
+
promiseArray.push(
|
|
2052
|
+
myConnector.getData().then(function(data){
|
|
2053
|
+
var referencedRow = data[0];
|
|
2054
|
+
grid.def.fields.forEach(function(fieldDef){
|
|
2055
|
+
var foreignFieldName = fieldDef.references == fkDef.references ? fieldDef.referencedName : fieldDef.inherited ? fieldDef.name : null;
|
|
2056
|
+
if (referencedRow && foreignFieldName in referencedRow) {
|
|
2057
|
+
var lookupValue = referencedRow[foreignFieldName];
|
|
2058
|
+
var fieldName = fieldDef.name;
|
|
2059
|
+
if(fieldDef.inherited && !sameValue(depot.row[fieldName], lookupValue)){
|
|
2060
|
+
depot.rowPendingForUpdate[fieldName] = lookupValue;
|
|
2061
|
+
}
|
|
2062
|
+
depot.row[fieldName]=lookupValue;
|
|
2063
|
+
if(depot.rowControls[fieldName]){
|
|
2064
|
+
depot.rowControls[fieldName].setTypedValue(lookupValue);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
})
|
|
2068
|
+
})
|
|
2069
|
+
)
|
|
2070
|
+
});
|
|
2071
|
+
return Promise.all(promiseArray);
|
|
2072
|
+
}
|
|
2064
2073
|
grid.dom.main.innerHTML='';
|
|
2065
2074
|
grid.dom.main.appendChild(grid.dom.table);
|
|
2066
2075
|
};
|
|
@@ -2201,8 +2210,12 @@ myOwn.TableGrid.prototype.displayGrid = function displayGrid(){
|
|
|
2201
2210
|
grid.my.clientSides[grid.def.clientSide].prepare(depot);
|
|
2202
2211
|
};
|
|
2203
2212
|
depot.clientSidePrepared=true;
|
|
2204
|
-
grid.my.clientSides[grid.def.clientSide].update(depot);
|
|
2205
2213
|
}
|
|
2214
|
+
grid.setInheritedFields(depot).then(function(){
|
|
2215
|
+
if(grid.def.clientSide){
|
|
2216
|
+
grid.my.clientSides[grid.def.clientSide].update(depot);
|
|
2217
|
+
}
|
|
2218
|
+
});
|
|
2206
2219
|
};
|
|
2207
2220
|
var changeIoStatus = function changeIoStatus(depot,newStatus, objectWithFieldsOrListOfFieldNames, title){
|
|
2208
2221
|
var fieldNames=typeof objectWithFieldsOrListOfFieldNames === "string"?[objectWithFieldsOrListOfFieldNames]:(
|
package/lib/backend-plus.d.ts
CHANGED
|
@@ -199,6 +199,7 @@ export type FieldDefinition = EditableDbDefinition & {
|
|
|
199
199
|
inJoin?:string /* alias from sql.join; implies inTable:false */
|
|
200
200
|
transformer?:string
|
|
201
201
|
table?:string
|
|
202
|
+
inherited?:boolean
|
|
202
203
|
} & ({} | {
|
|
203
204
|
sequence:SequenceDefinition
|
|
204
205
|
nullable:true
|
|
@@ -301,6 +302,7 @@ export type TableDefinition = EditableDbDefinition & {
|
|
|
301
302
|
description?:MarkdownDoc
|
|
302
303
|
exportJsonFieldAsColumns?:string
|
|
303
304
|
importCuidado?:boolean
|
|
305
|
+
specialValidator?:string
|
|
304
306
|
}
|
|
305
307
|
export interface DetailTable { table?: string, fields: FieldsForConnectDetailTable, abr: string, label?: string, refreshParent?:boolean, refreshFromParent?:boolean, wScreen?:string, condition?:string }
|
|
306
308
|
export type TableDefinitionFunction = (context: ContextForDump, opts?:any) => TableDefinition;
|
package/package.json
CHANGED