Make cf prefix a proper constant

This commit is contained in:
nathangray 2020-02-12 11:32:29 -07:00
parent c3350c8114
commit 7a79bfad93
4 changed files with 54 additions and 61 deletions

View File

@ -51,9 +51,6 @@ var et2_customfields_list = /** @class */ (function (_super) {
// Create a local copy of the options object
_this.options = et2_cloneObject(_attrs);
}
// Allows server side to override prefix - not an attribute though
if (typeof _this.options.prefix != 'undefined')
_this.prefix = _this.options.prefix;
// Create the table body and the table
_this.tbody = jQuery(document.createElement("tbody"));
_this.table = jQuery(document.createElement("table"))
@ -139,10 +136,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 = this.prefix + field_name;
var id = et2_customfields_list.PREFIX + field_name;
// Need curlies around ID for nm row expansion
if (this.id == '$row') {
id = "{" + this.id + "}" + "[" + this.prefix + field_name + "]";
id = "{" + this.id + "}" + "[" + et2_customfields_list.PREFIX + field_name + "]";
}
else if (this.id != et2_customfields_list.DEFAULT_ID) {
// Prefix this ID to avoid potential ID collisions
@ -163,7 +160,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[this.prefix + field_name]
'value': this.options.value[et2_customfields_list.PREFIX + field_name]
};
// Can't have a required readonly, it will warn & be removed later, so avoid the warning
if (attrs.readonly === true)
@ -247,13 +244,13 @@ var et2_customfields_list = /** @class */ (function (_super) {
var val = contentMgr.getEntry(this.id);
_attrs["value"] = {};
if (val !== null) {
if (this.id.indexOf(this.prefix) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(this.prefix, '')] === true) {
if (this.id.indexOf(et2_customfields_list.PREFIX) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(et2_customfields_list.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(this.prefix) == 0) {
if (key_3.indexOf(et2_customfields_list.PREFIX) == 0) {
_attrs["value"][key_3] = val[key_3];
}
}
@ -263,7 +260,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
else {
// Check for custom fields directly in record
for (var key in _attrs.customfields) {
_attrs["value"][this.prefix + key] = contentMgr.getEntry(this.prefix + key);
_attrs["value"][et2_customfields_list.PREFIX + key] = contentMgr.getEntry(et2_customfields_list.PREFIX + key);
}
}
}
@ -284,10 +281,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[this.prefix + field_name] ? _value[this.prefix + field_name] : null;
var value = _value[et2_customfields_list.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(this.prefix + field_name)) {
value = this.getArrayMgr("content").getEntry(this.prefix + field_name);
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);
}
switch (this.options.customfields[field_name].type) {
case 'date':
@ -313,7 +310,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[this.prefix + field_name] = this.widgets[field_name].getValue();
value[et2_customfields_list.PREFIX + field_name] = this.widgets[field_name].getValue();
}
}
return value;
@ -409,7 +406,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(this.prefix + field_name);
var data = this.getArrayMgr("modifications").getEntry(et2_customfields_list.PREFIX + field_name);
if (data)
jQuery.extend(data.config, attrs.config);
return true;
@ -536,12 +533,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[this.prefix + name_1]) {
if (this.rows[et2_customfields_list.PREFIX + name_1]) {
if (_fields[name_1]) {
jQuery(this.rows[this.prefix + name_1]).show();
jQuery(this.rows[et2_customfields_list.PREFIX + name_1]).show();
}
else {
jQuery(this.rows[this.prefix + name_1]).hide();
jQuery(this.rows[et2_customfields_list.PREFIX + name_1]).hide();
}
}
this.options.fields[name_1] = _fields[name_1];
@ -562,7 +559,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[this.prefix + key] ? true : false);
jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[et2_customfields_list.PREFIX + key] ? true : false);
}
};
et2_customfields_list._attributes = {
@ -604,7 +601,7 @@ var et2_customfields_list = /** @class */ (function (_super) {
"description": "JS code which is executed when the value changes."
}
};
et2_customfields_list.prefix = '#';
et2_customfields_list.PREFIX = '#';
et2_customfields_list.DEFAULT_ID = "custom_fields";
return et2_customfields_list;
}(et2_core_valueWidget_1.et2_valueWidget));

View File

@ -66,7 +66,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
legacyOptions = ["type_filter","private", "fields"]; // Field restriction & private done server-side
public static readonly prefix = '#';
public static readonly PREFIX = '#';
public static readonly DEFAULT_ID = "custom_fields";
private tbody: JQuery;
@ -92,9 +92,6 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
this.options = et2_cloneObject(_attrs);
}
// Allows server side to override prefix - not an attribute though
if(typeof this.options.prefix != 'undefined') this.prefix = this.options.prefix;
// Create the table body and the table
this.tbody = jQuery(document.createElement("tbody"));
this.table = jQuery(document.createElement("table"))
@ -203,12 +200,12 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
const field = this.options.customfields[field_name];
let id = this.prefix + field_name;
let id = et2_customfields_list.PREFIX + field_name;
// Need curlies around ID for nm row expansion
if(this.id == '$row')
{
id = "{" + this.id + "}" + "["+this.prefix + field_name+"]";
id = "{" + this.id + "}" + "["+et2_customfields_list.PREFIX + field_name+"]";
}
else if (this.id != et2_customfields_list.DEFAULT_ID)
{
@ -233,7 +230,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
'statustext': field.help,
'needed': field.needed,
'readonly': this.getArrayMgr("readonlys").isReadOnly(id, null, this.options.readonly),
'value': this.options.value[this.prefix + field_name]
'value': this.options.value[et2_customfields_list.PREFIX + field_name]
};
// Can't have a required readonly, it will warn & be removed later, so avoid the warning
if(attrs.readonly === true) delete attrs.needed;
@ -338,7 +335,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
_attrs["value"] = {};
if (val !== null)
{
if(this.id.indexOf(this.prefix) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(this.prefix,'')] === true)
if(this.id.indexOf(et2_customfields_list.PREFIX) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(et2_customfields_list.PREFIX,'')] === true)
{
_attrs['value'][this.id] = val;
}
@ -347,7 +344,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// Only set the values that match desired custom fields
for(let key in val)
{
if(key.indexOf(this.prefix) == 0) {
if(key.indexOf(et2_customfields_list.PREFIX) == 0) {
_attrs["value"][key] = val[key];
}
}
@ -359,7 +356,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// Check for custom fields directly in record
for(var key in _attrs.customfields)
{
_attrs["value"][this.prefix + key] = contentMgr.getEntry(this.prefix + key);
_attrs["value"][et2_customfields_list.PREFIX + key] = contentMgr.getEntry(et2_customfields_list.PREFIX + key);
}
}
}
@ -384,12 +381,12 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// Make sure widget is created, and has the needed function
if(!this.widgets[field_name] || !this.widgets[field_name].set_value) continue;
let value = _value[this.prefix + field_name] ? _value[this.prefix + field_name] : null;
let value = _value[et2_customfields_list.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(this.prefix + field_name))
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(this.prefix + field_name);
value = this.getArrayMgr("content").getEntry(et2_customfields_list.PREFIX + field_name);
}
switch(this.options.customfields[field_name].type)
@ -423,7 +420,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
{
if(this.widgets[field_name].getValue && !this.widgets[field_name].options.readonly)
{
value[this.prefix + field_name] = this.widgets[field_name].getValue();
value[et2_customfields_list.PREFIX + field_name] = this.widgets[field_name].getValue();
}
}
return value;
@ -551,7 +548,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
// be overwritten by the site config from the server
const data = this.getArrayMgr("modifications").getEntry(this.prefix + field_name);
const data = this.getArrayMgr("modifications").getEntry(et2_customfields_list.PREFIX + field_name);
if(data) jQuery.extend(data.config, attrs.config);
return true;
@ -716,15 +713,15 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
{
for(let name in _fields)
{
if(this.rows[this.prefix + name])
if(this.rows[et2_customfields_list.PREFIX + name])
{
if(_fields[name])
{
jQuery(this.rows[this.prefix+name]).show();
jQuery(this.rows[et2_customfields_list.PREFIX+name]).show();
}
else
{
jQuery(this.rows[this.prefix+name]).hide();
jQuery(this.rows[et2_customfields_list.PREFIX+name]).hide();
}
}
this.options.fields[name] = _fields[name];
@ -753,7 +750,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
{
// toggle() needs a boolean to do what we want
const key = _nodes[i].getAttribute('data-field');
jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[this.prefix + key]?true:false);
jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[et2_customfields_list.PREFIX + key]?true:false);
}
}
}

View File

@ -63,7 +63,6 @@ var et2_core_DOMWidget_1 = require("./et2_core_DOMWidget");
var et2_core_baseWidget_1 = require("./et2_core_baseWidget");
var et2_core_inputWidget_1 = require("./et2_core_inputWidget");
var et2_widget_selectbox_1 = require("./et2_widget_selectbox");
//import {et2_selectAccount} from "./et2_widget_SelectAccount";
var et2_extension_nextmatch_rowProvider_1 = require("./et2_extension_nextmatch_rowProvider");
var et2_extension_nextmatch_controller_1 = require("./et2_extension_nextmatch_controller");
var et2_dataview_1 = require("./et2_dataview");
@ -118,7 +117,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
var prefs = _this._getPreferences();
var cfs = {};
for (var i = 0; i < prefs.visible.length; i++) {
if (prefs.visible[i].indexOf(et2_nextmatch_customfields.prefix) == 0) {
if (prefs.visible[i].indexOf(et2_nextmatch_customfields.PREFIX) == 0) {
cfs[prefs.visible[i].substr(1)] = !prefs.negated;
}
}
@ -792,7 +791,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
colName = widget.id;
for (var name_1 in widget.options.fields) {
if (widget.options.fields[name_1])
custom_fields.push(et2_nextmatch_customfields.prefix + name_1);
custom_fields.push(et2_nextmatch_customfields.PREFIX + name_1);
}
}
if (visibility[colMgr.columns[i].id].visible)
@ -1073,10 +1072,10 @@ var et2_nextmatch = /** @class */ (function (_super) {
continue;
}
for (var field_name in widget.customfields) {
columns[et2_nextmatch_customfields.prefix + field_name] = " - " +
columns[et2_nextmatch_customfields.PREFIX + field_name] = " - " +
widget.customfields[field_name].label;
if (widget.options.fields[field_name])
columns_selected.push(et2_extension_customfields_1.et2_customfields_list.prefix + field_name);
columns_selected.push(et2_extension_customfields_1.et2_customfields_list.PREFIX + field_name);
}
}
}
@ -1162,7 +1161,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
}
// Turn on selected custom fields - start from 0 in case they're not in order
for (var j = 0; j < value.length; j++) {
if (value[j].indexOf(et2_extension_customfields_1.et2_customfields_list.prefix) != 0)
if (value[j].indexOf(et2_extension_customfields_1.et2_customfields_list.PREFIX) != 0)
continue;
visible[value[j].substring(1)] = true;
i++;
@ -1182,7 +1181,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
self.sortedColumnsList.push(col_widget.id);
for (var field_name_1 in col_widget.customfields) {
if (jQuery.isEmptyObject(col_widget.options.fields) || col_widget.options.fields[field_name_1] == true) {
self.sortedColumnsList.push(et2_extension_customfields_1.et2_customfields_list.prefix + field_name_1);
self.sortedColumnsList.push(et2_extension_customfields_1.et2_customfields_list.PREFIX + field_name_1);
}
}
}
@ -1305,7 +1304,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
}
// Turn on selected custom fields - start from 0 in case they're not in order
for (var j = 0; j < column_list.length; j++) {
if (column_list[j].indexOf(et2_extension_customfields_1.et2_customfields_list.prefix) != 0)
if (column_list[j].indexOf(et2_extension_customfields_1.et2_customfields_list.PREFIX) != 0)
continue;
visible[column_list[j].substring(1)] = true;
}
@ -1765,9 +1764,9 @@ var et2_nextmatch = /** @class */ (function (_super) {
if (col.visibility === et2_dataview_grid.ET2_COL_VISIBILITY_VISIBLE && !jQuery.isEmptyObject(widget.customfields)) {
columns[colName] = col.caption;
for (var field_name in widget.customfields) {
columns[et2_nextmatch_customfields.prefix + field_name] = " - " + widget.customfields[field_name].label;
columns[et2_nextmatch_customfields.PREFIX + field_name] = " - " + widget.customfields[field_name].label;
if (widget.options.fields[field_name] && columns_selected.indexOf(colName) >= 0) {
columns_selected.push(et2_nextmatch_customfields.prefix + field_name);
columns_selected.push(et2_nextmatch_customfields.PREFIX + field_name);
}
}
}
@ -2738,7 +2737,7 @@ var et2_nextmatch_customfields = /** @class */ (function (_super) {
var apps = egw.link_app_list();
for (var field_name in this.options.customfields) {
var field = this.options.customfields[field_name];
var cf_id = et2_extension_customfields_1.et2_customfields_list.prefix + field_name;
var cf_id = et2_extension_customfields_1.et2_customfields_list.PREFIX + field_name;
if (this.rows[field_name])
continue;
// Table row
@ -2821,7 +2820,7 @@ var et2_nextmatch_customfields = /** @class */ (function (_super) {
var visible = [];
for (var field_name in this.options.customfields) {
if (jQuery.isEmptyObject(this.options.fields) || this.options.fields[field_name] == true) {
visible.push(et2_extension_customfields_1.et2_customfields_list.prefix + field_name);
visible.push(et2_extension_customfields_1.et2_customfields_list.PREFIX + field_name);
jQuery(this.rows[field_name]).show();
}
else if (typeof this.rows[field_name] != "undefined") {

View File

@ -257,7 +257,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
const cfs = {};
for(let i = 0; i < prefs.visible.length; i++)
{
if(prefs.visible[i].indexOf(et2_nextmatch_customfields.prefix) == 0)
if(prefs.visible[i].indexOf(et2_nextmatch_customfields.PREFIX) == 0)
{
cfs[prefs.visible[i].substr(1)] = !prefs.negated;
}
@ -1114,7 +1114,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Just the ID for server side, not the whole nm name - some apps use it to skip custom fields
colName = widget.id;
for(let name in widget.options.fields) {
if(widget.options.fields[name]) custom_fields.push(et2_nextmatch_customfields.prefix+name);
if(widget.options.fields[name]) custom_fields.push(et2_nextmatch_customfields.PREFIX+name);
}
}
if(visibility[colMgr.columns[i].id].visible) colDisplay.push(colName);
@ -1515,9 +1515,9 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
}
for(var field_name in (<et2_nextmatch_customfields><unknown>widget).customfields)
{
columns[et2_nextmatch_customfields.prefix+field_name] = " - "+
columns[et2_nextmatch_customfields.PREFIX+field_name] = " - "+
(<et2_nextmatch_customfields><unknown>widget).customfields[field_name].label;
if(widget.options.fields[field_name]) columns_selected.push(et2_customfields_list.prefix+field_name);
if(widget.options.fields[field_name]) columns_selected.push(et2_customfields_list.PREFIX+field_name);
}
}
}
@ -1622,7 +1622,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Turn on selected custom fields - start from 0 in case they're not in order
for(let j = 0; j < value.length; j++)
{
if(value[j].indexOf(et2_customfields_list.prefix) != 0) continue;
if(value[j].indexOf(et2_customfields_list.PREFIX) != 0) continue;
visible[value[j].substring(1)] = true;
i++;
}
@ -1646,7 +1646,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
{
if(jQuery.isEmptyObject(col_widget.options.fields) || col_widget.options.fields[field_name] == true)
{
self.sortedColumnsList.push(et2_customfields_list.prefix + field_name);
self.sortedColumnsList.push(et2_customfields_list.PREFIX + field_name);
}
}
}
@ -1796,7 +1796,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Turn on selected custom fields - start from 0 in case they're not in order
for(let j = 0; j < column_list.length; j++)
{
if(column_list[j].indexOf(et2_customfields_list.prefix) != 0) continue;
if(column_list[j].indexOf(et2_customfields_list.PREFIX) != 0) continue;
visible[column_list[j].substring(1)] = true;
}
(<et2_nextmatch_customfields><unknown>widget).set_visible(visible);
@ -2381,10 +2381,10 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
columns[colName] = col.caption;
for(let field_name in (<et2_nextmatch_customfields><unknown>widget).customfields)
{
columns[et2_nextmatch_customfields.prefix+field_name] = " - "+(<et2_nextmatch_customfields><unknown>widget).customfields[field_name].label;
columns[et2_nextmatch_customfields.PREFIX+field_name] = " - "+(<et2_nextmatch_customfields><unknown>widget).customfields[field_name].label;
if(widget.options.fields[field_name] && columns_selected.indexOf(colName) >= 0)
{
columns_selected.push(et2_nextmatch_customfields.prefix+field_name);
columns_selected.push(et2_nextmatch_customfields.PREFIX+field_name);
}
}
}
@ -3477,7 +3477,7 @@ export class et2_nextmatch_customfields extends et2_customfields_list implements
for(let field_name in this.options.customfields)
{
const field = this.options.customfields[field_name];
const cf_id = et2_customfields_list.prefix + field_name;
const cf_id = et2_customfields_list.PREFIX + field_name;
if(this.rows[field_name]) continue;
@ -3587,7 +3587,7 @@ export class et2_nextmatch_customfields extends et2_customfields_list implements
{
if(jQuery.isEmptyObject(this.options.fields) || this.options.fields[field_name] == true)
{
visible.push(et2_customfields_list.prefix + field_name);
visible.push(et2_customfields_list.PREFIX + field_name);
jQuery(this.rows[field_name]).show();
}
else if (typeof this.rows[field_name] != "undefined")