Etemplate: add customfield prefix as an explicit attribute, importexport filter was using it

This commit is contained in:
nathangray 2020-06-30 10:43:19 -06:00
parent 6ba8210d83
commit 5958feb1c3
2 changed files with 46 additions and 30 deletions

View File

@ -135,10 +135,10 @@ var et2_customfields_list = /** @class */ (function (_super) {
if (this.getType() != 'customfields-list' && !jQuery.isEmptyObject(this.options.fields) && !this.options.fields[field_name]) if (this.getType() != 'customfields-list' && !jQuery.isEmptyObject(this.options.fields) && !this.options.fields[field_name])
continue; continue;
var field = this.options.customfields[field_name]; var field = this.options.customfields[field_name];
var id = et2_customfields_list.PREFIX + field_name; var id = this.options.prefix + field_name;
// Need curlies around ID for nm row expansion // Need curlies around ID for nm row expansion
if (this.id == '$row') { if (this.id == '$row') {
id = "{" + this.id + "}" + "[" + et2_customfields_list.PREFIX + field_name + "]"; id = "{" + this.id + "}" + "[" + this.options.prefix + field_name + "]";
} }
else if (this.id != et2_customfields_list.DEFAULT_ID) { else if (this.id != et2_customfields_list.DEFAULT_ID) {
// Prefix this ID to avoid potential ID collisions // Prefix this ID to avoid potential ID collisions
@ -159,7 +159,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
'statustext': field.help, 'statustext': field.help,
'needed': field.needed, 'needed': field.needed,
'readonly': this.getArrayMgr("readonlys").isReadOnly(id, null, this.options.readonly), 'readonly': this.getArrayMgr("readonlys").isReadOnly(id, null, this.options.readonly),
'value': this.options.value[et2_customfields_list.PREFIX + field_name] 'value': this.options.value[this.options.prefix + field_name]
}); });
// Can't have a required readonly, it will warn & be removed later, so avoid the warning // Can't have a required readonly, it will warn & be removed later, so avoid the warning
if (attrs.readonly === true) if (attrs.readonly === true)
@ -243,14 +243,15 @@ var et2_customfields_list = /** @class */ (function (_super) {
if (contentMgr != null) { if (contentMgr != null) {
var val = contentMgr.getEntry(this.id); var val = contentMgr.getEntry(this.id);
_attrs["value"] = {}; _attrs["value"] = {};
var prefix = _attrs["prefix"] || et2_customfields_list.PREFIX;
if (val !== null) { if (val !== null) {
if (this.id.indexOf(et2_customfields_list.PREFIX) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(et2_customfields_list.PREFIX, '')] === true) { if (this.id.indexOf(prefix) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(prefix, '')] === true) {
_attrs['value'][this.id] = val; _attrs['value'][this.id] = val;
} }
else { else {
// Only set the values that match desired custom fields // Only set the values that match desired custom fields
for (var key_3 in val) { for (var key_3 in val) {
if (key_3.indexOf(et2_customfields_list.PREFIX) == 0) { if (key_3.indexOf(prefix) === 0) {
_attrs["value"][key_3] = val[key_3]; _attrs["value"][key_3] = val[key_3];
} }
} }
@ -260,7 +261,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
else { else {
// Check for custom fields directly in record // Check for custom fields directly in record
for (var key in _attrs.customfields) { for (var key in _attrs.customfields) {
_attrs["value"][et2_customfields_list.PREFIX + key] = contentMgr.getEntry(et2_customfields_list.PREFIX + key); _attrs["value"][prefix + key] = contentMgr.getEntry(prefix + key);
} }
} }
} }
@ -281,10 +282,10 @@ var et2_customfields_list = /** @class */ (function (_super) {
// Make sure widget is created, and has the needed function // Make sure widget is created, and has the needed function
if (!this.widgets[field_name] || !this.widgets[field_name].set_value) if (!this.widgets[field_name] || !this.widgets[field_name].set_value)
continue; continue;
var value = _value[et2_customfields_list.PREFIX + field_name] ? _value[et2_customfields_list.PREFIX + field_name] : null; var value = _value[this.options.prefix + field_name] ? _value[et2_customfields_list.PREFIX + field_name] : null;
// Check if ID was missing // Check if ID was missing
if (value == null && this.id == et2_customfields_list.DEFAULT_ID && this.getArrayMgr("content").getEntry(et2_customfields_list.PREFIX + field_name)) { if (value == null && this.id == et2_customfields_list.DEFAULT_ID && this.getArrayMgr("content").getEntry(this.options.prefix + field_name)) {
value = this.getArrayMgr("content").getEntry(et2_customfields_list.PREFIX + field_name); value = this.getArrayMgr("content").getEntry(this.options.prefix + field_name);
} }
switch (this.options.customfields[field_name].type) { switch (this.options.customfields[field_name].type) {
case 'date': case 'date':
@ -310,7 +311,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
var value = {}; var value = {};
for (var field_name in this.widgets) { for (var field_name in this.widgets) {
if (this.widgets[field_name].getValue && !this.widgets[field_name].options.readonly) { if (this.widgets[field_name].getValue && !this.widgets[field_name].options.readonly) {
value[et2_customfields_list.PREFIX + field_name] = this.widgets[field_name].getValue(); value[this.options.prefix + field_name] = this.widgets[field_name].getValue();
} }
} }
return value; return value;
@ -413,7 +414,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
attrs.config.height = (((field.rows > 0 && field.rows != 'undefined') ? field.rows : 5) * 16) + 'px'; attrs.config.height = (((field.rows > 0 && field.rows != 'undefined') ? field.rows : 5) * 16) + 'px';
// We have to push the config modifications into the modifications array, or they'll // We have to push the config modifications into the modifications array, or they'll
// be overwritten by the site config from the server // be overwritten by the site config from the server
var data = this.getArrayMgr("modifications").getEntry(et2_customfields_list.PREFIX + field_name); var data = this.getArrayMgr("modifications").getEntry(this.options.prefix + field_name);
if (data) if (data)
jQuery.extend(data.config, attrs.config); jQuery.extend(data.config, attrs.config);
return true; return true;
@ -540,12 +541,12 @@ var et2_customfields_list = /** @class */ (function (_super) {
*/ */
et2_customfields_list.prototype.set_visible = function (_fields) { et2_customfields_list.prototype.set_visible = function (_fields) {
for (var name_1 in _fields) { for (var name_1 in _fields) {
if (this.rows[et2_customfields_list.PREFIX + name_1]) { if (this.rows[this.options.prefix + name_1]) {
if (_fields[name_1]) { if (_fields[name_1]) {
jQuery(this.rows[et2_customfields_list.PREFIX + name_1]).show(); jQuery(this.rows[this.options.prefix + name_1]).show();
} }
else { else {
jQuery(this.rows[et2_customfields_list.PREFIX + name_1]).hide(); jQuery(this.rows[this.options.prefix + name_1]).hide();
} }
} }
this.options.fields[name_1] = _fields[name_1]; this.options.fields[name_1] = _fields[name_1];
@ -566,7 +567,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
for (var i = 0; i < _nodes.length; i++) { for (var i = 0; i < _nodes.length; i++) {
// toggle() needs a boolean to do what we want // toggle() needs a boolean to do what we want
var key = _nodes[i].getAttribute('data-field'); var key = _nodes[i].getAttribute('data-field');
jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[et2_customfields_list.PREFIX + key] ? true : false); jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[this.options.prefix + key] ? true : false);
} }
}; };
et2_customfields_list._attributes = { et2_customfields_list._attributes = {
@ -606,6 +607,13 @@ var et2_customfields_list = /** @class */ (function (_super) {
"type": "string", "type": "string",
"default": et2_no_init, "default": et2_no_init,
"description": "JS code which is executed when the value changes." "description": "JS code which is executed when the value changes."
},
// Allow changing the field prefix. Normally it's the constant but importexport filter changes it.
"prefix": {
name: "prefix",
type: "string",
default: et2_no_init,
description: "Custom prefix for custom fields. Default #"
} }
}; };
et2_customfields_list.legacyOptions = ["type_filter", "private", "fields"]; // Field restriction & private done server-side et2_customfields_list.legacyOptions = ["type_filter", "private", "fields"]; // Field restriction & private done server-side

View File

@ -61,6 +61,13 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
"type": "string", "type": "string",
"default": et2_no_init, "default": et2_no_init,
"description": "JS code which is executed when the value changes." "description": "JS code which is executed when the value changes."
},
// Allow changing the field prefix. Normally it's the constant but importexport filter changes it.
"prefix": {
name: "prefix",
type: "string",
default: et2_no_init,
description: "Custom prefix for custom fields. Default #"
} }
}; };
@ -200,12 +207,12 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
const field = this.options.customfields[field_name]; const field = this.options.customfields[field_name];
let id = et2_customfields_list.PREFIX + field_name; let id = this.options.prefix + field_name;
// Need curlies around ID for nm row expansion // Need curlies around ID for nm row expansion
if(this.id == '$row') if(this.id == '$row')
{ {
id = "{" + this.id + "}" + "["+et2_customfields_list.PREFIX + field_name+"]"; id = "{" + this.id + "}" + "["+this.options.prefix + field_name+"]";
} }
else if (this.id != et2_customfields_list.DEFAULT_ID) else if (this.id != et2_customfields_list.DEFAULT_ID)
{ {
@ -230,7 +237,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
'statustext': field.help, 'statustext': field.help,
'needed': field.needed, 'needed': field.needed,
'readonly': this.getArrayMgr("readonlys").isReadOnly(id, null, this.options.readonly), 'readonly': this.getArrayMgr("readonlys").isReadOnly(id, null, this.options.readonly),
'value': this.options.value[et2_customfields_list.PREFIX + field_name] 'value': this.options.value[this.options.prefix + field_name]
}); });
// Can't have a required readonly, it will warn & be removed later, so avoid the warning // Can't have a required readonly, it will warn & be removed later, so avoid the warning
if(attrs.readonly === true) delete attrs.needed; if(attrs.readonly === true) delete attrs.needed;
@ -335,9 +342,10 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
if (contentMgr != null) { if (contentMgr != null) {
const val = contentMgr.getEntry(this.id); const val = contentMgr.getEntry(this.id);
_attrs["value"] = {}; _attrs["value"] = {};
let prefix = _attrs["prefix"] || et2_customfields_list.PREFIX;
if (val !== null) if (val !== null)
{ {
if(this.id.indexOf(et2_customfields_list.PREFIX) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(et2_customfields_list.PREFIX,'')] === true) if(this.id.indexOf(prefix) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(prefix,'')] === true)
{ {
_attrs['value'][this.id] = val; _attrs['value'][this.id] = val;
} }
@ -346,7 +354,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// Only set the values that match desired custom fields // Only set the values that match desired custom fields
for(let key in val) for(let key in val)
{ {
if(key.indexOf(et2_customfields_list.PREFIX) == 0) { if(key.indexOf(prefix) === 0) {
_attrs["value"][key] = val[key]; _attrs["value"][key] = val[key];
} }
} }
@ -358,7 +366,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// Check for custom fields directly in record // Check for custom fields directly in record
for(var key in _attrs.customfields) for(var key in _attrs.customfields)
{ {
_attrs["value"][et2_customfields_list.PREFIX + key] = contentMgr.getEntry(et2_customfields_list.PREFIX + key); _attrs["value"][prefix + key] = contentMgr.getEntry(prefix + key);
} }
} }
} }
@ -383,12 +391,12 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// Make sure widget is created, and has the needed function // Make sure widget is created, and has the needed function
if(!this.widgets[field_name] || !this.widgets[field_name].set_value) continue; if(!this.widgets[field_name] || !this.widgets[field_name].set_value) continue;
let value = _value[et2_customfields_list.PREFIX + field_name] ? _value[et2_customfields_list.PREFIX + field_name] : null; let value = _value[this.options.prefix + field_name] ? _value[et2_customfields_list.PREFIX + field_name] : null;
// Check if ID was missing // Check if ID was missing
if(value == null && this.id == et2_customfields_list.DEFAULT_ID && this.getArrayMgr("content").getEntry(et2_customfields_list.PREFIX + field_name)) if(value == null && this.id == et2_customfields_list.DEFAULT_ID && this.getArrayMgr("content").getEntry(this.options.prefix + field_name))
{ {
value = this.getArrayMgr("content").getEntry(et2_customfields_list.PREFIX + field_name); value = this.getArrayMgr("content").getEntry(this.options.prefix + field_name);
} }
switch(this.options.customfields[field_name].type) switch(this.options.customfields[field_name].type)
@ -422,7 +430,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
{ {
if(this.widgets[field_name].getValue && !this.widgets[field_name].options.readonly) if(this.widgets[field_name].getValue && !this.widgets[field_name].options.readonly)
{ {
value[et2_customfields_list.PREFIX + field_name] = this.widgets[field_name].getValue(); value[this.options.prefix + field_name] = this.widgets[field_name].getValue();
} }
} }
return value; return value;
@ -559,7 +567,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// We have to push the config modifications into the modifications array, or they'll // We have to push the config modifications into the modifications array, or they'll
// be overwritten by the site config from the server // be overwritten by the site config from the server
const data = this.getArrayMgr("modifications").getEntry(et2_customfields_list.PREFIX + field_name); const data = this.getArrayMgr("modifications").getEntry(this.options.prefix + field_name);
if(data) jQuery.extend(data.config, attrs.config); if(data) jQuery.extend(data.config, attrs.config);
return true; return true;
@ -724,15 +732,15 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
{ {
for(let name in _fields) for(let name in _fields)
{ {
if(this.rows[et2_customfields_list.PREFIX + name]) if(this.rows[this.options.prefix + name])
{ {
if(_fields[name]) if(_fields[name])
{ {
jQuery(this.rows[et2_customfields_list.PREFIX+name]).show(); jQuery(this.rows[this.options.prefix+name]).show();
} }
else else
{ {
jQuery(this.rows[et2_customfields_list.PREFIX+name]).hide(); jQuery(this.rows[this.options.prefix+name]).hide();
} }
} }
this.options.fields[name] = _fields[name]; this.options.fields[name] = _fields[name];
@ -761,7 +769,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
{ {
// toggle() needs a boolean to do what we want // toggle() needs a boolean to do what we want
const key = _nodes[i].getAttribute('data-field'); const key = _nodes[i].getAttribute('data-field');
jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[et2_customfields_list.PREFIX + key]?true:false); jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[this.options.prefix + key]?true:false);
} }
} }
} }