Fix Uncaught TypeError: Cannot read properties of null (reading 'app_obj') when clicking a project title.

onclick for nextmatch rows was not getting re-parsed for each row, so it was trying with the original widget from the template instead of the one from the row.
Also accepting widget as argument into compiled legacy code and using it over original context so we don't need to re-compile for each row.
This commit is contained in:
nathan 2022-08-17 13:23:55 -06:00
parent 6caaba1bca
commit 40bbc53af8
3 changed files with 25 additions and 4 deletions

View File

@ -1412,6 +1412,16 @@ function transformAttributes(widget, mgr : et2_arrayMgr, attributes)
}
break;
case Function:
if(typeof attrValue == "string" && mgr.getPerspectiveData().row == null &&
(attrValue.indexOf("$row") > -1 || attrValue.indexOf("$row_cont") > -1)
)
{
// Need row context, defer it until later
// Repeating rows & nextmatch will parse it again when doing the row
widget.deferredProperties[attribute] = attrValue;
console.log("Had to defer %s parsing for %o\nCan it be rewritten to avoid $row & $row_cont?", attribute, widget);
break;
}
// We parse it into a function here so we can pass in the widget as context.
// Leaving it to the LitElement conversion loses the widget as context
if(typeof attrValue !== "function")

View File

@ -111,7 +111,8 @@ export function et2_compileLegacyJS(_code, _widget, _context)
// Execute the code and return its results, pass the egw instance and
// the widget
return function(ev) {
return function(ev, widget?)
{
// Dump the executed code for debugging
egw.debug('log', 'Executing legacy JS code: ', _code);
@ -120,7 +121,7 @@ export function et2_compileLegacyJS(_code, _widget, _context)
egw.debug('warn', 'Legacy JS code only supports 2 arguments (event and widget)', _code, arguments);
}
// Return the result of the called function
return func.call(context, ev, _widget);
return func.call(context, ev, widget || _widget);
};
}

View File

@ -170,7 +170,8 @@ export class et2_nextmatch_rowProvider
let widget = entry.widget;
// Parse the attribute expressions
var data : any = {};
let data : any = {};
let attributes = entry.data.map(attr => attr.attribute);
for(var j = 0; j < entry.data.length; j++)
{
var set = entry.data[j];
@ -216,8 +217,17 @@ export class et2_nextmatch_rowProvider
// Adjust data for that row
widget.transformAttributes?.call(widget, data);
// Make sure to only send detached attributes, filter out any deferredProperties
let filtered = widget.deferredProperties ? Object.keys(data)
.filter(key => attributes.includes(key))
.reduce((obj, key) =>
{
obj[key] = data[key];
return obj
}, {}) : data;
// Call the setDetachedAttributes function
widget.setDetachedAttributes(nodes, data, _data);
widget.setDetachedAttributes(nodes, filtered, _data);
}
// Insert the row into the tr