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])
continue;
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
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) {
// Prefix this ID to avoid potential ID collisions
@ -159,7 +159,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
'statustext': field.help,
'needed': field.needed,
'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
if (attrs.readonly === true)
@ -243,14 +243,15 @@ var et2_customfields_list = /** @class */ (function (_super) {
if (contentMgr != null) {
var val = contentMgr.getEntry(this.id);
_attrs["value"] = {};
var prefix = _attrs["prefix"] || et2_customfields_list.PREFIX;
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;
}
else {
// Only set the values that match desired custom fields
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];
}
}
@ -260,7 +261,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
else {
// Check for custom fields directly in record
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
if (!this.widgets[field_name] || !this.widgets[field_name].set_value)
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
if (value == null && this.id == et2_customfields_list.DEFAULT_ID && this.getArrayMgr("content").getEntry(et2_customfields_list.PREFIX + field_name)) {
value = 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(this.options.prefix + field_name);
}
switch (this.options.customfields[field_name].type) {
case 'date':
@ -310,7 +311,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
var value = {};
for (var field_name in this.widgets) {
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;
@ -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';
// We have to push the config modifications into the modifications array, or they'll
// 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)
jQuery.extend(data.config, attrs.config);
return true;
@ -540,12 +541,12 @@ var et2_customfields_list = /** @class */ (function (_super) {
*/
et2_customfields_list.prototype.set_visible = function (_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]) {
jQuery(this.rows[et2_customfields_list.PREFIX + name_1]).show();
jQuery(this.rows[this.options.prefix + name_1]).show();
}
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];
@ -566,7 +567,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
for (var i = 0; i < _nodes.length; i++) {
// toggle() needs a boolean to do what we want
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 = {
@ -606,6 +607,13 @@ var et2_customfields_list = /** @class */ (function (_super) {
"type": "string",
"default": et2_no_init,
"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