2020-02-11 23:20:01 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - JS Custom fields object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
2021-06-07 17:33:53 +02:00
|
|
|
* @link https://www.egroupware.org
|
2020-02-11 23:20:01 +01:00
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright Nathan Gray 2011
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
lib/tooltip;
|
|
|
|
/vendor/bower-asset/jquery/dist/jquery.js;
|
|
|
|
et2_core_xml;
|
|
|
|
et2_core_DOMWidget;
|
|
|
|
et2_core_inputWidget;
|
|
|
|
*/
|
|
|
|
|
2021-06-07 17:33:53 +02:00
|
|
|
import {et2_createWidget, et2_register_widget, et2_registry, WidgetConfig} from "./et2_core_widget";
|
2020-02-11 23:20:01 +01:00
|
|
|
import {ClassWithAttributes} from "./et2_core_inheritance";
|
|
|
|
import {et2_valueWidget} from "./et2_core_valueWidget";
|
2021-06-04 18:50:23 +02:00
|
|
|
import {et2_readonlysArrayMgr} from "./et2_core_arrayMgr";
|
2021-06-07 17:33:53 +02:00
|
|
|
import {et2_IDetachedDOM, et2_IInput} from "./et2_core_interfaces";
|
|
|
|
import {et2_cloneObject, et2_no_init} from "./et2_core_common";
|
|
|
|
import {et2_DOMWidget} from "./et2_core_DOMWidget";
|
2022-05-02 13:52:53 +02:00
|
|
|
import {loadWebComponent} from "./Et2Widget/Et2Widget";
|
2023-09-13 19:55:33 +02:00
|
|
|
import {LitElement} from "lit";
|
2024-02-26 22:26:14 +01:00
|
|
|
import {Et2VfsSelectButton} from "./Et2Vfs/Et2VfsSelectButton";
|
2024-03-20 20:49:09 +01:00
|
|
|
import {Et2Tabs} from "./Layout/Et2Tabs/Et2Tabs";
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
export class et2_customfields_list extends et2_valueWidget implements et2_IDetachedDOM, et2_IInput
|
|
|
|
{
|
|
|
|
static readonly _attributes = {
|
|
|
|
'customfields': {
|
|
|
|
'name': 'Custom fields',
|
|
|
|
'description': 'Auto filled',
|
|
|
|
'type': 'any'
|
|
|
|
},
|
|
|
|
'fields': {
|
|
|
|
'name': 'Custom fields',
|
|
|
|
'description': 'Auto filled',
|
|
|
|
'type': 'any'
|
|
|
|
},
|
2024-03-25 16:01:51 +01:00
|
|
|
exclude: {
|
|
|
|
name: 'Fields to exclude',
|
|
|
|
description: 'comma-separated list of fields to exclude',
|
|
|
|
type: 'string',
|
|
|
|
default: undefined,
|
|
|
|
},
|
2020-02-11 23:20:01 +01:00
|
|
|
'value': {
|
|
|
|
'name': 'Custom fields',
|
|
|
|
'description': 'Auto filled',
|
|
|
|
'type': "any"
|
|
|
|
},
|
|
|
|
'type_filter': {
|
|
|
|
'name': 'Field filter',
|
|
|
|
"default": "",
|
|
|
|
"type": "any", // String or array
|
2024-03-20 20:49:09 +01:00
|
|
|
"description": "Filter displayed custom fields by their 'type2' attribute, use 'previous' for the filter of the previous / regular cf widget"
|
2020-02-11 23:20:01 +01:00
|
|
|
},
|
|
|
|
'private': {
|
|
|
|
ignore: true,
|
|
|
|
type: 'boolean'
|
|
|
|
},
|
|
|
|
'sub_app': {
|
|
|
|
'name': 'sub app name',
|
|
|
|
'type': "string",
|
|
|
|
'description': "Name of sub application"
|
|
|
|
},
|
|
|
|
// Allow onchange so you can put handlers on the sub-widgets
|
|
|
|
'onchange': {
|
|
|
|
"name": "onchange",
|
|
|
|
"type": "string",
|
|
|
|
"default": et2_no_init,
|
|
|
|
"description": "JS code which is executed when the value changes."
|
2020-06-30 18:43:19 +02:00
|
|
|
},
|
2024-03-20 20:49:09 +01:00
|
|
|
// filter cfs by a given tab value
|
|
|
|
'tab': {
|
|
|
|
name: "tab",
|
|
|
|
type: "string",
|
|
|
|
default: null,
|
|
|
|
description: "only show cfs with the given tab attribute value, use 'panel' for the tab-panel the widget is in"
|
|
|
|
},
|
2020-06-30 18:43:19 +02:00
|
|
|
// Allow changing the field prefix. Normally it's the constant but importexport filter changes it.
|
|
|
|
"prefix": {
|
|
|
|
name: "prefix",
|
|
|
|
type: "string",
|
2020-07-02 17:40:09 +02:00
|
|
|
default: "#",
|
2020-06-30 18:43:19 +02:00
|
|
|
description: "Custom prefix for custom fields. Default #"
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-30 18:28:48 +02:00
|
|
|
public static readonly legacyOptions = ["type_filter","private", "fields"]; // Field restriction & private done server-side
|
2020-02-11 23:20:01 +01:00
|
|
|
|
2020-02-12 19:32:29 +01:00
|
|
|
public static readonly PREFIX = '#';
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
public static readonly DEFAULT_ID = "custom_fields";
|
|
|
|
private tbody: JQuery;
|
|
|
|
private table: JQuery;
|
|
|
|
private rows = {};
|
2021-06-07 17:33:53 +02:00
|
|
|
widgets = {};
|
2020-02-11 23:20:01 +01:00
|
|
|
private detachedNodes = [];
|
|
|
|
|
2024-03-20 20:49:09 +01:00
|
|
|
static previous_type_filter;
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
constructor(_parent?, _attrs? : WidgetConfig, _child? : object)
|
|
|
|
{
|
|
|
|
super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_customfields_list._attributes, _child || {}));
|
|
|
|
|
|
|
|
// Some apps (infolog edit) don't give ID, so assign one to get settings
|
|
|
|
if(!this.id)
|
|
|
|
{
|
|
|
|
this.id = _attrs.id = et2_customfields_list.DEFAULT_ID;
|
|
|
|
|
|
|
|
// Add all attributes hidden in the content arrays to the attributes
|
|
|
|
// parameter
|
|
|
|
this.transformAttributes(_attrs);
|
|
|
|
|
|
|
|
// Create a local copy of the options object
|
|
|
|
this.options = et2_cloneObject(_attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the table body and the table
|
|
|
|
this.tbody = jQuery(document.createElement("tbody"));
|
|
|
|
this.table = jQuery(document.createElement("table"))
|
|
|
|
.addClass("et2_grid et2_customfield_list");
|
|
|
|
this.table.append(this.tbody);
|
|
|
|
|
|
|
|
if(!this.options.fields) this.options.fields = {};
|
|
|
|
if(typeof this.options.fields === 'string')
|
|
|
|
{
|
|
|
|
const fields = this.options.fields.split(',');
|
|
|
|
this.options.fields = {};
|
|
|
|
for(var i = 0; i < fields.length; i++)
|
|
|
|
{
|
|
|
|
this.options.fields[fields[i]] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 20:49:09 +01:00
|
|
|
// allow to use previous type_filter
|
|
|
|
if (this.options.type_filter === "previous")
|
|
|
|
{
|
|
|
|
this.options.type_filter = et2_customfields_list.previous_type_filter;
|
|
|
|
}
|
|
|
|
et2_customfields_list.previous_type_filter = this.options.type_filter;
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
if(this.options.type_filter && typeof this.options.type_filter == "string")
|
|
|
|
{
|
|
|
|
this.options.type_filter = this.options.type_filter.split(",");
|
|
|
|
}
|
|
|
|
if(this.options.type_filter)
|
|
|
|
{
|
|
|
|
for(let field_name in this.options.customfields)
|
|
|
|
{
|
|
|
|
if(!this.options.customfields[field_name].type2 || this.options.customfields[field_name].type2.length == 0 ||
|
|
|
|
this.options.customfields[field_name].type2 == '0')
|
|
|
|
{
|
|
|
|
// No restrictions
|
|
|
|
this.options.fields[field_name] = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const types = typeof this.options.customfields[field_name].type2 == 'string' ? this.options.customfields[field_name].type2.split(",") : this.options.customfields[field_name].type2;
|
|
|
|
this.options.fields[field_name] = false;
|
|
|
|
for(var i = 0; i < types.length; i++)
|
|
|
|
{
|
|
|
|
if(jQuery.inArray(types[i],this.options.type_filter) > -1)
|
|
|
|
{
|
|
|
|
this.options.fields[field_name] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 09:28:27 +01:00
|
|
|
// tab === "panel" --> use label of tab panel
|
2024-03-25 15:03:48 +01:00
|
|
|
const default_tab = Et2Tabs.getTabPanel(this)?.match(/^cf-default(-(non-)?private)?$/);
|
2024-03-20 20:49:09 +01:00
|
|
|
if (this.options.tab === 'panel')
|
|
|
|
{
|
2024-03-25 15:03:48 +01:00
|
|
|
if (default_tab)
|
|
|
|
{
|
|
|
|
this.options.tab = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.options.tab = Et2Tabs.getTabPanel(this, true);
|
|
|
|
}
|
2024-03-20 20:49:09 +01:00
|
|
|
}
|
2024-03-25 16:01:51 +01:00
|
|
|
const exclude : Array<string> = this.options.exclude ? this.options.exclude.split(',') : [];
|
2024-03-21 09:28:27 +01:00
|
|
|
// filter fields additionally by tab attribute
|
2024-03-20 20:49:09 +01:00
|
|
|
if (typeof this.options.fields === "undefined" || !Object.keys(this.options.fields).length)
|
|
|
|
{
|
|
|
|
this.options.fields = {};
|
|
|
|
for(let field_name in this.options.customfields)
|
|
|
|
{
|
2024-03-25 16:01:51 +01:00
|
|
|
if (exclude.indexOf(field_name) >= 0) continue;
|
2024-03-20 20:49:09 +01:00
|
|
|
if (this.options.customfields[field_name].tab === this.options.tab)
|
|
|
|
{
|
|
|
|
this.options.fields[field_name] = true;
|
|
|
|
}
|
2024-03-25 15:03:48 +01:00
|
|
|
else if (default_tab)
|
|
|
|
{
|
|
|
|
if (this.options.customfields[field_name].private.length) // private cf
|
|
|
|
{
|
|
|
|
this.options.fields[field_name] = default_tab[1] !== '-non-private';
|
|
|
|
}
|
|
|
|
else // non-private cf
|
|
|
|
{
|
|
|
|
this.options.fields[field_name] = default_tab[1] !== '-private';
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 20:49:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(let field_name in this.options.customfields)
|
|
|
|
{
|
2024-03-25 16:01:51 +01:00
|
|
|
if (exclude.indexOf(field_name) >= 0)
|
|
|
|
{
|
|
|
|
this.options.fields[field_name] = false;
|
|
|
|
}
|
|
|
|
else if (default_tab ? this.options.customfields[field_name].tab : this.options.customfields[field_name].tab !== this.options.tab)
|
2024-03-20 20:49:09 +01:00
|
|
|
{
|
2024-03-21 09:28:27 +01:00
|
|
|
this.options.fields[field_name] = false;
|
|
|
|
}
|
2024-03-25 15:03:48 +01:00
|
|
|
else if (default_tab)
|
|
|
|
{
|
|
|
|
if (this.options.customfields[field_name].private.length) // private cf
|
|
|
|
{
|
|
|
|
this.options.fields[field_name] = default_tab[1] !== '-non-private';
|
|
|
|
}
|
2024-03-25 18:52:21 +01:00
|
|
|
else if (this.options.fields[field_name]) // non-private cf
|
2024-03-25 15:03:48 +01:00
|
|
|
{
|
|
|
|
this.options.fields[field_name] = default_tab[1] !== '-private';
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 20:49:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
this.setDOMNode(this.table[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy( )
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
this.rows = {};
|
|
|
|
this.widgets = {};
|
|
|
|
this.detachedNodes = [];
|
|
|
|
this.tbody = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What does this do? I don't know, but when everything is done the second
|
|
|
|
* time, this makes it work. Otherwise, all custom fields are lost.
|
|
|
|
*/
|
|
|
|
assign( _obj)
|
|
|
|
{
|
|
|
|
this.loadFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
getDOMNode( _sender)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Check whether the _sender object exists inside the management array
|
2021-05-13 18:01:38 +02:00
|
|
|
if (this.rows && _sender.id && this.rows[_sender.id]) {
|
2020-02-11 23:20:01 +01:00
|
|
|
return this.rows[_sender.id];
|
|
|
|
}
|
2021-05-13 18:01:38 +02:00
|
|
|
if (this.rows && _sender.id && _sender.id.indexOf("_label") && this.rows[_sender.id.replace("_label", "")])
|
|
|
|
{
|
|
|
|
return jQuery(this.rows[_sender.id.replace("_label","")]).prev("td")[0] || null;
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
return super.getDOMNode(_sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize widgets for custom fields
|
|
|
|
*/
|
|
|
|
loadFields( )
|
|
|
|
{
|
|
|
|
if(!this.options || !this.options.customfields) return;
|
|
|
|
|
|
|
|
// Already set up - avoid duplicates in nextmatch
|
2020-12-17 17:17:38 +01:00
|
|
|
if(this.getType() == 'customfields-list' && !this.isInTree() && Object.keys(this.widgets).length > 0) return;
|
2020-02-11 23:20:01 +01:00
|
|
|
if(!jQuery.isEmptyObject(this.widgets)) return;
|
|
|
|
|
|
|
|
// Check for global setting changes (visibility)
|
|
|
|
const global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~');
|
|
|
|
if(global_data && global_data.fields && !this.options.fields) this.options.fields = global_data.fields;
|
|
|
|
|
|
|
|
// For checking app entries
|
|
|
|
const apps = this.egw().link_app_list();
|
|
|
|
|
|
|
|
// Create the table rows
|
|
|
|
for(let field_name in this.options.customfields)
|
|
|
|
{
|
|
|
|
// Skip fields if we're filtering
|
|
|
|
if(this.getType() != 'customfields-list' && !jQuery.isEmptyObject(this.options.fields) && !this.options.fields[field_name]) continue;
|
|
|
|
|
|
|
|
const field = this.options.customfields[field_name];
|
|
|
|
|
2020-06-30 18:43:19 +02:00
|
|
|
let id = this.options.prefix + field_name;
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
// Need curlies around ID for nm row expansion
|
|
|
|
if(this.id == '$row')
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
id = "{" + this.id + "}" + "["+this.options.prefix + field_name+"]";
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
else if (this.id != et2_customfields_list.DEFAULT_ID)
|
|
|
|
{
|
|
|
|
// Prefix this ID to avoid potential ID collisions
|
|
|
|
id = this.id + "["+id+"]";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid creating field twice
|
|
|
|
if(!this.rows[id])
|
|
|
|
{
|
|
|
|
const row = jQuery(document.createElement("tr"))
|
|
|
|
.appendTo(this.tbody)
|
|
|
|
.addClass(this.id + '_' + id);
|
|
|
|
let cf = jQuery(document.createElement("td"))
|
|
|
|
.appendTo(row);
|
|
|
|
if(!field.type) field.type = 'text";';
|
|
|
|
const setup_function = '_setup_' + (apps[field.type] ? 'link_entry' : field.type.replace("-", "_"));
|
|
|
|
|
2020-04-15 19:21:53 +02:00
|
|
|
const attrs: any = jQuery.extend({},this.options[field_name] ? this.options[field_name] : {}, {
|
2020-02-11 23:20:01 +01:00
|
|
|
'id': id,
|
2022-05-02 13:52:53 +02:00
|
|
|
'statustext': field.help || '',
|
2020-02-11 23:20:01 +01:00
|
|
|
'needed': field.needed,
|
2021-06-04 18:50:23 +02:00
|
|
|
'readonly':( <et2_readonlysArrayMgr> this.getArrayMgr("readonlys")).isReadOnly(id, ""+this.options.readonly),
|
2020-06-30 18:43:19 +02:00
|
|
|
'value': this.options.value[this.options.prefix + field_name]
|
2020-04-15 19:21:53 +02:00
|
|
|
});
|
2020-02-11 23:20:01 +01:00
|
|
|
// Can't have a required readonly, it will warn & be removed later, so avoid the warning
|
|
|
|
if(attrs.readonly === true) delete attrs.needed;
|
|
|
|
|
|
|
|
if(this.options.onchange)
|
|
|
|
{
|
|
|
|
attrs.onchange = this.options.onchange;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this[setup_function]) {
|
|
|
|
const no_skip = this[setup_function].call(this, field_name, field, attrs);
|
|
|
|
if(!no_skip) continue;
|
|
|
|
}
|
2021-05-13 18:01:38 +02:00
|
|
|
this.rows[id] = cf[0];
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
if(this.getType() == 'customfields-list') {
|
2022-05-02 13:52:53 +02:00
|
|
|
// No label, custom widget
|
2020-02-11 23:20:01 +01:00
|
|
|
attrs.readonly = true;
|
|
|
|
// Widget tooltips don't work in nextmatch because of the creation / binding separation
|
|
|
|
// Set title to field label so browser will show something
|
|
|
|
// Add field label & help as data attribute to row, so it can be stylied with CSS (title should be disabled)
|
|
|
|
row.attr('title', field.label);
|
|
|
|
row.attr('data-label', field.label);
|
|
|
|
row.attr('data-field', field_name);
|
|
|
|
row.attr('data-help', field.help);
|
|
|
|
this.detachedNodes.push(row[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Label in first column, widget in 2nd
|
2023-07-26 14:20:13 +02:00
|
|
|
const label = this.options.label || field.label || '';
|
2024-03-27 16:06:38 +01:00
|
|
|
const label_td = jQuery(document.createElement("td")).prependTo(row);
|
|
|
|
if (['label','header'].indexOf(attrs.type || field.type) !== -1)
|
|
|
|
{
|
|
|
|
label_td.attr('colspan', 2).addClass('et2_customfield_'+(attrs.type || field.type));
|
|
|
|
}
|
2023-06-29 18:52:20 +02:00
|
|
|
et2_createWidget("label", {id: id + "_label", value: label.trim(), for: id}, this);
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
|
2022-05-02 13:52:53 +02:00
|
|
|
const type = attrs.type ? attrs.type : field.type;
|
2020-02-11 23:20:01 +01:00
|
|
|
// Set any additional attributes set in options, but not for widgets that pass actual options
|
2024-02-08 21:26:07 +01:00
|
|
|
if(['select','radio','radiogroup','checkbox','button'].indexOf(field.type) == -1 &&
|
|
|
|
setup_function !== '_setup_link_entry' && !jQuery.isEmptyObject(field.values))
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
2022-05-02 13:52:53 +02:00
|
|
|
const w = et2_registry[type];
|
2022-07-08 17:40:16 +02:00
|
|
|
const wc = window.customElements.get('et2-' + type);
|
|
|
|
if(wc)
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
2022-05-02 13:52:53 +02:00
|
|
|
for(let attr_name in field.values)
|
2020-03-05 23:37:42 +01:00
|
|
|
{
|
2022-07-08 17:40:16 +02:00
|
|
|
if(wc.getPropertyOptions(attr_name))
|
2022-05-02 13:52:53 +02:00
|
|
|
{
|
|
|
|
attrs[attr_name] = field.values[attr_name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-08 17:40:16 +02:00
|
|
|
else if(typeof w !== 'undefined')
|
2022-05-02 13:52:53 +02:00
|
|
|
{
|
2022-07-08 17:40:16 +02:00
|
|
|
for(let attr_name in field.values)
|
2022-05-02 13:52:53 +02:00
|
|
|
{
|
2022-07-08 17:40:16 +02:00
|
|
|
if(typeof w._attributes[attr_name] != "undefined")
|
2022-05-02 13:52:53 +02:00
|
|
|
{
|
2022-07-08 17:40:16 +02:00
|
|
|
attrs[attr_name] = field.values[attr_name];
|
2022-05-02 13:52:53 +02:00
|
|
|
}
|
2020-03-05 23:37:42 +01:00
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Create widget
|
2022-07-08 17:40:16 +02:00
|
|
|
if(window.customElements.get('et2-' + type))
|
2022-05-02 13:52:53 +02:00
|
|
|
{
|
|
|
|
if (typeof attrs.needed !== 'undefined')
|
|
|
|
{
|
|
|
|
attrs.required = attrs.needed;
|
|
|
|
delete attrs.needed;
|
|
|
|
}
|
2022-08-24 08:47:53 +02:00
|
|
|
if (typeof attrs.size !== 'undefined' && ['small', 'medium', 'large'].indexOf(attrs.size) === -1)
|
|
|
|
{
|
|
|
|
if (attrs.size > 0) attrs.width = attrs.size+'em';
|
|
|
|
delete attrs.size;
|
|
|
|
}
|
2022-07-08 17:40:16 +02:00
|
|
|
//this.widgets[field_name] = loadWebComponent('et2-' + type, attrs, null);
|
|
|
|
// et2_extension_customfields.getDOMNode() needs webcomponent to have ID before it can put it in
|
|
|
|
let wc = <LitElement>loadWebComponent('et2-' + type, attrs, this);
|
|
|
|
wc.setParent(this);
|
|
|
|
wc.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.widgets[field_name] = wc;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else if(typeof et2_registry[type] !== 'undefined')
|
|
|
|
{
|
|
|
|
this.widgets[field_name] = et2_createWidget(type, attrs, this);
|
2022-05-02 13:52:53 +02:00
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Field is not to be shown
|
|
|
|
if(!this.options.fields || jQuery.isEmptyObject(this.options.fields) || this.options.fields[field_name] == true)
|
|
|
|
{
|
|
|
|
jQuery(this.rows[field_name]).show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jQuery(this.rows[field_name]).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read needed info on available custom fields from various places it's stored.
|
|
|
|
*/
|
|
|
|
transformAttributes( _attrs)
|
|
|
|
{
|
|
|
|
super.transformAttributes(_attrs);
|
|
|
|
|
|
|
|
// Add in settings that are objects
|
|
|
|
|
|
|
|
// Customized settings for this widget (unlikely)
|
2023-10-13 18:01:24 +02:00
|
|
|
const data = this.id ? this.getArrayMgr("modifications").getEntry(this.id) ?? {} : {};
|
2020-02-11 23:20:01 +01:00
|
|
|
// Check for global settings
|
|
|
|
const global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~', true);
|
|
|
|
if(global_data)
|
|
|
|
{
|
|
|
|
for(let key in data)
|
|
|
|
{
|
2024-04-29 21:57:06 +02:00
|
|
|
// Don't overwrite fields / customfields with global values
|
2024-05-04 08:10:36 +02:00
|
|
|
if (global_data[key] && key !== 'fields' && (key !== "customfields" || !data.customfields || !Object.keys(data.customfields).length))
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
2024-04-29 21:57:06 +02:00
|
|
|
data[key] = {...data[key], ...global_data[key]};
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(var key in data)
|
|
|
|
{
|
|
|
|
_attrs[key] = data[key];
|
|
|
|
}
|
|
|
|
for(let key in global_data)
|
|
|
|
{
|
|
|
|
if(typeof global_data[key] != 'undefined' && ! _attrs[key]) _attrs[key] = global_data[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.id)
|
|
|
|
{
|
|
|
|
// Set the value for this element
|
|
|
|
const contentMgr = this.getArrayMgr("content");
|
|
|
|
if (contentMgr != null) {
|
|
|
|
const val = contentMgr.getEntry(this.id);
|
|
|
|
_attrs["value"] = {};
|
2020-06-30 18:43:19 +02:00
|
|
|
let prefix = _attrs["prefix"] || et2_customfields_list.PREFIX;
|
2020-02-11 23:20:01 +01:00
|
|
|
if (val !== null)
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
if(this.id.indexOf(prefix) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(prefix,'')] === true)
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
|
|
|
_attrs['value'][this.id] = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Only set the values that match desired custom fields
|
|
|
|
for(let key in val)
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
if(key.indexOf(prefix) === 0) {
|
2020-02-11 23:20:01 +01:00
|
|
|
_attrs["value"][key] = val[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//_attrs["value"] = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check for custom fields directly in record
|
|
|
|
for(var key in _attrs.customfields)
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
_attrs["value"][prefix + key] = contentMgr.getEntry(prefix + key);
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-29 18:52:20 +02:00
|
|
|
loadFromXML(_node)
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
|
|
|
this.loadFields();
|
|
|
|
|
|
|
|
// Load the nodes as usual
|
|
|
|
super.loadFromXML(_node);
|
|
|
|
}
|
|
|
|
|
2023-06-29 18:52:20 +02:00
|
|
|
set_label(_value : string)
|
|
|
|
{
|
|
|
|
// If we've got a field list, or all fields use normal label
|
|
|
|
if(this.getType() == 'customfields-list' || jQuery.isEmptyObject(this.options.fields) ||
|
|
|
|
Object.keys(this.options.fields).filter(f => this.options.fields[f]).length != 1)
|
|
|
|
{
|
|
|
|
return super.set_label(_value);
|
|
|
|
}
|
|
|
|
// For single field, we apply the widget label to the single field
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
set_value( _value)
|
|
|
|
{
|
|
|
|
if(!this.options.customfields) return;
|
|
|
|
for(let field_name in this.options.customfields)
|
|
|
|
{
|
|
|
|
// Skip fields if we're filtering
|
|
|
|
if(!jQuery.isEmptyObject(this.options.fields) && !this.options.fields[field_name]) continue;
|
|
|
|
|
|
|
|
// Make sure widget is created, and has the needed function
|
|
|
|
if(!this.widgets[field_name] || !this.widgets[field_name].set_value) continue;
|
2020-12-17 17:17:38 +01:00
|
|
|
let value = _value[this.options.prefix + field_name] ? _value[this.options.prefix + field_name] : null;
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
// Check if ID was missing
|
2020-06-30 18:43:19 +02:00
|
|
|
if(value == null && this.id == et2_customfields_list.DEFAULT_ID && this.getArrayMgr("content").getEntry(this.options.prefix + field_name))
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
value = this.getArrayMgr("content").getEntry(this.options.prefix + field_name);
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(this.options.customfields[field_name].type)
|
|
|
|
{
|
|
|
|
case 'date':
|
|
|
|
// Date custom fields are always in Y-m-d, which seldom matches user's preference
|
|
|
|
// which fails when sent to date widget. This is only used for nm rows, when possible
|
|
|
|
// this is fixed server side
|
|
|
|
if(value && isNaN(value))
|
|
|
|
{
|
2022-05-02 13:52:53 +02:00
|
|
|
// ToDo: value = jQuery.datepicker.parseDate("yy-mm-dd",value);
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.widgets[field_name].set_value(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et2_IInput so the custom field can be it's own widget.
|
|
|
|
*/
|
|
|
|
getValue( )
|
|
|
|
{
|
|
|
|
// Not using an ID means we have to grab all the widget values, and put them where server knows to look
|
|
|
|
if(this.id != et2_customfields_list.DEFAULT_ID)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const value = {};
|
|
|
|
for(let field_name in this.widgets)
|
|
|
|
{
|
|
|
|
if(this.widgets[field_name].getValue && !this.widgets[field_name].options.readonly)
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
value[this.options.prefix + field_name] = this.widgets[field_name].getValue();
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
isDirty( )
|
|
|
|
{
|
2020-06-19 21:27:41 +02:00
|
|
|
let dirty = false;
|
2020-02-11 23:20:01 +01:00
|
|
|
for(let field_name in this.widgets)
|
|
|
|
{
|
|
|
|
if(this.widgets[field_name].isDirty)
|
|
|
|
{
|
2020-06-19 21:27:41 +02:00
|
|
|
dirty = dirty || this.widgets[field_name].isDirty();
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetDirty( )
|
|
|
|
{
|
|
|
|
for(let field_name in this.widgets)
|
|
|
|
{
|
|
|
|
if(this.widgets[field_name].resetDirty)
|
|
|
|
{
|
|
|
|
this.widgets[field_name].resetDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isValid( )
|
|
|
|
{
|
|
|
|
// Individual customfields will handle themselves
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adapt provided attributes to match options for widget
|
|
|
|
*
|
|
|
|
* rows > 1 --> textarea, with rows=rows and cols=len
|
|
|
|
* !rows --> input, with size=len
|
|
|
|
* rows = 1 --> input, with size=len, maxlength=len
|
|
|
|
*/
|
|
|
|
_setup_text( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
// No label on the widget itself
|
2022-08-29 17:21:49 +02:00
|
|
|
delete (attrs.label);
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
field.type = 'textbox';
|
|
|
|
attrs.rows = field.rows > 1 ? field.rows : null;
|
2022-08-29 17:21:49 +02:00
|
|
|
if(attrs.rows && attrs.rows > 0)
|
|
|
|
{
|
|
|
|
field.type = 'textarea';
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
if(field.len)
|
|
|
|
{
|
|
|
|
attrs.size = field.len;
|
2022-08-29 17:21:49 +02:00
|
|
|
if(field.rows == 1)
|
|
|
|
{
|
|
|
|
attrs.maxlength = field.len;
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
2022-08-30 21:28:15 +02:00
|
|
|
if(attrs.readonly)
|
|
|
|
{
|
|
|
|
field.type = 'description';
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
2022-08-29 17:21:49 +02:00
|
|
|
|
2020-06-12 18:56:44 +02:00
|
|
|
_setup_passwd( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
// No label on the widget itself
|
|
|
|
delete (attrs.label);
|
2023-08-02 23:05:33 +02:00
|
|
|
attrs.type = "password";
|
2020-07-21 23:36:45 +02:00
|
|
|
let defaults = {
|
|
|
|
viewable:true,
|
|
|
|
plaintext: false,
|
|
|
|
suggest: 16
|
|
|
|
};
|
|
|
|
for(let key of Object.keys(defaults))
|
|
|
|
{
|
|
|
|
attrs[key] = (field.values && typeof field.values[key] !== "undefined") ? field.values[key] : defaults[key];
|
|
|
|
}
|
|
|
|
|
2020-06-12 18:56:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
_setup_ajax_select( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
const attributes = ['get_rows', 'get_title', 'id_field', 'template'];
|
|
|
|
if(field.values)
|
|
|
|
{
|
|
|
|
for(let i = 0; i < attributes.length; i++)
|
|
|
|
{
|
|
|
|
if(typeof field.values[attributes[i]] !== 'undefined')
|
|
|
|
{
|
|
|
|
attrs[attributes[i]] = field.values[attributes[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2024-03-21 15:40:39 +01:00
|
|
|
|
2024-03-27 16:06:38 +01:00
|
|
|
_setup_serial(field_name, field, attrs)
|
|
|
|
{
|
|
|
|
delete (attrs.label);
|
2024-03-30 10:18:28 +01:00
|
|
|
field.type = "textbox"
|
2024-03-27 16:06:38 +01:00
|
|
|
attrs.readonly = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-21 15:40:39 +01:00
|
|
|
_setup_int(field_name, field, attrs)
|
|
|
|
{
|
|
|
|
delete (attrs.label);
|
|
|
|
field.type = "number"
|
|
|
|
attrs.precision = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
_setup_float( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
2024-03-21 15:40:39 +01:00
|
|
|
field.type = 'number';
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
if(field.len)
|
|
|
|
{
|
|
|
|
attrs.size = field.len;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2024-03-21 15:40:39 +01:00
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
_setup_select( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
// No label on the widget itself
|
2022-09-26 19:38:36 +02:00
|
|
|
delete (attrs.label);
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
attrs.rows = field.rows;
|
2022-09-26 19:38:36 +02:00
|
|
|
if(attrs.rows > 1)
|
|
|
|
{
|
|
|
|
attrs.multiple = true;
|
|
|
|
}
|
2023-07-22 00:39:47 +02:00
|
|
|
if(field.values && field.values["@"])
|
|
|
|
{
|
|
|
|
// Options are in a list stored in a file
|
2023-07-24 23:12:45 +02:00
|
|
|
attrs.searchUrl = field.values["@"];
|
2023-07-22 00:39:47 +02:00
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_setup_select_account( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
attrs.empty_label = egw.lang('Select');
|
|
|
|
if(field.account_type)
|
|
|
|
{
|
|
|
|
attrs.account_type = field.account_type;
|
|
|
|
}
|
|
|
|
return this._setup_select(field_name, field, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
_setup_date(field_name, field, attrs) {
|
|
|
|
attrs.data_format = field.values && field.values.format ? field.values.format : 'Y-m-d';
|
2023-09-13 17:08:00 +02:00
|
|
|
if(field.values?.format)
|
|
|
|
{
|
|
|
|
delete field.values.format;
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_setup_date_time( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
attrs.data_format = field.values && field.values.format ? field.values.format : 'Y-m-d H:i:s';
|
2023-09-13 17:08:00 +02:00
|
|
|
if(field.values?.format)
|
|
|
|
{
|
|
|
|
delete field.values.format;
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_setup_htmlarea( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
attrs.config = field.config ? field.config : {};
|
|
|
|
attrs.config.toolbarStartupExpanded = false;
|
|
|
|
if(field.len)
|
|
|
|
{
|
|
|
|
attrs.config.width = field.len+'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
|
|
|
|
// be overwritten by the site config from the server
|
2020-06-30 18:43:19 +02:00
|
|
|
const data = this.getArrayMgr("modifications").getEntry(this.options.prefix + field_name);
|
2020-02-11 23:20:01 +01:00
|
|
|
if(data) jQuery.extend(data.config, attrs.config);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_setup_radio( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
// 'Empty' label will be first
|
|
|
|
delete(attrs.label);
|
|
|
|
|
|
|
|
if(field.values && field.values[''])
|
|
|
|
{
|
|
|
|
attrs.label = field.values[''];
|
|
|
|
delete field.values[''];
|
|
|
|
}
|
|
|
|
|
|
|
|
field.type = 'radiogroup';
|
|
|
|
attrs.options = field.values;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_setup_checkbox( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
// Read-only checkbox is just text
|
2021-01-26 18:42:18 +01:00
|
|
|
if(attrs.readonly && this.getType() !== "customfields")
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
|
|
|
attrs.ro_true = field.label;
|
|
|
|
}
|
2021-01-26 18:42:18 +01:00
|
|
|
else if (field.hasOwnProperty('ro_true'))
|
|
|
|
{
|
|
|
|
attrs.ro_true = field.ro_true;
|
|
|
|
}
|
|
|
|
if (field.hasOwnProperty('ro_false'))
|
|
|
|
{
|
|
|
|
attrs.ro_false = field.ro_false;
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* People set button attributes as
|
|
|
|
* label: javascript
|
|
|
|
*/
|
|
|
|
_setup_button( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
|
|
|
attrs.label = field.label;
|
|
|
|
|
|
|
|
if (this.getType() == 'customfields-list')
|
|
|
|
{
|
|
|
|
// No buttons in a list, it causes problems with detached nodes
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Simple case, one widget for a custom field
|
|
|
|
if(!field.values || typeof field.values != 'object' || Object.keys(field.values).length == 1)
|
|
|
|
{
|
|
|
|
for(let key in field.values)
|
|
|
|
{
|
|
|
|
attrs.label = key;
|
|
|
|
attrs.onclick = field.values[key];
|
|
|
|
}
|
|
|
|
if (!attrs.label)
|
|
|
|
{
|
|
|
|
attrs.label = 'No "label=onclick" in values!';
|
|
|
|
attrs.onclick = function(){ return false; };
|
|
|
|
}
|
|
|
|
return !attrs.readonly;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Complicated case, a single custom field you get multiple widgets
|
|
|
|
// Handle it all here, since this is the exception
|
|
|
|
const row = jQuery('tr', this.tbody).last();
|
|
|
|
let cf = jQuery('td', row);
|
|
|
|
// Label in first column, widget in 2nd
|
|
|
|
cf.text(field.label + "");
|
|
|
|
cf = jQuery(document.createElement("td"))
|
|
|
|
.appendTo(row);
|
|
|
|
|
|
|
|
for(var key in field.values)
|
|
|
|
{
|
|
|
|
const button_attrs = jQuery.extend({}, attrs);
|
|
|
|
button_attrs.label = key;
|
|
|
|
button_attrs.onclick = field.values[key];
|
|
|
|
button_attrs.id = attrs.id + '_' + key;
|
|
|
|
|
|
|
|
// This controls where the button is placed in the DOM
|
|
|
|
this.rows[button_attrs.id] = cf[0];
|
|
|
|
|
|
|
|
// Do not store in the widgets list, one name for multiple widgets would cause problems
|
|
|
|
/*this.widgets[field_name] = */ et2_createWidget(attrs.type ? attrs.type : field.type, button_attrs, this);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_setup_link_entry( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
if(field.type === 'filemanager')
|
|
|
|
{
|
|
|
|
return this._setup_filemanager(field_name, field, attrs);
|
|
|
|
}
|
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
|
|
|
attrs.type = "link-entry";
|
2022-07-18 23:24:10 +02:00
|
|
|
attrs[attrs.readonly ? "app" : "only_app"] = typeof field.only_app == "undefined" ? field.type : field.only_app;
|
2024-02-08 21:26:07 +01:00
|
|
|
attrs.searchOptions = {filter: field.values || {}};
|
2020-02-11 23:20:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_setup_filemanager( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
attrs.type = 'vfs-upload';
|
|
|
|
delete(attrs.label);
|
|
|
|
|
2024-03-26 11:40:51 +01:00
|
|
|
// allow to set/pass further et2_file attributes to the vfs-upload
|
|
|
|
if (field.values && typeof field.values === 'object')
|
|
|
|
{
|
|
|
|
['mime', 'accept', 'max_file_size'].forEach((name) => {
|
|
|
|
if (typeof field.values[name] !== 'undefined')
|
|
|
|
{
|
|
|
|
attrs[name] = field.values[name];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
if (this.getType() == 'customfields-list')
|
|
|
|
{
|
|
|
|
// No special UI needed?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Complicated case, a single custom field you get multiple widgets
|
|
|
|
// Handle it all here, since this is the exception
|
|
|
|
const row = jQuery('tr', this.tbody).last();
|
|
|
|
let cf = jQuery('td', row);
|
|
|
|
|
|
|
|
// Label in first column, widget in 2nd
|
|
|
|
cf.text(field.label + "");
|
|
|
|
cf = jQuery(document.createElement("td"))
|
|
|
|
.appendTo(row);
|
|
|
|
|
|
|
|
// Create upload widget
|
2024-02-29 22:32:58 +01:00
|
|
|
let widget = this.widgets[field_name] = <et2_DOMWidget>et2_createWidget(attrs.type ? attrs.type : field.type, {...attrs}, this);
|
2020-02-11 23:20:01 +01:00
|
|
|
|
|
|
|
// This controls where the widget is placed in the DOM
|
|
|
|
this.rows[attrs.id] = cf[0];
|
|
|
|
jQuery(widget.getDOMNode(widget)).css('vertical-align','top');
|
|
|
|
|
2024-03-27 16:44:57 +01:00
|
|
|
// should we show the VfsSelect
|
|
|
|
if (!field.values || typeof field.values !== 'object' || !field.values.noVfsSelect)
|
|
|
|
{
|
|
|
|
// Add a link to existing VFS file
|
|
|
|
const required = attrs.needed ?? attrs.required;
|
|
|
|
delete attrs.needed;
|
|
|
|
const select_attrs = {
|
|
|
|
...attrs,
|
|
|
|
// Filemanager select
|
|
|
|
...{
|
|
|
|
path: '~',
|
|
|
|
mode: widget.options.multiple ? 'open-multiple' : 'open',
|
|
|
|
method: 'EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_existing',
|
|
|
|
methodId: attrs.path,
|
|
|
|
buttonLabel: this.egw().lang('Link')
|
|
|
|
},
|
|
|
|
type: 'et2-vfs-select',
|
|
|
|
required: required
|
|
|
|
}
|
|
|
|
select_attrs.id = attrs.id + '_vfs_select';
|
2020-02-11 23:20:01 +01:00
|
|
|
|
2024-03-27 16:44:57 +01:00
|
|
|
// This controls where the button is placed in the DOM
|
|
|
|
this.rows[select_attrs.id] = cf[0];
|
2020-02-11 23:20:01 +01:00
|
|
|
|
2024-03-27 16:44:57 +01:00
|
|
|
// Do not store in the widgets list, one name for multiple widgets would cause problems
|
|
|
|
widget = <Et2VfsSelectButton>loadWebComponent(select_attrs.type, select_attrs, this);
|
|
|
|
jQuery(widget.getDOMNode(widget)).css('vertical-align','top').prependTo(cf);
|
|
|
|
}
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-04 18:50:23 +02:00
|
|
|
/**
|
|
|
|
* Display links in list as CF name
|
|
|
|
* @param field_name
|
|
|
|
* @param field
|
|
|
|
* @param attrs
|
|
|
|
*/
|
|
|
|
_setup_url( field_name, field, attrs)
|
|
|
|
{
|
|
|
|
if(this.getType() == 'customfields-list')
|
|
|
|
{
|
|
|
|
attrs.label = field.label;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:20:01 +01:00
|
|
|
/**
|
|
|
|
* Set which fields are visible, by name
|
|
|
|
*
|
|
|
|
* Note: no # prefix on the name
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
set_visible( _fields)
|
|
|
|
{
|
|
|
|
for(let name in _fields)
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
if(this.rows[this.options.prefix + name])
|
2020-02-11 23:20:01 +01:00
|
|
|
{
|
|
|
|
if(_fields[name])
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
jQuery(this.rows[this.options.prefix+name]).show();
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-30 18:43:19 +02:00
|
|
|
jQuery(this.rows[this.options.prefix+name]).hide();
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.options.fields[name] = _fields[name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code for implementing et2_IDetachedDOM
|
|
|
|
*/
|
|
|
|
getDetachedAttributes(_attrs)
|
|
|
|
{
|
|
|
|
_attrs.push("value", "class");
|
|
|
|
}
|
|
|
|
|
|
|
|
getDetachedNodes()
|
|
|
|
{
|
|
|
|
return this.detachedNodes ? this.detachedNodes : [];
|
|
|
|
}
|
|
|
|
|
|
|
|
setDetachedAttributes(_nodes, _values)
|
|
|
|
{
|
|
|
|
// Individual widgets are detected and handled by the grid, but the interface is needed for this to happen
|
|
|
|
|
|
|
|
// Show the row if there's a value, hide it if there is no value
|
|
|
|
for(let i = 0; i < _nodes.length; i++)
|
|
|
|
{
|
|
|
|
// toggle() needs a boolean to do what we want
|
|
|
|
const key = _nodes[i].getAttribute('data-field');
|
2020-06-30 18:43:19 +02:00
|
|
|
jQuery(_nodes[i]).toggle(_values.fields[key] && _values.value[this.options.prefix + key]?true:false);
|
2020-02-11 23:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-02 13:52:53 +02:00
|
|
|
et2_register_widget(et2_customfields_list, ["customfields", "customfields-list"]);
|