2011-10-07 01:44:55 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS Custom fields object
|
2011-10-07 01:44:55 +02:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright Nathan Gray 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
lib/tooltip;
|
|
|
|
jquery.jquery;
|
|
|
|
et2_core_xml;
|
|
|
|
et2_core_DOMWidget;
|
|
|
|
et2_core_inputWidget;
|
|
|
|
*/
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* @augments et2_dataview
|
|
|
|
*/
|
2014-02-24 15:47:55 +01:00
|
|
|
var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput],
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2011-10-07 01:44:55 +02:00
|
|
|
attributes: {
|
|
|
|
'customfields': {
|
|
|
|
'name': 'Custom fields',
|
2013-04-09 09:22:35 +02:00
|
|
|
'description': 'Auto filled',
|
|
|
|
'type': 'any'
|
2011-10-07 01:44:55 +02:00
|
|
|
},
|
|
|
|
'fields': {
|
|
|
|
'name': 'Custom fields',
|
2013-04-09 09:22:35 +02:00
|
|
|
'description': 'Auto filled',
|
|
|
|
'type': 'any'
|
2011-10-07 01:44:55 +02:00
|
|
|
},
|
|
|
|
'value': {
|
|
|
|
'name': 'Custom fields',
|
2012-07-24 01:54:16 +02:00
|
|
|
'description': 'Auto filled',
|
|
|
|
'type': "any"
|
2011-10-07 01:44:55 +02:00
|
|
|
},
|
2012-03-22 00:23:07 +01:00
|
|
|
'type_filter': {
|
|
|
|
'name': 'Field filter',
|
|
|
|
"default": "",
|
2012-07-24 01:54:16 +02:00
|
|
|
"type": "any", // String or array
|
2012-03-22 00:23:07 +01:00
|
|
|
"description": "Filter displayed custom fields by their 'type2' attribute"
|
2013-11-27 18:17:37 +01:00
|
|
|
},
|
|
|
|
'private': {
|
|
|
|
ignore: true,
|
|
|
|
type: 'boolean'
|
2012-03-22 00:23:07 +01:00
|
|
|
}
|
2011-10-07 01:44:55 +02:00
|
|
|
},
|
|
|
|
|
2015-04-01 14:29:20 +02:00
|
|
|
legacyOptions: ["type_filter","private", "fields"], // Field restriction & private done server-side
|
2012-03-22 00:23:07 +01:00
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
prefix: '#',
|
|
|
|
|
2012-07-24 18:37:24 +02:00
|
|
|
DEFAULT_ID: "custom_fields",
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-02-24 15:47:55 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_customfields_list
|
|
|
|
*/
|
2011-10-07 01:44:55 +02:00
|
|
|
init: function() {
|
2011-10-11 20:18:58 +02:00
|
|
|
// Some apps (infolog edit) don't give ID, so assign one to get settings
|
2012-07-24 18:37:24 +02:00
|
|
|
if(!arguments[1].id) arguments[1].id = this.DEFAULT_ID;
|
2011-10-11 20:18:58 +02:00
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2013-11-01 22:12:20 +01:00
|
|
|
// Allows server side to override prefix - not an attribute though
|
|
|
|
if(typeof this.options.prefix != 'undefined') this.prefix = this.options.prefix;
|
2014-02-24 15:47:55 +01:00
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
// Create the table body and the table
|
2013-03-20 17:41:46 +01:00
|
|
|
this.tbody = $j(document.createElement("tbody"));
|
|
|
|
this.table = $j(document.createElement("table"))
|
2014-01-18 12:59:05 +01:00
|
|
|
.addClass("et2_grid et2_customfield_list");
|
2013-03-20 17:41:46 +01:00
|
|
|
this.table.append(this.tbody);
|
2011-10-07 01:44:55 +02:00
|
|
|
|
|
|
|
this.rows = {};
|
|
|
|
this.widgets = {};
|
|
|
|
this.detachedNodes = [];
|
2012-07-24 18:37:24 +02:00
|
|
|
if(!this.options.fields) this.options.fields = {};
|
2011-10-07 01:44:55 +02:00
|
|
|
|
2012-03-22 00:23:07 +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)
|
|
|
|
{
|
2012-07-24 18:37:24 +02:00
|
|
|
var already_filtered = !jQuery.isEmptyObject(this.options.fields);
|
2012-03-22 00:23:07 +01:00
|
|
|
for(var field_name in this.options.customfields)
|
|
|
|
{
|
2012-07-24 18:37:24 +02:00
|
|
|
// Already excluded?
|
|
|
|
if(already_filtered && !this.options.fields[field_name]) continue;
|
|
|
|
|
2013-06-10 22:15:11 +02:00
|
|
|
if(!this.options.customfields[field_name].type2 || this.options.customfields[field_name].type2.length == 0 ||
|
|
|
|
this.options.customfields[field_name].type2 == '0')
|
2012-03-22 00:23:07 +01:00
|
|
|
{
|
|
|
|
// No restrictions
|
|
|
|
this.options.fields[field_name] = true;
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-25 00:57:27 +02:00
|
|
|
var types = typeof this.options.customfields[field_name].type2 == 'string' ? this.options.customfields[field_name].type2.split(",") : this.options.customfields[field_name].type2;
|
2012-03-22 00:23:07 +01:00
|
|
|
this.options.fields[field_name] = false;
|
2012-07-11 22:30:33 +02:00
|
|
|
for(var i = 0; i < types.length; i++)
|
2012-03-22 00:23:07 +01:00
|
|
|
{
|
2012-07-11 22:30:33 +02:00
|
|
|
if(jQuery.inArray(types[i],this.options.type_filter) > -1)
|
2012-03-22 00:23:07 +01:00
|
|
|
{
|
|
|
|
this.options.fields[field_name] = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:01:55 +01:00
|
|
|
this.setDOMNode(this.table[0]);
|
2011-10-07 01:44:55 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2013-03-20 21:47:54 +01:00
|
|
|
this.rows = {};
|
|
|
|
this.widgets = {};
|
|
|
|
this.detachedNodes = [];
|
2011-10-11 20:18:58 +02:00
|
|
|
this.tbody = null;
|
2011-10-07 01:44:55 +02:00
|
|
|
},
|
|
|
|
|
2012-03-13 19:01:55 +01:00
|
|
|
/**
|
|
|
|
* 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: function(_obj) {
|
|
|
|
this.loadFields();
|
|
|
|
},
|
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
getDOMNode: function(_sender) {
|
|
|
|
|
|
|
|
// Check whether the _sender object exists inside the management array
|
|
|
|
if(this.rows && _sender.id && this.rows[_sender.id])
|
|
|
|
{
|
|
|
|
return this.rows[_sender.id];
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:01:55 +01:00
|
|
|
return this._super.apply(this, arguments);
|
2011-10-07 01:44:55 +02:00
|
|
|
},
|
|
|
|
|
2011-10-11 20:18:58 +02:00
|
|
|
/**
|
|
|
|
* Initialize widgets for custom fields
|
|
|
|
*/
|
2011-10-07 01:44:55 +02:00
|
|
|
loadFields: function() {
|
|
|
|
if(!this.options || !this.options.customfields) return;
|
2011-10-11 20:18:58 +02:00
|
|
|
|
|
|
|
// Already set up - avoid duplicates in nextmatch
|
|
|
|
if(this._type == 'customfields-list' && !this.isInTree()) return;
|
2011-10-18 18:32:35 +02:00
|
|
|
if(!jQuery.isEmptyObject(this.widgets)) return;
|
2011-10-07 01:44:55 +02:00
|
|
|
|
2011-10-17 18:34:58 +02:00
|
|
|
// Check for global setting changes (visibility)
|
|
|
|
var global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~');
|
2013-11-01 22:12:20 +01:00
|
|
|
if(global_data && global_data.fields && !this.options.fields) this.options.fields = global_data.fields;
|
2011-10-17 18:34:58 +02:00
|
|
|
|
2011-10-18 22:09:48 +02:00
|
|
|
// For checking app entries
|
2012-03-02 11:44:56 +01:00
|
|
|
var apps = this.egw().link_app_list();
|
2011-10-18 22:09:48 +02:00
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
// Create the table rows
|
|
|
|
for(var field_name in this.options.customfields)
|
|
|
|
{
|
2012-03-22 00:23:07 +01:00
|
|
|
// Skip fields if we're filtering
|
2014-07-08 05:37:47 +02:00
|
|
|
if(this._type != 'customfields-list' && !jQuery.isEmptyObject(this.options.fields) && !this.options.fields[field_name]) continue;
|
2012-03-22 00:23:07 +01:00
|
|
|
|
2011-10-17 18:34:58 +02:00
|
|
|
var field = this.options.customfields[field_name];
|
2012-03-23 00:35:25 +01:00
|
|
|
|
2012-06-12 22:58:25 +02:00
|
|
|
var id = this.prefix+field_name;
|
|
|
|
|
2012-03-23 00:35:25 +01:00
|
|
|
// Need curlies around ID for nm row expansion
|
|
|
|
if(this.id == '$row')
|
|
|
|
{
|
|
|
|
id = "{" + this.id + "}" + "["+this.prefix + field_name+"]";
|
|
|
|
}
|
2012-07-24 18:37:24 +02:00
|
|
|
else if (this.id != this.DEFAULT_ID)
|
|
|
|
{
|
|
|
|
// Prefix this ID to avoid potential ID collisions
|
|
|
|
id = this.id + "["+id+"]";
|
|
|
|
}
|
2011-10-17 18:34:58 +02:00
|
|
|
|
2011-10-11 20:18:58 +02:00
|
|
|
// Avoid creating field twice
|
2011-10-18 18:32:35 +02:00
|
|
|
if(!this.rows[id])
|
|
|
|
{
|
|
|
|
|
|
|
|
var row = jQuery(document.createElement("tr"))
|
2015-04-01 14:29:20 +02:00
|
|
|
.appendTo(this.tbody)
|
|
|
|
.addClass(this.id+'_'+id);
|
2011-10-18 18:32:35 +02:00
|
|
|
var cf = jQuery(document.createElement("td"))
|
2011-10-07 01:44:55 +02:00
|
|
|
.appendTo(row);
|
2013-07-04 01:06:59 +02:00
|
|
|
if(!field.type) field.type = 'text";'
|
2011-10-18 22:09:48 +02:00
|
|
|
var setup_function = '_setup_'+(apps[field.type] ? 'link_entry' : field.type.replace("-","_"));
|
2014-02-24 15:47:55 +01:00
|
|
|
|
2011-10-18 18:32:35 +02:00
|
|
|
var attrs = {
|
|
|
|
'id': id,
|
|
|
|
'statustext': field.help,
|
2013-06-26 22:50:10 +02:00
|
|
|
'needed': field.needed,
|
2015-07-27 18:53:19 +02:00
|
|
|
'readonly': this.getArrayMgr("readonlys").isReadOnly(id, null, this.options.readonly),
|
2012-03-22 00:23:07 +01:00
|
|
|
'value': this.options.value[this.prefix+field_name]
|
2011-10-18 18:32:35 +02:00
|
|
|
};
|
2014-01-11 17:40:45 +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;
|
2014-02-24 15:47:55 +01:00
|
|
|
|
2011-10-18 18:32:35 +02:00
|
|
|
if(this[setup_function]) {
|
2012-03-22 00:23:07 +01:00
|
|
|
var no_skip = this[setup_function].call(this, field_name, field, attrs);
|
|
|
|
if(!no_skip) continue;
|
2011-10-18 18:32:35 +02:00
|
|
|
}
|
2014-02-24 15:47:55 +01:00
|
|
|
|
2011-10-18 18:32:35 +02:00
|
|
|
if(this._type == 'customfields-list') {
|
|
|
|
// No label, cust widget
|
|
|
|
attrs.readonly = true;
|
2014-03-24 19:00:09 +01:00
|
|
|
// 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);
|
2014-06-11 20:03:19 +02:00
|
|
|
row.attr('data-field', field_name);
|
2014-03-24 19:00:09 +01:00
|
|
|
row.attr('data-help', field.help);
|
2014-06-10 22:22:43 +02:00
|
|
|
this.detachedNodes.push(row[0]);
|
2014-07-08 22:13:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-18 18:32:35 +02:00
|
|
|
// Label in first column, widget in 2nd
|
|
|
|
cf.text(field.label + "");
|
|
|
|
cf = jQuery(document.createElement("td"))
|
|
|
|
.appendTo(row);
|
|
|
|
}
|
|
|
|
this.rows[id] = cf[0];
|
|
|
|
|
2015-05-11 20:22:43 +02:00
|
|
|
// Set any additional attributes set in options, but not for widgets that pass actual options
|
|
|
|
if(['select','radio','radiogroup','checkbox','button'].indexOf(field.type) == -1 && !jQuery.isEmptyObject(field.values))
|
|
|
|
{
|
|
|
|
var w = et2_registry[attrs.type ? attrs.type : field.type];
|
|
|
|
for(var attr_name in field.values)
|
|
|
|
{
|
|
|
|
if (typeof w.prototype.attributes[attr_name] != "undefined")
|
|
|
|
attrs[attr_name] = field.values[attr_name];
|
|
|
|
}
|
|
|
|
}
|
2011-10-18 18:32:35 +02:00
|
|
|
// Create widget
|
2011-10-18 22:09:48 +02:00
|
|
|
var widget = this.widgets[field_name] = et2_createWidget(attrs.type ? attrs.type : field.type, attrs, this);
|
2011-10-07 01:44:55 +02:00
|
|
|
}
|
2011-10-12 22:56:11 +02:00
|
|
|
|
2011-10-18 18:32:35 +02: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();
|
2014-07-08 22:13:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-18 18:32:35 +02:00
|
|
|
jQuery(this.rows[field_name]).hide();
|
|
|
|
}
|
2011-10-11 20:18:58 +02:00
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
}
|
|
|
|
},
|
2011-10-11 20:18:58 +02:00
|
|
|
|
2012-03-13 19:01:55 +01:00
|
|
|
/**
|
|
|
|
* Read needed info on available custom fields from various places it's stored.
|
|
|
|
*/
|
2011-10-07 01:44:55 +02:00
|
|
|
transformAttributes: function(_attrs) {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2011-10-11 20:18:58 +02:00
|
|
|
// Add in settings that are objects
|
2013-03-20 17:41:46 +01:00
|
|
|
|
|
|
|
// Customized settings for this widget (unlikely)
|
|
|
|
var data = this.getArrayMgr("modifications").getEntry(this.id);
|
|
|
|
// Check for global settings
|
|
|
|
var global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~', true);
|
|
|
|
if(global_data)
|
2011-10-11 20:18:58 +02:00
|
|
|
{
|
2013-03-20 17:41:46 +01:00
|
|
|
for(var key in data)
|
2012-06-06 06:13:19 +02:00
|
|
|
{
|
2013-03-20 17:41:46 +01:00
|
|
|
// Don't overwrite fields with global values
|
|
|
|
if(global_data[key] && key !== 'fields')
|
2012-06-06 06:13:19 +02:00
|
|
|
{
|
2013-03-20 17:41:46 +01:00
|
|
|
data[key] = jQuery.extend(true, {}, data[key], global_data[key]);
|
2012-06-06 06:13:19 +02:00
|
|
|
}
|
|
|
|
}
|
2013-03-20 17:41:46 +01:00
|
|
|
}
|
|
|
|
for(var key in data)
|
|
|
|
{
|
|
|
|
_attrs[key] = data[key];
|
|
|
|
}
|
|
|
|
for(var key in global_data)
|
|
|
|
{
|
|
|
|
if(typeof global_data[key] != 'undefined' && ! _attrs[key]) _attrs[key] = global_data[key];
|
2011-10-11 20:18:58 +02:00
|
|
|
}
|
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
if (this.id)
|
|
|
|
{
|
|
|
|
// Set the value for this element
|
|
|
|
var contentMgr = this.getArrayMgr("content");
|
|
|
|
if (contentMgr != null) {
|
2015-07-27 18:53:19 +02:00
|
|
|
var val = contentMgr.getEntry(this.id);
|
2011-10-11 20:18:58 +02:00
|
|
|
_attrs["value"] = {};
|
2011-10-07 01:44:55 +02:00
|
|
|
if (val !== null)
|
|
|
|
{
|
2015-04-24 16:37:55 +02:00
|
|
|
if(this.id.indexOf(this.prefix) === 0 && typeof data.fields != 'undefined' && data.fields[this.id.replace(this.prefix,'')] === true)
|
2011-10-07 01:44:55 +02:00
|
|
|
{
|
2015-04-01 14:29:20 +02:00
|
|
|
_attrs['value'][this.id] = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Only set the values that match desired custom fields
|
|
|
|
for(var key in val)
|
|
|
|
{
|
|
|
|
if(key.indexOf(this.prefix) == 0) {
|
|
|
|
_attrs["value"][key] = val[key];
|
|
|
|
}
|
2011-10-07 01:44:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//_attrs["value"] = val;
|
|
|
|
}
|
2011-10-11 20:18:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check for custom fields directly in record
|
|
|
|
for(var key in _attrs.customfields)
|
|
|
|
{
|
|
|
|
_attrs["value"][this.prefix + key] = contentMgr.getEntry(this.prefix + key);
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 01:44:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-02-24 15:47:55 +01:00
|
|
|
|
2012-03-13 19:01:55 +01:00
|
|
|
loadFromXML: function(_node) {
|
|
|
|
this.loadFields();
|
|
|
|
|
|
|
|
// Load the nodes as usual
|
2014-06-10 22:22:43 +02:00
|
|
|
this._super.apply(this, arguments);
|
2012-03-13 19:01:55 +01:00
|
|
|
},
|
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
set_value: function(_value) {
|
|
|
|
if(!this.options.customfields) return;
|
|
|
|
for(var field_name in this.options.customfields)
|
|
|
|
{
|
2013-03-20 21:47:54 +01:00
|
|
|
// Skip fields if we're filtering
|
|
|
|
if(!jQuery.isEmptyObject(this.options.fields) && !this.options.fields[field_name]) continue;
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
// Make sure widget is created, and has the needed function
|
2011-10-07 01:44:55 +02:00
|
|
|
if(!this.widgets[field_name] || !this.widgets[field_name].set_value) continue;
|
2011-10-07 18:59:50 +02:00
|
|
|
var value = _value[this.prefix + field_name] ? _value[this.prefix + field_name] : null;
|
2012-03-22 17:34:45 +01:00
|
|
|
|
2012-06-12 22:58:25 +02:00
|
|
|
// Check if ID was missing
|
2012-07-24 18:37:24 +02:00
|
|
|
if(value == null && this.id == this.DEFAULT_ID && this.getArrayMgr("content").getEntry(this.prefix + field_name))
|
2012-06-12 22:58:25 +02:00
|
|
|
{
|
|
|
|
value = this.getArrayMgr("content").getEntry(this.prefix + field_name);
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:34:45 +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))
|
|
|
|
{
|
|
|
|
value = jQuery.datepicker.parseDate("yy-mm-dd",value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-10-11 20:18:58 +02:00
|
|
|
this.widgets[field_name].set_value(value);
|
2011-10-07 01:44:55 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-12 22:58:25 +02:00
|
|
|
/**
|
2014-02-24 15:47:55 +01:00
|
|
|
* et2_IInput so the custom field can be it's own widget.
|
2012-06-12 22:58:25 +02:00
|
|
|
*/
|
|
|
|
getValue: function() {
|
|
|
|
// Not using an ID means we have to grab all the widget values, and put them where server knows to look
|
2012-07-24 18:37:24 +02:00
|
|
|
if(this.id != this.DEFAULT_ID)
|
2012-06-12 22:58:25 +02:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var value = {};
|
2012-06-13 17:18:34 +02:00
|
|
|
for(var field_name in this.widgets)
|
2012-06-12 22:58:25 +02:00
|
|
|
{
|
2014-05-15 18:49:53 +02:00
|
|
|
if(this.widgets[field_name].getValue && !this.widgets[field_name].options.readonly)
|
2012-06-12 22:58:25 +02:00
|
|
|
{
|
|
|
|
value[this.prefix + field_name] = this.widgets[field_name].getValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
|
|
|
isDirty: function() {
|
|
|
|
var dirty = true;
|
2012-06-13 17:18:34 +02:00
|
|
|
for(var field_name in this.widgets)
|
2012-06-12 22:58:25 +02:00
|
|
|
{
|
|
|
|
if(this.widgets[field_name].isDirty)
|
|
|
|
{
|
|
|
|
dirty = dirty && this.widgets[field_name].isDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dirty;
|
|
|
|
},
|
|
|
|
|
|
|
|
resetDirty: function() {
|
2012-06-13 17:18:34 +02:00
|
|
|
for(var field_name in this.widgets)
|
2012-06-12 22:58:25 +02:00
|
|
|
{
|
|
|
|
if(this.widgets[field_name].resetDirty)
|
|
|
|
{
|
|
|
|
this.widgets[field_name].resetDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-02-24 15:47:55 +01:00
|
|
|
|
2013-06-26 22:50:10 +02:00
|
|
|
isValid: function() {
|
|
|
|
// Individual customfields will handle themselves
|
|
|
|
return true;
|
|
|
|
},
|
2012-06-12 22:58:25 +02:00
|
|
|
|
2011-10-07 18:59:50 +02:00
|
|
|
/**
|
|
|
|
* Adapt provided attributes to match options for widget
|
2014-12-10 15:35:08 +01:00
|
|
|
*
|
|
|
|
* rows > 1 --> textarea, with rows=rows and cols=len
|
|
|
|
* !rows --> input, with size=len
|
|
|
|
* rows = 1 --> input, with size=len, maxlength=len
|
2011-10-07 18:59:50 +02:00
|
|
|
*/
|
|
|
|
_setup_text: function(field_name, field, attrs) {
|
2012-03-22 00:23:07 +01:00
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
2011-10-07 18:59:50 +02:00
|
|
|
field.type = 'textbox';
|
2014-12-10 15:35:08 +01:00
|
|
|
attrs.rows = field.rows > 1 ? field.rows : null;
|
2013-06-18 19:03:06 +02:00
|
|
|
|
|
|
|
if(field.len)
|
|
|
|
{
|
2014-12-10 15:35:08 +01:00
|
|
|
attrs.size = field.len;
|
|
|
|
if (field.rows == 1) attrs.maxlength = field.len;
|
2013-06-18 19:03:06 +02:00
|
|
|
}
|
2012-03-22 00:23:07 +01:00
|
|
|
return true;
|
2011-10-07 18:59:50 +02:00
|
|
|
},
|
2015-04-21 18:47:33 +02:00
|
|
|
_setup_ajax_select: function(field_name, field, attrs) {
|
|
|
|
var attributes = ['get_rows','get_title','id_field','template'];
|
2015-09-22 18:05:27 +02:00
|
|
|
if(field.values)
|
2015-04-21 18:47:33 +02:00
|
|
|
{
|
2015-09-22 18:05:27 +02:00
|
|
|
for(var i = 0; i < attributes.length; i++)
|
2015-04-21 18:47:33 +02:00
|
|
|
{
|
2015-09-22 18:05:27 +02:00
|
|
|
if(typeof field.values[attributes[i]] !== 'undefined')
|
|
|
|
{
|
|
|
|
attrs[attributes[i]] = field.values[attributes[i]];
|
|
|
|
}
|
2015-04-21 18:47:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2014-10-08 12:45:55 +02:00
|
|
|
_setup_float: function(field_name, field, attrs) {
|
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
|
|
|
field.type = 'float';
|
|
|
|
|
|
|
|
if(field.len)
|
|
|
|
{
|
2014-12-10 15:35:08 +01:00
|
|
|
attrs.size = field.len;
|
2014-10-08 12:45:55 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2011-10-07 18:59:50 +02:00
|
|
|
_setup_select: function(field_name, field, attrs) {
|
2012-03-22 00:23:07 +01:00
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
2013-06-18 19:16:08 +02:00
|
|
|
attrs.rows = field.rows;
|
2014-02-24 15:47:55 +01:00
|
|
|
// select_options are now send from server-side incl. ones defined via a file in EGroupware root
|
2013-11-01 22:12:20 +01:00
|
|
|
attrs.tags = field.tags;
|
2014-02-24 15:47:55 +01:00
|
|
|
|
2012-03-22 00:23:07 +01:00
|
|
|
return true;
|
|
|
|
},
|
2014-05-08 19:45:09 +02:00
|
|
|
_setup_date: function(field_name, field, attrs) {
|
2014-12-10 15:35:08 +01:00
|
|
|
attrs.data_format = 'Y-m-d';
|
2014-05-08 19:45:09 +02:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
_setup_date_time: function(field_name, field, attrs) {
|
2014-12-10 15:35:08 +01:00
|
|
|
attrs.data_format = 'Y-m-d H:i:s';
|
2014-05-08 19:45:09 +02:00
|
|
|
return true;
|
|
|
|
},
|
2012-06-06 06:13:19 +02:00
|
|
|
_setup_htmlarea: function(field_name, field, attrs) {
|
|
|
|
attrs.config = field.config ? field.config : {};
|
|
|
|
attrs.config.toolbarStartupExpanded = false;
|
2014-02-24 15:47:55 +01:00
|
|
|
if(field.len)
|
2012-06-06 06:13:19 +02:00
|
|
|
{
|
2014-12-10 15:35:08 +01:00
|
|
|
attrs.config.width = field.len+'px';
|
2012-06-06 06:13:19 +02:00
|
|
|
}
|
2014-07-02 11:34:51 +02:00
|
|
|
attrs.config.height = (((field.rows > 0 && field.rows !='undefined') ? field.rows : 5) *16) +'px';
|
2013-06-19 01:23:42 +02:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
if(data) jQuery.extend(data.config, attrs.config);
|
|
|
|
|
2012-06-06 06:13:19 +02:00
|
|
|
return true;
|
|
|
|
},
|
2012-03-23 19:57:13 +01:00
|
|
|
_setup_radio: function(field_name, field, attrs) {
|
2014-02-24 15:47:55 +01:00
|
|
|
// 'Empty' label will be first
|
2012-03-23 19:57:13 +01:00
|
|
|
delete(attrs.label);
|
|
|
|
|
2013-06-18 22:55:13 +02:00
|
|
|
if(field.values && field.values[''])
|
|
|
|
{
|
|
|
|
attrs.label = field.values[''];
|
|
|
|
delete field.values[''];
|
|
|
|
}
|
|
|
|
|
2012-03-23 19:57:13 +01:00
|
|
|
field.type = 'radiogroup';
|
|
|
|
attrs.options = field.values;
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2012-03-23 00:35:25 +01:00
|
|
|
_setup_checkbox: function(field_name, field, attrs) {
|
|
|
|
// Read-only checkbox is just text
|
|
|
|
if(attrs.readonly)
|
|
|
|
{
|
|
|
|
attrs.ro_true = field.label;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2012-03-22 00:23:07 +01:00
|
|
|
/**
|
|
|
|
* People set button attributes as
|
|
|
|
* label: javascript
|
|
|
|
*/
|
|
|
|
_setup_button: function(field_name, field, attrs) {
|
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
|
|
|
attrs.label = field.label;
|
2014-10-08 12:45:55 +02:00
|
|
|
|
2014-11-14 13:38:40 +01:00
|
|
|
if (this._type == 'customfields-list')
|
|
|
|
{
|
|
|
|
// No buttons in a list, it causes problems with detached nodes
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-08 22:13:51 +02:00
|
|
|
// Simple case, one widget for a custom field
|
2014-11-14 13:38:40 +01:00
|
|
|
if(!field.values || typeof field.values != 'object' || Object.keys(field.values).length == 1)
|
2012-03-22 00:23:07 +01:00
|
|
|
{
|
2014-07-08 22:13:51 +02:00
|
|
|
for(var key in field.values)
|
|
|
|
{
|
|
|
|
attrs.label = key;
|
|
|
|
attrs.onclick = field.values[key];
|
|
|
|
}
|
2014-11-14 13:38:40 +01:00
|
|
|
if (!attrs.label)
|
|
|
|
{
|
|
|
|
attrs.label = 'No "label=onclick" in values!';
|
|
|
|
attrs.onclick = function(){ return false; };
|
|
|
|
}
|
2014-07-08 22:13:51 +02:00
|
|
|
return !attrs.readonly;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Complicated case, a single custom field you get multiple widgets
|
|
|
|
// Handle it all here, since this is the exception
|
|
|
|
var row = $j('tr',this.tbody).last();
|
|
|
|
var cf = $j('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)
|
|
|
|
{
|
|
|
|
var 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;
|
2012-03-22 00:23:07 +01:00
|
|
|
}
|
2011-10-07 18:59:50 +02:00
|
|
|
},
|
2011-10-18 22:09:48 +02:00
|
|
|
_setup_link_entry: function(field_name, field, attrs) {
|
2012-03-22 00:23:07 +01:00
|
|
|
// No label on the widget itself
|
|
|
|
delete(attrs.label);
|
|
|
|
|
2011-10-18 22:09:48 +02:00
|
|
|
attrs.type = "link-entry";
|
2013-06-05 19:10:57 +02:00
|
|
|
attrs.only_app = field.type;
|
2012-03-22 00:23:07 +01:00
|
|
|
return true;
|
2011-10-18 22:09:48 +02:00
|
|
|
},
|
2011-10-07 18:59:50 +02:00
|
|
|
|
2014-02-24 15:47:55 +01:00
|
|
|
/**
|
2012-03-19 20:23:23 +01:00
|
|
|
* Set which fields are visible, by name
|
|
|
|
*
|
|
|
|
* Note: no # prefix on the name
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
set_visible: function(_fields) {
|
|
|
|
for(var name in _fields)
|
|
|
|
{
|
|
|
|
if(this.rows[this.prefix + name])
|
|
|
|
{
|
|
|
|
if(_fields[name])
|
|
|
|
{
|
2012-03-19 20:57:02 +01:00
|
|
|
jQuery(this.rows[this.prefix+name]).show();
|
2012-03-19 20:23:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-19 20:57:02 +01:00
|
|
|
jQuery(this.rows[this.prefix+name]).hide();
|
2012-03-19 20:23:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.options.fields[name] = _fields[name];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-07 01:44:55 +02:00
|
|
|
/**
|
2012-03-06 17:29:18 +01:00
|
|
|
* Code for implementing et2_IDetachedDOM
|
|
|
|
*/
|
2011-10-07 01:44:55 +02:00
|
|
|
getDetachedAttributes: function(_attrs)
|
|
|
|
{
|
|
|
|
_attrs.push("value", "class");
|
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedNodes: function()
|
|
|
|
{
|
|
|
|
return this.detachedNodes ? this.detachedNodes : [];
|
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function(_nodes, _values)
|
|
|
|
{
|
2011-10-18 18:32:35 +02:00
|
|
|
// Individual widgets are detected and handled by the grid, but the interface is needed for this to happen
|
2014-06-10 22:22:43 +02:00
|
|
|
|
|
|
|
// Show the row if there's a value, hide it if there is no value
|
2014-06-11 20:03:19 +02:00
|
|
|
for(var i = 0; i < _nodes.length; i++)
|
2014-06-10 22:22:43 +02:00
|
|
|
{
|
|
|
|
// toggle() needs a boolean to do what we want
|
2014-07-11 17:52:43 +02:00
|
|
|
var key = _nodes[i].getAttribute('data-field');
|
2014-06-11 20:03:19 +02:00
|
|
|
$j(_nodes[i]).toggle(_values.fields[key] && _values.value[this.prefix + key]?true:false);
|
2014-06-10 22:22:43 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 01:44:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_customfields_list, ["customfields", "customfields-list"]);
|
|
|
|
|