2011-08-16 19:02:09 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS Selectbox object
|
2011-08-16 19:02:09 +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
|
2011-08-21 10:48:53 +02:00
|
|
|
* @author Andreas Stöckel
|
2011-08-16 19:02:09 +02:00
|
|
|
* @copyright Nathan Gray 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
2013-03-15 18:47:28 +01:00
|
|
|
/phpgwapi/js/jquery/chosen/chosen.jquery.js;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_xml;
|
|
|
|
et2_core_DOMWidget;
|
2011-08-24 12:44:51 +02:00
|
|
|
et2_core_inputWidget;
|
2011-08-16 19:02:09 +02:00
|
|
|
*/
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* @augments et2_inputWidget
|
|
|
|
*/
|
|
|
|
var et2_selectbox = et2_inputWidget.extend(
|
|
|
|
{
|
2011-08-16 19:02:09 +02:00
|
|
|
attributes: {
|
2011-08-22 10:58:20 +02:00
|
|
|
"multiple": {
|
|
|
|
"name": "multiple",
|
2011-08-16 19:02:09 +02:00
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "Allow selecting multiple options"
|
|
|
|
},
|
2014-02-24 19:13:54 +01:00
|
|
|
"expand_multiple_rows": {
|
|
|
|
"name": "Expand multiple",
|
|
|
|
"type": "integer",
|
|
|
|
"default": et2_no_init,
|
|
|
|
"description": "Shows single select widget, with a button. If the "+
|
|
|
|
"user clicks the button, the input will toggle to a multiselect,"+
|
|
|
|
"with this many rows. "
|
|
|
|
},
|
2011-08-16 19:02:09 +02:00
|
|
|
"rows": {
|
|
|
|
"name": "Rows",
|
|
|
|
"type": "any", // Old options put either rows or empty_label in first space
|
|
|
|
"default": 1,
|
|
|
|
"description": "Number of rows to display"
|
|
|
|
},
|
|
|
|
"empty_label": {
|
|
|
|
"name": "Empty label",
|
|
|
|
"type": "string",
|
|
|
|
"default": "",
|
2014-05-07 14:23:02 +02:00
|
|
|
"description": "Textual label for first row, eg: 'All' or 'None'. ID will be ''",
|
|
|
|
translate:true
|
2011-08-21 10:48:53 +02:00
|
|
|
},
|
|
|
|
"select_options": {
|
2011-08-21 15:24:20 +02:00
|
|
|
"type": "any",
|
|
|
|
"name": "Select options",
|
|
|
|
"default": {},
|
|
|
|
"description": "Internaly used to hold the select options."
|
2012-03-15 23:57:55 +01:00
|
|
|
},
|
|
|
|
"selected_first": {
|
|
|
|
"name": "Selected options first",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true,
|
|
|
|
"description": "For multi-selects, put the selected options at the top of the list when first loaded"
|
2012-04-09 23:49:28 +02:00
|
|
|
},
|
2013-03-15 18:47:28 +01:00
|
|
|
|
|
|
|
// Chosen options
|
|
|
|
"search": {
|
|
|
|
"name": "Search",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "For single selects, add a search box to the drop-down list"
|
|
|
|
},
|
|
|
|
"tags": {
|
|
|
|
"name": "Tag style",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "For multi-selects, displays selected as a list of tags instead of a big list"
|
|
|
|
},
|
|
|
|
|
|
|
|
// Value can be string or integer
|
2012-04-09 23:49:28 +02:00
|
|
|
"value": {
|
2013-03-15 18:47:28 +01:00
|
|
|
"type": "any"
|
2013-02-07 15:36:19 +01:00
|
|
|
},
|
|
|
|
// Type specific legacy options. Avoid using.
|
|
|
|
"other": {
|
2013-11-03 14:33:32 +01:00
|
|
|
"ignore": true,
|
2013-02-07 15:36:19 +01:00
|
|
|
"type": "any"
|
2011-08-16 19:02:09 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-07 15:36:19 +01:00
|
|
|
legacyOptions: ["rows","other"], // Other is sub-type specific
|
2011-08-16 19:02:09 +02:00
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Construtor
|
2013-11-03 14:33:32 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_selectbox
|
|
|
|
*/
|
2011-08-24 12:05:52 +02:00
|
|
|
init: function() {
|
2011-08-16 19:02:09 +02:00
|
|
|
this._super.apply(this, arguments);
|
2012-03-15 23:57:55 +01:00
|
|
|
|
|
|
|
this.input = null;
|
2014-02-05 17:34:32 +01:00
|
|
|
// Start at '' to avoid infinite loops while setting value/select options
|
2014-02-04 09:27:26 +01:00
|
|
|
this.value = '';
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2011-08-31 18:58:44 +02:00
|
|
|
// Allow no other widgets inside this one
|
|
|
|
this.supportedWidgetClasses = [];
|
2011-08-21 10:59:12 +02:00
|
|
|
|
2013-11-03 14:33:32 +01:00
|
|
|
// Legacy options could have row count or empty label in first slot
|
2012-03-15 23:57:55 +01:00
|
|
|
if(typeof this.options.rows == "string")
|
|
|
|
{
|
2013-11-03 14:33:32 +01:00
|
|
|
if(isNaN(this.options.rows))
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
2015-03-20 20:25:51 +01:00
|
|
|
this.options.empty_label = this.egw().lang(this.options.rows);
|
2012-03-15 23:57:55 +01:00
|
|
|
this.options.rows = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.options.rows = parseInt(this.options.rows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-03 14:33:32 +01:00
|
|
|
if(this.options.rows > 1)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
|
|
|
this.options.multiple = true;
|
2013-03-15 18:47:28 +01:00
|
|
|
if(this.options.tags)
|
|
|
|
{
|
|
|
|
this.createInputWidget();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.createMultiSelect();
|
|
|
|
}
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.createInputWidget();
|
2011-08-24 12:05:52 +02:00
|
|
|
}
|
2011-08-16 19:02:09 +02:00
|
|
|
},
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
destroy: function() {
|
2013-07-17 15:08:48 +02:00
|
|
|
if(this.input != null)
|
|
|
|
{
|
|
|
|
this.input.unchosen();
|
|
|
|
}
|
2014-02-24 19:13:54 +01:00
|
|
|
if(this.expand_button)
|
|
|
|
{
|
|
|
|
this.expand_button.off();
|
2014-03-25 16:20:05 +01:00
|
|
|
this.expand_button.remove();
|
|
|
|
this.expand_button = null;
|
2014-02-24 19:13:54 +01:00
|
|
|
}
|
2011-08-21 15:24:20 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.input = null;
|
|
|
|
},
|
2011-08-23 11:45:45 +02:00
|
|
|
|
2011-08-21 17:22:00 +02:00
|
|
|
transformAttributes: function(_attrs) {
|
2011-08-23 11:45:45 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2011-10-19 23:03:22 +02:00
|
|
|
// If select_options are already known, skip the rest
|
2013-11-04 20:00:43 +01:00
|
|
|
if(this.options && this.options.select_options && !jQuery.isEmptyObject(this.options.select_options) ||
|
2014-03-17 21:24:34 +01:00
|
|
|
_attrs.select_options && !jQuery.isEmptyObject(_attrs.select_options) ||
|
|
|
|
// Allow children to skip select_options - check to make sure default got set to something (should be {})
|
|
|
|
typeof _attrs.select_options == 'undefined' || _attrs.select_options === null
|
2013-11-04 20:00:43 +01:00
|
|
|
)
|
2011-10-19 23:03:22 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-01 19:11:21 +02:00
|
|
|
var sel_options = et2_selectbox.find_select_options(this, _attrs['select_options'], _attrs);
|
2014-05-05 19:25:01 +02:00
|
|
|
if(!jQuery.isEmptyObject(sel_options))
|
2011-09-26 18:01:42 +02:00
|
|
|
{
|
2014-05-05 19:25:01 +02:00
|
|
|
_attrs['select_options'] = sel_options;
|
2011-08-21 10:48:53 +02:00
|
|
|
}
|
2011-08-16 19:02:09 +02:00
|
|
|
},
|
|
|
|
|
2013-11-07 14:20:49 +01:00
|
|
|
/**
|
|
|
|
* Switch instanciated widget to multi-selection and back, optionally enabeling tags too
|
|
|
|
*
|
|
|
|
* If you want to switch tags on too, you need to do so after switching to multiple!
|
|
|
|
*
|
|
|
|
* @param {boolean} _multiple
|
|
|
|
* @param {integer} _size default=3
|
|
|
|
*/
|
|
|
|
set_multiple: function(_multiple, _size)
|
|
|
|
{
|
|
|
|
this.options.multiple = _multiple;
|
|
|
|
|
|
|
|
if (this.input)
|
|
|
|
{
|
|
|
|
if (_multiple)
|
|
|
|
{
|
|
|
|
this.input.attr('size', _size || 3);
|
|
|
|
this.input.attr('multiple', true);
|
|
|
|
this.input.attr('name', this.id + '[]');
|
|
|
|
|
2013-11-19 00:56:25 +01:00
|
|
|
if (this.input[0].options.length && this.input[0].options[0].value === '')
|
2013-11-07 14:20:49 +01:00
|
|
|
{
|
|
|
|
this.input[0].options[0] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.input.attr('multiple', false);
|
|
|
|
this.input.removeAttr('size');
|
|
|
|
this.input.attr('name', this.id);
|
|
|
|
|
|
|
|
if (this.options.empty_label && this.input[0].options[0].value !== '')
|
|
|
|
{
|
|
|
|
this._appendOptionElement('', this.options.empty_label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
/**
|
|
|
|
* Add an option to regular drop-down select
|
2014-01-29 19:55:24 +01:00
|
|
|
*
|
|
|
|
* @param {string} _value value attribute of option
|
|
|
|
* @param {string} _label label of option
|
|
|
|
* @param {string} _title title attribute of option
|
|
|
|
* @param {node} dom_element parent of new option
|
2012-03-15 23:57:55 +01:00
|
|
|
*/
|
2013-04-29 20:36:48 +02:00
|
|
|
_appendOptionElement: function(_value, _label, _title, dom_element) {
|
2011-09-09 17:47:38 +02:00
|
|
|
if(_value == "" && (_label == null || _label == "")) {
|
2013-10-11 15:02:22 +02:00
|
|
|
return; // empty_label is added in set_select_options anyway, ignoring it here to not add it twice
|
2011-09-09 17:47:38 +02:00
|
|
|
}
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
if(this.input == null)
|
|
|
|
{
|
2013-04-29 20:36:48 +02:00
|
|
|
return this._appendMultiOption(_value, _label, _title, dom_element);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2011-08-31 18:58:44 +02:00
|
|
|
var option = $j(document.createElement("option"))
|
2011-08-21 10:48:53 +02:00
|
|
|
.attr("value", _value)
|
2011-10-12 22:56:11 +02:00
|
|
|
.text(_label+"");
|
2011-08-31 18:58:44 +02:00
|
|
|
|
|
|
|
if (typeof _title != "undefined" && _title)
|
|
|
|
{
|
|
|
|
option.attr("title", _title);
|
|
|
|
}
|
2013-11-28 19:12:08 +01:00
|
|
|
if(_label == this.options.empty_label || this.options.empty_label == "" && _value === "")
|
2012-03-19 20:22:21 +01:00
|
|
|
{
|
|
|
|
// Make sure empty / all option is first
|
|
|
|
option.prependTo(this.input);
|
|
|
|
}
|
2013-11-03 14:33:32 +01:00
|
|
|
else
|
2012-03-19 20:22:21 +01:00
|
|
|
{
|
2013-04-29 20:36:48 +02:00
|
|
|
option.appendTo(dom_element || this.input);
|
2012-03-19 20:22:21 +01:00
|
|
|
}
|
2011-08-16 22:32:13 +02:00
|
|
|
},
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
/**
|
2013-11-03 14:33:32 +01:00
|
|
|
* Append a value to multi-select
|
2014-01-29 19:55:24 +01:00
|
|
|
*
|
|
|
|
* @param {string} _value value attribute of option
|
|
|
|
* @param {string} _label label of option
|
|
|
|
* @param {string} _title title attribute of option
|
|
|
|
* @param {node} dom_element parent of new option
|
2012-03-15 23:57:55 +01:00
|
|
|
*/
|
2013-04-29 20:36:48 +02:00
|
|
|
_appendMultiOption: function(_value, _label, _title, dom_element) {
|
2012-03-15 23:57:55 +01:00
|
|
|
var option_data = null;
|
|
|
|
if(typeof _label == "object")
|
|
|
|
{
|
|
|
|
option_data = _label;
|
|
|
|
_label = option_data.label;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Already in header
|
|
|
|
if(_label == this.options.empty_label) return;
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2013-08-23 16:10:37 +02:00
|
|
|
var opt_id = this.dom_id + "_opt_" + _value;
|
2012-03-15 23:57:55 +01:00
|
|
|
var label = jQuery(document.createElement("label"))
|
|
|
|
.attr("for", opt_id)
|
|
|
|
.hover(
|
2013-04-13 21:00:13 +02:00
|
|
|
function() {jQuery(this).addClass("ui-state-hover");},
|
|
|
|
function() {jQuery(this).removeClass("ui-state-hover");}
|
2012-03-15 23:57:55 +01:00
|
|
|
);
|
|
|
|
var option = jQuery(document.createElement("input"))
|
|
|
|
.attr("type", "checkbox")
|
|
|
|
.attr("id",opt_id)
|
|
|
|
.attr("value", _value)
|
|
|
|
.appendTo(label);
|
|
|
|
if(typeof _title !== "undefined")
|
|
|
|
{
|
|
|
|
option.attr("title",_title);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some special stuff for categories
|
2012-05-01 01:29:31 +02:00
|
|
|
if(option_data )
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
2012-05-01 01:29:31 +02:00
|
|
|
if(option_data.icon)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
2012-05-01 01:29:31 +02:00
|
|
|
var img = this.egw().image(option_data.icon);
|
2012-03-15 23:57:55 +01:00
|
|
|
jQuery(document.createElement("img"))
|
|
|
|
.attr("src", img)
|
|
|
|
.appendTo(label);
|
|
|
|
}
|
2012-05-01 01:29:31 +02:00
|
|
|
if(option_data.color)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
2012-05-01 01:29:31 +02:00
|
|
|
label.css("background-color",option_data.color);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
label.append(jQuery("<span>"+_label+"</span>"));
|
2012-03-15 23:57:55 +01:00
|
|
|
var li = jQuery(document.createElement("li")).append(label);
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2013-04-29 20:36:48 +02:00
|
|
|
li.appendTo(dom_element || this.multiOptions);
|
2012-03-15 23:57:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a regular drop-down select box
|
|
|
|
*/
|
2011-08-21 10:48:53 +02:00
|
|
|
createInputWidget: function() {
|
|
|
|
// Create the base input widget
|
|
|
|
this.input = $j(document.createElement("select"))
|
|
|
|
.addClass("et2_selectbox")
|
|
|
|
.attr("size", this.options.rows);
|
2011-08-16 22:32:13 +02:00
|
|
|
|
2011-08-21 10:48:53 +02:00
|
|
|
this.setDOMNode(this.input[0]);
|
|
|
|
|
|
|
|
// Add the empty label
|
|
|
|
if(this.options.empty_label)
|
2011-08-16 19:02:09 +02:00
|
|
|
{
|
2013-08-21 17:59:42 +02:00
|
|
|
this._appendOptionElement("", this.options.empty_label);
|
2011-08-16 19:02:09 +02:00
|
|
|
}
|
2011-08-20 20:34:14 +02:00
|
|
|
|
2011-08-22 10:58:20 +02:00
|
|
|
// Set multiple
|
|
|
|
if(this.options.multiple)
|
2011-08-21 10:48:53 +02:00
|
|
|
{
|
|
|
|
this.input.attr("multiple", "multiple");
|
2011-08-17 19:50:15 +02:00
|
|
|
}
|
2011-08-21 15:24:20 +02:00
|
|
|
},
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
/**
|
|
|
|
* Create a list of checkboxes
|
|
|
|
*/
|
|
|
|
createMultiSelect: function() {
|
|
|
|
var node = jQuery(document.createElement("div"))
|
|
|
|
.addClass("et2_selectbox");
|
|
|
|
|
|
|
|
var header = jQuery(document.createElement("div"))
|
|
|
|
.addClass("ui-widget-header ui-helper-clearfix")
|
|
|
|
.appendTo(node);
|
2012-07-05 22:16:19 +02:00
|
|
|
var controls = jQuery(document.createElement("ul"))
|
|
|
|
.addClass('ui-helper-reset')
|
|
|
|
.appendTo(header);
|
2012-03-15 23:57:55 +01:00
|
|
|
|
|
|
|
if(this.options.empty_label)
|
|
|
|
{
|
|
|
|
jQuery(document.createElement("span"))
|
|
|
|
.text(this.options.empty_label)
|
|
|
|
.addClass("ui-multiselect-header")
|
|
|
|
.appendTo(header);
|
|
|
|
}
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
// Set up for options to be added later
|
|
|
|
var options = this.multiOptions = jQuery(document.createElement("ul"));
|
|
|
|
this.multiOptions.addClass("ui-multiselect-checkboxes ui-helper-reset")
|
|
|
|
.css("height", 1.9*this.options.rows + "em")
|
|
|
|
.appendTo(node);
|
|
|
|
|
2013-11-03 14:33:32 +01:00
|
|
|
if(this.options.rows >= 5)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
|
|
|
// Check / uncheck all
|
|
|
|
var header_controls = {
|
|
|
|
check: {
|
|
|
|
icon_class: 'ui-icon-check',
|
|
|
|
label: 'Check all',
|
|
|
|
click: function(e) {
|
2013-06-06 00:45:19 +02:00
|
|
|
var all_set = jQuery("input[type='checkbox']",e.data).prop("checked");
|
|
|
|
jQuery("input[type='checkbox']",e.data).prop("checked", !all_set);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
2014-01-29 19:55:24 +01:00
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2012-03-15 23:57:55 +01:00
|
|
|
for(var key in header_controls)
|
|
|
|
{
|
|
|
|
jQuery(document.createElement("li"))
|
|
|
|
.addClass("et2_clickable")
|
|
|
|
.click(options, header_controls[key].click)
|
2013-08-19 22:21:56 +02:00
|
|
|
.attr("title", header_controls[key].label)
|
2012-03-15 23:57:55 +01:00
|
|
|
.append('<span class="ui-icon ' + header_controls[key].icon_class + '"/>')
|
|
|
|
.appendTo(controls);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
this.setDOMNode(node[0]);
|
|
|
|
},
|
|
|
|
|
2013-03-15 18:47:28 +01:00
|
|
|
doLoadingFinished: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2014-06-10 00:55:39 +02:00
|
|
|
this.set_tags(this.options.tags, this.options.width);
|
2013-06-17 22:55:42 +02:00
|
|
|
|
2013-03-15 18:47:28 +01:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2011-08-31 18:58:44 +02:00
|
|
|
loadFromXML: function(_node) {
|
2012-07-11 00:20:13 +02:00
|
|
|
// Handle special case where legacy option for empty label is used (conflicts with rows), and rows is set as an attribute
|
2014-01-29 19:55:24 +01:00
|
|
|
var legacy = _node.getAttribute("options");
|
|
|
|
if(legacy)
|
2012-07-11 00:20:13 +02:00
|
|
|
{
|
|
|
|
var legacy = legacy.split(",");
|
|
|
|
if(legacy.length && isNaN(legacy[0]))
|
|
|
|
{
|
|
|
|
this.options.empty_label = legacy[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-31 18:58:44 +02:00
|
|
|
// Read the option-tags
|
|
|
|
var options = et2_directChildrenByTagName(_node, "options");
|
|
|
|
for (var i = 0; i < options.length; i++)
|
|
|
|
{
|
2012-05-02 21:45:35 +02:00
|
|
|
this.options.select_options[et2_readAttrWithDefault(options[i], "value", options[i].textContent)] = {
|
|
|
|
"label": options[i].textContent,
|
|
|
|
"title": et2_readAttrWithDefault(options[i], "title", "")
|
|
|
|
};
|
2011-08-31 18:58:44 +02:00
|
|
|
}
|
2014-05-13 20:40:31 +02:00
|
|
|
|
2012-05-02 21:45:35 +02:00
|
|
|
this.set_select_options(this.options.select_options);
|
2011-08-31 18:58:44 +02:00
|
|
|
},
|
|
|
|
|
2014-07-13 11:14:58 +02:00
|
|
|
/**
|
|
|
|
* Regular expression, to check string-value contains multiple comma-separated values
|
|
|
|
*/
|
|
|
|
_is_multiple_regexp: /^[,0-9A-Za-z/_-]+$/,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set value
|
|
|
|
*
|
|
|
|
* @param _value
|
|
|
|
*/
|
2014-06-04 11:52:02 +02:00
|
|
|
set_value: function(_value)
|
|
|
|
{
|
|
|
|
if (typeof _value == "number") _value = ""+_value; // convert to string for consitent matching
|
2014-07-13 11:14:58 +02:00
|
|
|
if(typeof _value == "string" && this.options.multiple && _value.match(this._is_multiple_regexp) !== null)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
|
|
|
_value = _value.split(',');
|
|
|
|
}
|
2014-09-29 22:37:23 +02:00
|
|
|
if(this.input !== null && this.options.select_options && (
|
|
|
|
!jQuery.isEmptyObject(this.options.select_options) || this.options.select_options.length > 0
|
|
|
|
) && this.input.children().length == 0)
|
2013-11-01 22:12:20 +01:00
|
|
|
{
|
|
|
|
// No options set yet
|
|
|
|
this.set_select_options(this.options.select_options);
|
|
|
|
}
|
2015-03-31 18:23:41 +02:00
|
|
|
this._oldValue = this.value;
|
2013-06-25 23:56:08 +02:00
|
|
|
if(this.input !== null && (this.options.tags || this.options.search))
|
2013-03-15 18:47:28 +01:00
|
|
|
{
|
2014-12-08 19:14:00 +01:00
|
|
|
// Value must be a real Array, not an object
|
2014-12-08 21:01:15 +01:00
|
|
|
this.input.val(typeof _value == 'object' && _value != null ? jQuery.map(_value,function(value,index){return [value];}) : _value);
|
2013-03-15 18:47:28 +01:00
|
|
|
this.input.trigger("liszt:updated");
|
2013-11-01 22:12:20 +01:00
|
|
|
this.value = this.input.val();
|
2013-03-15 18:47:28 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-03-15 23:57:55 +01:00
|
|
|
if(this.input == null)
|
|
|
|
{
|
|
|
|
return this.set_multi_value(_value);
|
|
|
|
}
|
2012-06-05 23:09:16 +02:00
|
|
|
if(typeof _value != 'string' && jQuery(this.value).not(_value).length == 0 && jQuery(_value).not(this.value).length == 0)
|
|
|
|
{
|
|
|
|
// Unchanged
|
2013-03-05 00:25:36 +01:00
|
|
|
if(_value == this.value) return;
|
2012-06-05 23:09:16 +02:00
|
|
|
}
|
2013-07-20 19:20:55 +02:00
|
|
|
jQuery("option",this.input).prop("selected", false);
|
2011-09-29 21:20:20 +02:00
|
|
|
if(typeof _value == "array")
|
2011-09-26 18:01:42 +02:00
|
|
|
{
|
2011-09-29 21:20:20 +02:00
|
|
|
for(var i = 0; i < _value.length; i++)
|
|
|
|
{
|
2013-07-20 19:20:55 +02:00
|
|
|
jQuery("option[value='"+_value[i]+"']", this.input).prop("selected", true);
|
2011-09-29 21:20:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (typeof _value == "object")
|
|
|
|
{
|
|
|
|
for(var i in _value)
|
|
|
|
{
|
2013-07-20 19:20:55 +02:00
|
|
|
jQuery("option[value='"+_value[i]+"']", this.input).prop("selected", true);
|
2011-09-29 21:20:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-01 22:12:20 +01:00
|
|
|
if(_value && jQuery("option[value='"+_value+"']", this.input).prop("selected", true).length == 0)
|
2011-09-29 21:20:20 +02:00
|
|
|
{
|
2012-04-30 19:00:50 +02:00
|
|
|
if(this.options.select_options[_value])
|
|
|
|
{
|
|
|
|
// Options not set yet? Do that now, which will try again.
|
|
|
|
return this.set_select_options(this.options.select_options);
|
|
|
|
}
|
2013-11-01 22:12:20 +01:00
|
|
|
else if (jQuery.isEmptyObject(this.options.select_options))
|
|
|
|
{
|
|
|
|
this.egw().debug("warn", "Can't set value to '%s', widget has no options set",_value, this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.egw().debug("warn", "Tried to set value '%s' that isn't an option", _value, this);
|
|
|
|
}
|
|
|
|
return;
|
2011-09-29 21:20:20 +02:00
|
|
|
}
|
2011-09-26 18:01:42 +02:00
|
|
|
}
|
2015-03-31 18:29:15 +02:00
|
|
|
this.value = _value;
|
2015-03-31 18:23:41 +02:00
|
|
|
if(this.isAttached() && this._oldValue !== et2_no_init && this._oldValue !== _value)
|
|
|
|
{
|
|
|
|
this.input.change();
|
|
|
|
}
|
2011-09-26 18:01:42 +02:00
|
|
|
},
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
set_multi_value: function(_value) {
|
2013-07-20 19:20:55 +02:00
|
|
|
jQuery("input",this.multiOptions).prop("checked", false);
|
2012-03-15 23:57:55 +01:00
|
|
|
if(typeof _value == "array")
|
|
|
|
{
|
|
|
|
for(var i = 0; i < _value.length; i++)
|
|
|
|
{
|
2013-07-20 19:20:55 +02:00
|
|
|
jQuery("input[value='"+_value[i]+"']", this.multiOptions).prop("checked", true);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (typeof _value == "object")
|
|
|
|
{
|
|
|
|
for(var i in _value)
|
|
|
|
{
|
2013-07-20 19:20:55 +02:00
|
|
|
jQuery("input[value='"+_value[i]+"']", this.multiOptions).prop("checked", true);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-20 19:20:55 +02:00
|
|
|
if(jQuery("input[value='"+_value+"']", this.multiOptions).prop("checked", true).length == 0)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
2014-01-21 15:39:51 +01:00
|
|
|
this.egw().debug("warn", "Tried to set value that isn't an option", this, _value);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort selected to the top
|
|
|
|
if(this.selected_first)
|
|
|
|
{
|
|
|
|
this.multiOptions.find("li:has(input:checked)").prependTo(this.multiOptions);
|
|
|
|
}
|
2013-11-27 17:35:45 +01:00
|
|
|
this.value = _value;
|
2012-03-15 23:57:55 +01:00
|
|
|
},
|
|
|
|
|
2014-02-24 19:13:54 +01:00
|
|
|
/**
|
|
|
|
* Add a button to toggle between single select and multi select.
|
|
|
|
*
|
|
|
|
* @param {number} _rows How many rows for multi-select
|
|
|
|
*/
|
|
|
|
set_expand_multiple_rows: function(_rows)
|
|
|
|
{
|
|
|
|
this.options.expand_multiple_rows = _rows;
|
|
|
|
|
|
|
|
var surroundings = this.getSurroundings();
|
|
|
|
if(_rows <= 1 )
|
|
|
|
{
|
|
|
|
// Remove
|
|
|
|
surroundings.removeDOMNode(this.expand_button.get(0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-25 16:20:05 +01:00
|
|
|
if (!this.expand_button)
|
|
|
|
{
|
|
|
|
var button_id = this.getInstanceManager().uniqueId+'_'+this.id.replace(/\./g, '-') + "_expand";
|
|
|
|
this.expand_button = $j("<button class='et2_button et2_button_icon et2_selectbox_expand' id='" + button_id + "'/>")
|
|
|
|
.on("click", jQuery.proxy(function(e) {
|
|
|
|
if(typeof this.input.attr('size') !== 'undefined' && this.input.attr('size') != 1)
|
|
|
|
{
|
|
|
|
this.set_multiple(false, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.set_multiple(true, this.options.expand_multiple_rows);
|
|
|
|
}
|
|
|
|
},this));
|
|
|
|
}
|
2014-02-24 19:13:54 +01:00
|
|
|
surroundings.appendDOMNode(this.expand_button.get(0));
|
|
|
|
}
|
|
|
|
surroundings.update();
|
|
|
|
},
|
|
|
|
|
2013-06-17 22:55:42 +02:00
|
|
|
/**
|
|
|
|
* Turn tag style on and off
|
2013-11-07 14:20:49 +01:00
|
|
|
*
|
|
|
|
* If you want to switch multiple on too, you need to do so before switching tags on!
|
|
|
|
*
|
|
|
|
* @param {boolean} _tags
|
|
|
|
* @param {string} _width width to use, default width of selectbox
|
2013-06-17 22:55:42 +02:00
|
|
|
*/
|
2013-11-07 14:20:49 +01:00
|
|
|
set_tags: function(_tags, _width)
|
|
|
|
{
|
|
|
|
this.options.tags = _tags;
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2013-06-17 22:55:42 +02:00
|
|
|
// Can't actually do chosen until attached, loadingFinished should call again
|
|
|
|
if(!this.isAttached()) return;
|
|
|
|
|
|
|
|
if(this.input != null && !this.options.tags && !this.options.search)
|
|
|
|
{
|
|
|
|
this.input.unchosen().css('width', '');
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2013-06-17 22:55:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn on tags, if desired
|
|
|
|
if(this.input != null && (this.options.search || this.options.tags) && !this.options.disabled)
|
|
|
|
{
|
|
|
|
if(this.options.empty_label)
|
|
|
|
{
|
2014-05-07 14:23:02 +02:00
|
|
|
this.input.attr("data-placeholder", this.options.empty_label);
|
2013-11-27 19:03:26 +01:00
|
|
|
// Remove from list of options, if multiple
|
|
|
|
if (this.options.multiple)
|
2013-11-21 18:39:44 +01:00
|
|
|
{
|
|
|
|
this.input.children('[value=""]').remove();
|
|
|
|
}
|
2013-06-17 22:55:42 +02:00
|
|
|
}
|
2014-04-22 17:47:22 +02:00
|
|
|
// Don't do it again if already done
|
|
|
|
if(this.input.hasClass("chzn-done")) return;
|
2014-06-04 11:52:02 +02:00
|
|
|
|
2013-09-18 22:15:11 +02:00
|
|
|
// Properly size chosen, even if on a hidden tab
|
|
|
|
var size = egw.getHiddenDimensions(this.input);
|
|
|
|
this.input.chosen({
|
2013-11-07 14:20:49 +01:00
|
|
|
inherit_select_classes: true,
|
|
|
|
search_contains: true,
|
|
|
|
width: _width || size.w + "px"
|
|
|
|
})
|
|
|
|
.change(this.onchange);
|
2013-06-17 22:55:42 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
/**
|
2011-09-14 22:36:39 +02:00
|
|
|
* The set_select_options function is added, as the select options have to be
|
2011-08-21 15:24:20 +02:00
|
|
|
* added after the "option"-widgets were added to selectbox.
|
2014-01-29 19:55:24 +01:00
|
|
|
*
|
|
|
|
* @param {(array|object)} _options array or object with options
|
2011-08-21 15:24:20 +02:00
|
|
|
*/
|
|
|
|
set_select_options: function(_options) {
|
2012-04-30 19:00:50 +02:00
|
|
|
// Empty current options
|
|
|
|
if(this.input)
|
|
|
|
{
|
|
|
|
this.input.empty();
|
|
|
|
}
|
|
|
|
else if (this.multiOptions)
|
|
|
|
{
|
|
|
|
this.multiOptions.empty();
|
|
|
|
}
|
2013-10-10 12:23:37 +02:00
|
|
|
// Re-add empty, it's usually not there (empty_label get's allways translated, independent of no_lang!)
|
2014-04-22 17:47:22 +02:00
|
|
|
// Empty label should not be added as an option for chosen, it conflicts
|
|
|
|
if(this.options.empty_label && !(this.options.tags || this.options.search))
|
2012-04-30 19:00:50 +02:00
|
|
|
{
|
2014-05-07 15:03:14 +02:00
|
|
|
this._appendOptionElement('',this.egw().lang(this.options.empty_label));
|
2012-04-30 19:00:50 +02:00
|
|
|
}
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
// Add the select_options
|
|
|
|
for (var key in _options)
|
|
|
|
{
|
2012-03-05 22:07:02 +01:00
|
|
|
// Translate the options
|
|
|
|
if(!this.options.no_lang)
|
|
|
|
{
|
2015-03-19 11:54:29 +01:00
|
|
|
if (typeof _options[key] === 'object' && _options[key] !== null)
|
2012-03-05 22:07:02 +01:00
|
|
|
{
|
2012-03-05 22:40:44 +01:00
|
|
|
if(_options[key]["label"]) _options[key]["label"] = this.egw().lang(_options[key]["label"]);
|
|
|
|
if(_options[key]["title"]) _options[key]["title"] = this.egw().lang(_options[key]["title"]);
|
2012-03-05 22:07:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-05 22:40:44 +01:00
|
|
|
_options[key] = this.egw().lang(_options[key]);
|
2012-03-05 22:07:02 +01:00
|
|
|
}
|
|
|
|
}
|
2011-08-22 10:58:20 +02:00
|
|
|
|
2015-03-19 11:54:29 +01:00
|
|
|
if (typeof _options[key] === 'object' && _options[key] !== null)
|
2011-08-22 10:58:20 +02:00
|
|
|
{
|
2013-04-29 20:36:48 +02:00
|
|
|
// Optgroup
|
|
|
|
if(typeof _options[key]["label"] == 'undefined' && typeof _options[key]["title"] == "undefined")
|
|
|
|
{
|
|
|
|
var group = $j(document.createElement("optgroup"))
|
|
|
|
.attr("label", this.options.no_lang ? key : this.egw().lang(key))
|
|
|
|
.appendTo(this.input);
|
|
|
|
if(this.input == null)
|
|
|
|
{
|
|
|
|
group = jQuery(document.createElement("ul"))
|
|
|
|
.append('<li class="ui-widget-header"><span>'+key+'</span></li>')
|
|
|
|
.appendTo(this.multiOptions);
|
|
|
|
}
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2013-04-29 20:36:48 +02:00
|
|
|
for(var sub in _options[key])
|
|
|
|
{
|
2015-03-19 11:54:29 +01:00
|
|
|
if (typeof _options[key][sub] === 'object' && _options[key][sub] !== null)
|
2013-04-29 20:36:48 +02:00
|
|
|
{
|
2013-11-03 14:33:32 +01:00
|
|
|
this._appendOptionElement(sub,
|
2013-04-29 20:36:48 +02:00
|
|
|
_options[key][sub]["label"] ? _options[key][sub]["label"] : "",
|
|
|
|
_options[key][sub]["title"] ? _options[key][sub]["title"] : "",
|
|
|
|
group
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-10 08:08:45 +01:00
|
|
|
this._appendOptionElement(sub, _options[key][sub],undefined,group);
|
2013-04-29 20:36:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(this.input == null)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
|
|
|
// Allow some special extras for objects by passing the whole thing
|
|
|
|
_options[key]["label"] = _options[key]["label"] ? _options[key]["label"] : "";
|
2013-11-06 11:31:31 +01:00
|
|
|
this._appendMultiOption(typeof _options[key].value != 'undefined' ? _options[key].value : key,
|
2013-11-03 14:33:32 +01:00
|
|
|
_options[key], _options[key]["title"]);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-06 11:31:31 +01:00
|
|
|
this._appendOptionElement(typeof _options[key].value != 'undefined' ? _options[key].value : key,
|
2012-03-15 23:57:55 +01:00
|
|
|
_options[key]["label"] ? _options[key]["label"] : "",
|
|
|
|
_options[key]["title"] ? _options[key]["title"] : "");
|
|
|
|
}
|
2011-08-22 10:58:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-31 18:58:44 +02:00
|
|
|
this._appendOptionElement(key, _options[key]);
|
2011-08-22 10:58:20 +02:00
|
|
|
}
|
2011-08-21 15:24:20 +02:00
|
|
|
}
|
2013-06-19 21:01:42 +02:00
|
|
|
|
2011-09-28 01:16:54 +02:00
|
|
|
// Sometimes value gets set before options
|
2012-05-08 19:43:13 +02:00
|
|
|
if(this.value || this.options.empty_label) this.set_value(this.value);
|
2012-03-15 23:57:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getValue: function() {
|
|
|
|
if(this.input == null)
|
|
|
|
{
|
|
|
|
var value = [];
|
|
|
|
jQuery("input:checked",this.multiOptions).each(function(){value.push(this.value);});
|
2014-09-26 13:25:09 +02:00
|
|
|
// we need to return null for no value instead of empty array, which gets overwritten by preserved value on server-side
|
|
|
|
this.value = value.length > 0 ? value : null;
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-11 00:20:13 +02:00
|
|
|
this.value = this._super.apply(this, arguments);
|
2012-03-15 23:57:55 +01:00
|
|
|
}
|
2012-07-11 00:20:13 +02:00
|
|
|
return this.value;
|
2013-09-19 22:37:17 +02:00
|
|
|
},
|
2013-11-03 14:33:32 +01:00
|
|
|
|
2013-09-19 22:37:17 +02:00
|
|
|
isDirty: function() {
|
|
|
|
if(this.input == null)
|
|
|
|
{
|
|
|
|
var value = this.getValue();
|
|
|
|
// Array comparison
|
|
|
|
return !($j(this._oldValue).not(value).length == 0 && $j(value).not(this._oldValue).length == 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
}
|
2011-08-16 19:02:09 +02:00
|
|
|
}
|
2011-08-21 10:48:53 +02:00
|
|
|
});
|
2011-09-26 18:01:42 +02:00
|
|
|
et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select", "select-cat",
|
2015-04-01 19:11:21 +02:00
|
|
|
"select-percent", 'select-priority',
|
2011-08-22 18:56:45 +02:00
|
|
|
'select-country', 'select-state', 'select-year', 'select-month',
|
2011-08-30 22:52:10 +02:00
|
|
|
'select-day', 'select-dow', 'select-hour', 'select-number', 'select-app',
|
2011-08-22 18:56:45 +02:00
|
|
|
'select-lang', 'select-bool', 'select-timezone' ]);
|
2011-08-20 20:34:14 +02:00
|
|
|
|
2014-05-05 19:25:01 +02:00
|
|
|
// Static class stuff
|
|
|
|
jQuery.extend(et2_selectbox,
|
|
|
|
{
|
2015-04-01 19:11:21 +02:00
|
|
|
type_cache: {},
|
|
|
|
|
2014-05-05 19:25:01 +02:00
|
|
|
/**
|
|
|
|
* Find the select options for a widget, out of the many places they could be.
|
2014-06-04 11:52:02 +02:00
|
|
|
* @param {et2_widget} widget to check for. Should be some sort of select widget.
|
|
|
|
* @param {object} attr_options Select options in attributes array
|
2015-04-01 19:11:21 +02:00
|
|
|
* @param {object} attrs Widget attributes
|
2014-05-05 19:25:01 +02:00
|
|
|
* @return {object} Select options, or empty object
|
|
|
|
*/
|
2015-04-01 19:11:21 +02:00
|
|
|
find_select_options: function(widget, attr_options, attrs)
|
2014-05-05 19:25:01 +02:00
|
|
|
{
|
|
|
|
var name_parts = widget.id.replace(/[/g,'[').replace(/]|]/g,'').split('[');
|
|
|
|
|
|
|
|
var content_options = {};
|
|
|
|
|
2015-04-01 19:11:21 +02:00
|
|
|
// First check type, there may be static options. There's some special handling
|
|
|
|
// for filterheaders, which have the wrong type.
|
|
|
|
var type = widget.instanceOf(et2_nextmatch_filterheader) ? attrs.widget_type || '' : widget._type;
|
|
|
|
var type_function = type.replace('select-','').replace('_ro','')+'_options';
|
|
|
|
if(typeof this[type_function] == 'function')
|
|
|
|
{
|
|
|
|
var old_type = widget._type;
|
|
|
|
widget._type = type;
|
|
|
|
content_options = this[type_function].call(this, widget, attrs);
|
|
|
|
widget._type = old_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find the options inside the "sel-options"
|
|
|
|
if(jQuery.isEmptyObject(content_options) && widget.getArrayMgr("sel_options"))
|
2014-05-05 19:25:01 +02:00
|
|
|
{
|
|
|
|
// Try first according to ID
|
|
|
|
content_options = widget.getArrayMgr("sel_options").getEntry(widget.id);
|
|
|
|
// ID can get set to an array with 0 => ' ' - not useful
|
|
|
|
if(content_options && content_options.length == 1 && typeof content_options[0] == 'string' && content_options[0].trim() == '')
|
|
|
|
{
|
|
|
|
content_options = null;
|
|
|
|
}
|
|
|
|
// We could wind up too far inside options if label,title are defined
|
|
|
|
if(content_options && !isNaN(name_parts[name_parts.length -1]) && content_options.label && content_options.title)
|
|
|
|
{
|
|
|
|
name_parts.pop();
|
|
|
|
content_options = widget.getArrayMgr("sel_options").getEntry(name_parts.join('['));
|
|
|
|
delete content_options["$row"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select options tend to be defined once, at the top level, so try that
|
|
|
|
if(!content_options || content_options.length == 0)
|
|
|
|
{
|
|
|
|
content_options = widget.getArrayMgr("sel_options").getRoot().getEntry(name_parts[name_parts.length-1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try in correct namespace (inside a grid or something)
|
|
|
|
if(!content_options || content_options.length == 0)
|
|
|
|
{
|
|
|
|
content_options = widget.getArrayMgr("sel_options").getEntry(name_parts[name_parts.length-1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try name like widget[$row]
|
2014-07-22 23:21:33 +02:00
|
|
|
if(name_parts.length > 1 && (!content_options || content_options.length == 0 ))
|
2014-05-05 19:25:01 +02:00
|
|
|
{
|
|
|
|
var pop_that = jQuery.extend([],name_parts);
|
|
|
|
while(pop_that.length > 0 && (!content_options || content_options.length == 0))
|
|
|
|
{
|
2014-07-22 23:21:33 +02:00
|
|
|
var last = pop_that.pop();
|
2014-05-05 19:25:01 +02:00
|
|
|
content_options = widget.getArrayMgr('sel_options').getEntry(pop_that.join('['));
|
2014-07-22 23:21:33 +02:00
|
|
|
|
|
|
|
// Double check, might have found a normal parent namespace ( eg subgrid in subgrid[selectbox] )
|
|
|
|
// with an empty entry for the selecbox. If there were valid options here,
|
|
|
|
// we would have found them already, and keeping this would result in the ID as an option
|
|
|
|
if(content_options && typeof content_options[last] != 'undefined' && content_options[last] )
|
|
|
|
{
|
|
|
|
content_options = content_options[last];
|
|
|
|
}
|
2014-05-05 19:25:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maybe in a row, and options got stuck in ${row} instead of top level
|
|
|
|
// not sure this code is still needed, as server-side no longer creates ${row} or {$row} for select-options
|
2015-03-25 22:45:57 +01:00
|
|
|
var row_stuck = ['${row}','{$row}'];
|
|
|
|
for(var i = 0; i < row_stuck.length && (!content_options || content_options.length == 0); i++)
|
2014-05-05 19:25:01 +02:00
|
|
|
{
|
2015-03-25 22:45:57 +01:00
|
|
|
// perspectiveData.row in nm, data["${row}"] in an auto-repeat grid
|
|
|
|
if(widget.getArrayMgr("sel_options").perspectiveData.row || widget.getArrayMgr("sel_options").data[row_stuck[i]])
|
2014-05-05 19:25:01 +02:00
|
|
|
{
|
2015-03-25 22:45:57 +01:00
|
|
|
var row_id = widget.id.replace(/[0-9]+/,row_stuck[i]);
|
|
|
|
content_options = widget.getArrayMgr("sel_options").getEntry(row_id);
|
|
|
|
if(!content_options || content_options.length == 0)
|
2014-05-05 19:25:01 +02:00
|
|
|
{
|
2015-03-25 22:45:57 +01:00
|
|
|
content_options = widget.getArrayMgr("sel_options").getEntry(row_stuck[i] + '[' + widget.id + ']');
|
2014-05-05 19:25:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(attr_options && !jQuery.isEmptyObject(attr_options) && content_options)
|
|
|
|
{
|
|
|
|
content_options = jQuery.extend(true, {},attr_options,content_options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the options entry was found, if not read it from the
|
|
|
|
// content array.
|
|
|
|
if (jQuery.isEmptyObject(content_options) && widget.getArrayMgr('content') != null)
|
|
|
|
{
|
|
|
|
if (content_options) attr_options = content_options;
|
|
|
|
var content_mgr = widget.getArrayMgr('content');
|
|
|
|
if (content_mgr)
|
|
|
|
{
|
|
|
|
// If that didn't work, check according to ID
|
|
|
|
if (!content_options) content_options = content_mgr.getEntry("options-" + widget.id);
|
2014-05-06 00:17:23 +02:00
|
|
|
// Again, try last name part at top level
|
|
|
|
if (!content_options) content_options = content_mgr.getRoot().getEntry("options-"+name_parts[name_parts.length-1]);
|
2014-05-05 19:25:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default to an empty object
|
|
|
|
if (content_options == null)
|
|
|
|
{
|
|
|
|
content_options = {};
|
|
|
|
}
|
|
|
|
return content_options;
|
2015-04-01 19:11:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some static options, no need to transfer them over and over.
|
|
|
|
* We still need the same thing on the server side to validate, so they
|
|
|
|
* have to match. See etemplate_widget_menupopup::typeOptions()
|
|
|
|
* The type specific legacy options wind up in attrs.other.
|
|
|
|
*/
|
|
|
|
priority_options: function(widget) {
|
|
|
|
return [
|
|
|
|
{value: 1, label: 'low'},
|
|
|
|
{value: 2, label: 'normal'},
|
|
|
|
{value: 3, label: 'high'}
|
|
|
|
];
|
|
|
|
},
|
|
|
|
bool_options: function(widget) {
|
|
|
|
return [
|
|
|
|
{value: 0, label: 'no'},
|
|
|
|
{value: 1, label: 'yes'}
|
|
|
|
];
|
|
|
|
},
|
|
|
|
month_options: function(widget) {
|
|
|
|
return [
|
|
|
|
{value: 1, label:'January'},
|
|
|
|
{value: 2, label:'February'},
|
|
|
|
{value: 3, label:'March'},
|
|
|
|
{value: 4, label:'April'},
|
|
|
|
{value: 5, label:'May'},
|
|
|
|
{value: 6, label:'June'},
|
|
|
|
{value: 7, label:'July'},
|
|
|
|
{value: 8, label:'August'},
|
|
|
|
{value: 9, label:'September'},
|
|
|
|
{value: 10, label:'October'},
|
|
|
|
{value: 11, label:'November'},
|
|
|
|
{value: 12, label:'December'}
|
|
|
|
];
|
|
|
|
},
|
|
|
|
number_options: function(widget, attrs) {
|
|
|
|
if(typeof attrs.other != 'object')
|
|
|
|
{
|
|
|
|
attrs.other = [];
|
|
|
|
}
|
|
|
|
var options = [];
|
|
|
|
var min = typeof(attrs.other[0]) == 'undefined' ? 1 : parseInt(attrs.other[0]);
|
|
|
|
var max = typeof(attrs.other[1]) == 'undefined' ? 10: parseInt(attrs.other[1]);
|
|
|
|
var interval = typeof(attrs.other[2]) == 'undefined' ? 1: parseInt(attrs.other[2]);
|
|
|
|
var format = '%d';
|
|
|
|
|
|
|
|
// leading zero specified in interval
|
|
|
|
if (attrs.other[2] && attrs.other[2][0] == '0')
|
|
|
|
{
|
|
|
|
format = '%0'+(''+interval).length+'d';
|
|
|
|
}
|
|
|
|
// Suffix
|
|
|
|
if(attrs.other[3])
|
|
|
|
{
|
|
|
|
format += widget.egw().lang(attrs.other[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid infinite loop if interval is the wrong direction
|
|
|
|
if ((min <= max) != (interval > 0))
|
|
|
|
{
|
|
|
|
interval = -interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0, n=min; n <= max && i <= 100; n += interval,++i)
|
|
|
|
{
|
|
|
|
options.push({value: n, label: sprintf(format,n)});
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
percent_options: function(widget, attrs)
|
|
|
|
{
|
|
|
|
if(typeof attrs.other != 'object')
|
|
|
|
{
|
|
|
|
attrs.other = [];
|
|
|
|
}
|
|
|
|
attrs.other[0] = 0;
|
|
|
|
attrs.other[1] = 100;
|
|
|
|
attrs.other[2] = typeof(attrs.other[2]) == 'undefined' ? 10 : parseInt(attrs.other[2]);
|
|
|
|
attrs.other[3] = '%%';
|
|
|
|
return this.number_options(widget,attrs);
|
|
|
|
},
|
|
|
|
year_options: function(widget, attrs)
|
|
|
|
{
|
|
|
|
if(typeof attrs.other != 'object')
|
|
|
|
{
|
|
|
|
attrs.other = [];
|
|
|
|
}
|
|
|
|
var t = new Date();
|
|
|
|
attrs.other[0] = t.getFullYear() - (typeof(attrs.other[0]) == 'undefined' ? 3 : parseInt(attrs.other[0]));
|
|
|
|
attrs.other[1] = t.getFullYear() + (typeof(attrs.other[1]) == 'undefined' ? 2 : parseInt(attrs.other[1]));
|
|
|
|
attrs.other[2] = typeof(attrs.other[2]) == 'undefined' ? 1 : parseInt(attrs.other[2]);
|
|
|
|
return this.number_options(widget,attrs);
|
|
|
|
},
|
|
|
|
day_options: function(widget, attrs)
|
|
|
|
{
|
|
|
|
attrs.other = [1,31,1];
|
|
|
|
return this.number_options(widget,attrs);
|
|
|
|
},
|
|
|
|
hour_options: function(widget, attrs)
|
|
|
|
{
|
|
|
|
var options = [];
|
|
|
|
var timeformat = egw.preference('common','timeformat');
|
|
|
|
for (var h = 0; h <= 23; ++h)
|
|
|
|
{
|
|
|
|
options.push({
|
|
|
|
value: h,
|
|
|
|
label: timeformat == 12 ?
|
|
|
|
(( 12 ? h % 12 : 12)+' '+(h < 12 ? egw.lang('am') : egw.lang('pm'))) :
|
|
|
|
sprintf('%02d',h)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
app_options: function(widget,attrs) {
|
|
|
|
var options = ','+(attrs.other||[]).join(',');
|
|
|
|
return this.cached_server_side_options(widget, options, attrs);
|
|
|
|
},
|
|
|
|
cat_options: function(widget, attrs) {
|
|
|
|
// Add in application, if not there
|
|
|
|
if(typeof attrs.other == 'undefined')
|
|
|
|
{
|
|
|
|
attrs.other = new Array(4);
|
|
|
|
}
|
|
|
|
if(typeof attrs.other[3] == 'undefined')
|
|
|
|
{
|
|
|
|
attrs.other[3] = attrs.application || widget.getInstanceManager().app;
|
|
|
|
}
|
|
|
|
var options =(attrs.other||[]).join(',');
|
|
|
|
return this.cached_server_side_options(widget, options, attrs);
|
|
|
|
},
|
|
|
|
country_options: function(widget, attrs) {
|
|
|
|
var options = ','+(attrs.other||[]).join(',');
|
|
|
|
return this.cached_server_side_options(widget, options, attrs);
|
|
|
|
},
|
|
|
|
dow_options: function(widget,attrs) {
|
|
|
|
var options = ','+(attrs.other||[]).join(',');
|
|
|
|
return this.cached_server_side_options(widget, options, attrs);
|
|
|
|
},
|
|
|
|
lang_options: function(widget,attrs) {
|
|
|
|
var options = ','+(attrs.other||[]).join(',');
|
|
|
|
return this.cached_server_side_options(widget, options, attrs);
|
|
|
|
},
|
|
|
|
timezone_options: function(widget,attrs) {
|
|
|
|
var options = ','+(attrs.other||[]).join(',');
|
|
|
|
return this.cached_server_side_options(widget, options, attrs);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Some options change, or are too complicated to have twice, so we get the
|
|
|
|
* options from the server once, then keep them to use if they're needed again.
|
|
|
|
* We use the options string to keep the different possibilites (eg. categories
|
|
|
|
* for different apps) seperate.
|
|
|
|
*
|
|
|
|
* @param {et2_selectbox} widget Selectbox we're looking at
|
|
|
|
* @param {string} options_string
|
|
|
|
* @param {Object} attrs Widget attributes (not yet fully set)
|
|
|
|
* @returns {Object} Array of options, or empty and they'll get filled in later
|
|
|
|
*/
|
|
|
|
cached_server_side_options: function(widget, options_string, attrs)
|
|
|
|
{
|
|
|
|
var cache_id = widget._type+'_'+options_string;
|
|
|
|
var cache = egw.window.et2_selectbox.type_cache[cache_id];
|
|
|
|
if (typeof cache == 'undefined')
|
|
|
|
{
|
|
|
|
// Fetch with json instead of jsonq because there may be more than
|
|
|
|
// one widget listening for the response by the time it gets back,
|
|
|
|
// and we can't do that when it's queued.
|
|
|
|
egw.window.et2_selectbox.type_cache[cache_id] = egw.json(
|
|
|
|
widget.getInstanceManager().app+'.etemplate_widget_menupopup.ajax_get_options.etemplate',
|
|
|
|
[widget._type,options_string]
|
|
|
|
).sendRequest();
|
|
|
|
}
|
|
|
|
cache = egw.window.et2_selectbox.type_cache[cache_id];
|
|
|
|
if(typeof cache.done == 'function')
|
|
|
|
{
|
|
|
|
// pending, wait for it
|
|
|
|
cache.done(jQuery.proxy(function(response) {
|
|
|
|
egw.window.et2_selectbox.type_cache[this.cache_id] = response.response[0].data||undefined;
|
|
|
|
// Set select_options in attributes in case we get a resonse before
|
|
|
|
// the widget is finished loading (otherwise it will re-set to {})
|
|
|
|
attrs.select_options = egw.window.et2_selectbox.type_cache[this.cache_id];
|
|
|
|
|
|
|
|
egw.window.setTimeout(jQuery.proxy(function() {
|
|
|
|
this.widget.set_select_options(egw.window.et2_selectbox.type_cache[this.cache_id]||{});
|
|
|
|
},this),1);
|
|
|
|
},{widget:widget,cache_id:cache_id}));
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return cache;
|
|
|
|
}
|
2014-05-05 19:25:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-08-23 02:12:01 +02:00
|
|
|
/**
|
|
|
|
* et2_selectbox_ro is the readonly implementation of the selectbox.
|
2013-11-03 14:33:32 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_selectbox
|
2011-08-23 02:12:01 +02:00
|
|
|
*/
|
2013-11-03 14:33:32 +01:00
|
|
|
var et2_selectbox_ro = et2_selectbox.extend([et2_IDetachedDOM],
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
2013-11-03 14:33:32 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_selectbox_ro
|
|
|
|
*/
|
2011-08-24 12:05:52 +02:00
|
|
|
init: function() {
|
2011-08-23 02:12:01 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.supportedWidgetClasses = [];
|
2011-08-23 11:45:45 +02:00
|
|
|
this.optionValues = {};
|
2012-05-24 01:54:30 +02:00
|
|
|
if(this.options.select_options) this.set_select_options(this.options.select_options);
|
2011-08-23 02:12:01 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
createInputWidget: function() {
|
|
|
|
this.span = $j(document.createElement("span"))
|
|
|
|
.addClass("et2_selectbox readonly")
|
|
|
|
.text(this.options.empty_label);
|
|
|
|
|
|
|
|
this.setDOMNode(this.span[0]);
|
|
|
|
},
|
2011-08-23 11:45:45 +02:00
|
|
|
|
2012-04-17 01:08:28 +02:00
|
|
|
// Handle read-only multiselects in the same way
|
|
|
|
createMultiSelect: function() {
|
2012-05-01 01:29:31 +02:00
|
|
|
this.span = $j(document.createElement("ul"))
|
|
|
|
.addClass("et2_selectbox readonly");
|
|
|
|
|
|
|
|
this.setDOMNode(this.span[0]);
|
2012-04-17 01:08:28 +02:00
|
|
|
},
|
|
|
|
|
2011-08-23 11:45:45 +02:00
|
|
|
loadFromXML: function(_node) {
|
|
|
|
// Read the option-tags
|
|
|
|
var options = et2_directChildrenByTagName(_node, "options");
|
|
|
|
for (var i = 0; i < options.length; i++)
|
|
|
|
{
|
|
|
|
this.optionValues[et2_readAttrWithDefault(options[i], "value", 0)] =
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
|
|
|
"label": options[i].textContent,
|
|
|
|
"title": et2_readAttrWithDefault(options[i], "title", "")
|
|
|
|
};
|
2011-08-23 11:45:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-23 02:12:01 +02:00
|
|
|
set_select_options: function(_options) {
|
2011-08-23 11:45:45 +02:00
|
|
|
for (var key in _options)
|
|
|
|
{
|
2013-06-25 16:37:24 +02:00
|
|
|
// Translate the options
|
|
|
|
if(!this.options.no_lang)
|
|
|
|
{
|
2013-07-20 19:20:55 +02:00
|
|
|
if (typeof _options[key] === 'object' && _options[key] != null)
|
2013-06-25 16:37:24 +02:00
|
|
|
{
|
|
|
|
if(_options[key]["label"]) _options[key]["label"] = this.egw().lang(_options[key]["label"]);
|
|
|
|
if(_options[key]["title"]) _options[key]["title"] = this.egw().lang(_options[key]["title"]);
|
2013-11-07 14:20:49 +01:00
|
|
|
|
2013-06-25 16:37:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_options[key] = this.egw().lang(_options[key]);
|
|
|
|
}
|
|
|
|
}
|
2011-08-23 11:45:45 +02:00
|
|
|
}
|
2014-03-18 15:41:23 +01:00
|
|
|
this.optionValues = _options;
|
2011-08-23 02:12:01 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
set_value: function(_value) {
|
2014-03-18 15:41:23 +01:00
|
|
|
this.value = _value;
|
|
|
|
|
|
|
|
if(typeof _value == "string")
|
2012-05-01 01:29:31 +02:00
|
|
|
{
|
2014-07-13 11:14:58 +02:00
|
|
|
_value = _value.match(this._is_multiple_regexp) !== null ? _value.split(',') : [_value];
|
2012-05-01 01:29:31 +02:00
|
|
|
}
|
2014-03-18 15:41:23 +01:00
|
|
|
this.span.empty();
|
|
|
|
|
|
|
|
if(_value)
|
2013-06-25 16:37:24 +02:00
|
|
|
{
|
2014-03-18 15:41:23 +01:00
|
|
|
for(var i = 0; i < _value.length; i++)
|
2012-05-03 00:12:42 +02:00
|
|
|
{
|
2014-03-18 15:41:23 +01:00
|
|
|
for(var o in this.optionValues)
|
2012-05-01 01:29:31 +02:00
|
|
|
{
|
2014-03-18 15:41:23 +01:00
|
|
|
var option = this.optionValues[o];
|
2014-08-27 19:13:38 +02:00
|
|
|
var key = typeof option == 'object' && option != null && typeof option.value != 'undefined' ? option.value : o;
|
2014-03-18 15:41:23 +01:00
|
|
|
if (key != _value[i]) continue;
|
|
|
|
var label = typeof option == 'object' ? option.label : option;
|
|
|
|
if (_value.length == 1)
|
2012-05-03 00:12:42 +02:00
|
|
|
{
|
2014-03-18 15:41:23 +01:00
|
|
|
this.span.text(label);
|
|
|
|
if (typeof option == 'object' && option.title) this.set_statustext(option.title);
|
2015-03-24 16:18:19 +01:00
|
|
|
break;
|
2012-05-03 00:12:42 +02:00
|
|
|
}
|
2014-03-18 15:41:23 +01:00
|
|
|
else
|
2013-03-26 00:00:25 +01:00
|
|
|
{
|
2014-03-18 15:41:23 +01:00
|
|
|
$j('<li>')
|
|
|
|
.text(label)
|
|
|
|
.attr('data-value', _value[i])
|
|
|
|
.appendTo(this.span);
|
2015-03-24 16:18:19 +01:00
|
|
|
break;
|
2013-03-26 00:00:25 +01:00
|
|
|
}
|
2012-05-01 01:29:31 +02:00
|
|
|
}
|
2012-05-03 00:12:42 +02:00
|
|
|
}
|
2011-10-18 16:13:44 +02:00
|
|
|
}
|
2014-11-24 20:58:59 +01:00
|
|
|
else if (this.options.empty_label)
|
|
|
|
{
|
|
|
|
this.span.text(this.options.empty_label);
|
|
|
|
}
|
2011-10-19 23:03:22 +02:00
|
|
|
},
|
|
|
|
|
2012-04-25 17:41:19 +02:00
|
|
|
/**
|
|
|
|
* Override parent to return null - no value, not node value
|
|
|
|
*/
|
|
|
|
getValue: function() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-10-19 23:03:22 +02:00
|
|
|
/**
|
|
|
|
* Functions for et2_IDetachedDOM
|
|
|
|
*/
|
|
|
|
/**
|
2014-01-29 19:55:24 +01:00
|
|
|
* Creates a list of attributes which can be set when working in the
|
|
|
|
* "detached" mode. The result is stored in the _attrs array which is provided
|
|
|
|
* by the calling code.
|
|
|
|
*
|
|
|
|
* @param {array} _attrs array to add further attributes to
|
|
|
|
*/
|
|
|
|
getDetachedAttributes: function(_attrs) {
|
|
|
|
_attrs.push("value");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of DOM nodes. The (relatively) same DOM-Nodes have to be
|
|
|
|
* passed to the "setDetachedAttributes" function in the same order.
|
|
|
|
*
|
|
|
|
* @return {array}
|
|
|
|
*/
|
|
|
|
getDetachedNodes: function() {
|
|
|
|
return [this.span[0]];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the given associative attribute->value array and applies the
|
|
|
|
* attributes to the given DOM-Node.
|
|
|
|
*
|
|
|
|
* @param _nodes is an array of nodes which have to be in the same order as
|
|
|
|
* the nodes returned by "getDetachedNodes"
|
|
|
|
* @param _values is an associative array which contains a subset of attributes
|
|
|
|
* returned by the "getDetachedAttributes" function and sets them to the
|
|
|
|
* given values.
|
|
|
|
*/
|
|
|
|
setDetachedAttributes: function(_nodes, _values) {
|
|
|
|
this.span = jQuery(_nodes[0]);
|
|
|
|
this.set_value(_values["value"]);
|
2011-08-23 02:12:01 +02:00
|
|
|
}
|
|
|
|
});
|
2011-10-18 16:13:44 +02:00
|
|
|
et2_register_widget(et2_selectbox_ro, ["menupopup_ro", "listbox_ro", "select_ro", "select-cat_ro",
|
2012-03-14 20:02:28 +01:00
|
|
|
"select-percent_ro", 'select-priority_ro', 'select-access_ro',
|
2011-08-23 02:12:01 +02:00
|
|
|
'select-country_ro', 'select-state_ro', 'select-year_ro', 'select-month_ro',
|
2011-08-30 22:52:10 +02:00
|
|
|
'select-day_ro', 'select-dow_ro', 'select-hour_ro', 'select-number_ro', 'select-app_ro',
|
2011-08-23 02:12:01 +02:00
|
|
|
'select-lang_ro', 'select-bool_ro', 'select-timezone_ro' ]);
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
/**
|
|
|
|
* Widget class which represents a single option inside a selectbox
|
|
|
|
*/
|
2011-08-31 18:58:44 +02:00
|
|
|
/*var et2_option = et2_baseWidget.extend({
|
2011-08-21 15:24:20 +02:00
|
|
|
|
|
|
|
attributes: {
|
|
|
|
"value": {
|
|
|
|
"name": "Value",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Value which is sent back to the server when this entry is selected."
|
|
|
|
},
|
2011-08-22 10:58:20 +02:00
|
|
|
"label": {
|
|
|
|
"name": "Label",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Caption of the option element"
|
|
|
|
},
|
2011-08-21 15:24:20 +02:00
|
|
|
"width": {
|
|
|
|
"ignore": true
|
|
|
|
},
|
|
|
|
"height": {
|
|
|
|
"ignore": true
|
|
|
|
},
|
|
|
|
"align": {
|
|
|
|
"ignore": true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2011-08-22 10:58:20 +02:00
|
|
|
// Only allow other options inside of this element
|
|
|
|
this.supportedWidgetClasses = [et2_option];
|
2011-08-21 15:24:20 +02:00
|
|
|
|
|
|
|
this.option = $j(document.createElement("option"))
|
2011-08-24 13:31:30 +02:00
|
|
|
.attr("value", this.options.value)
|
|
|
|
.attr("selected", this._parent.options.value == this.options.value ?
|
|
|
|
"selected" : "");
|
2011-08-21 15:24:20 +02:00
|
|
|
|
2011-08-22 10:58:20 +02:00
|
|
|
if (this.options.label)
|
|
|
|
{
|
|
|
|
this.option.text(this.options.label);
|
|
|
|
}
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
this.setDOMNode(this.option[0]);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.option = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadContent: function(_data) {
|
|
|
|
this.option.text(_data);
|
2011-08-26 11:58:25 +02:00
|
|
|
}
|
2011-08-22 10:58:20 +02:00
|
|
|
|
|
|
|
/* Doesn't work either with selectboxes
|
|
|
|
set_statustext: function(_value) {
|
|
|
|
this.statustext = _value;
|
|
|
|
this.option.attr("title", _value);
|
|
|
|
}*/
|
2011-08-21 15:24:20 +02:00
|
|
|
|
2011-08-31 18:58:44 +02:00
|
|
|
//});*/
|
2011-08-21 15:24:20 +02:00
|
|
|
|
2011-08-31 18:58:44 +02:00
|
|
|
//et2_register_widget(et2_option, ["option"]);
|
2011-08-21 15:24:20 +02:00
|
|
|
|
|
|
|
|
2011-08-20 20:34:14 +02:00
|
|
|
/**
|
|
|
|
* Class which just implements the menulist container
|
2013-11-03 14:33:32 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_DOMWidget
|
2013-11-03 14:33:32 +01:00
|
|
|
*/
|
2013-04-13 21:00:13 +02:00
|
|
|
var et2_menulist = et2_DOMWidget.extend(
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Construtor
|
2013-11-03 14:33:32 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_menulist
|
|
|
|
*/
|
2011-08-20 20:34:14 +02:00
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2011-08-23 02:12:01 +02:00
|
|
|
this.supportedWidgetClasses = [et2_selectbox, et2_selectbox_ro];
|
2011-08-20 20:34:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Just pass the parent DOM node through
|
|
|
|
getDOMNode: function(_sender) {
|
2011-08-21 17:22:00 +02:00
|
|
|
if (_sender != this)
|
2011-08-20 20:34:14 +02:00
|
|
|
{
|
|
|
|
return this._parent.getDOMNode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2012-03-13 23:16:08 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Also need to pass through parent's children
|
|
|
|
getChildren: function() {
|
|
|
|
return this._parent.getChildren();
|
2011-08-20 20:34:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
et2_register_widget(et2_menulist, ["menulist"]);
|
|
|
|
|