2011-08-16 19:02:09 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate2 - JS Selectbox object
|
|
|
|
*
|
|
|
|
* @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;
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
var et2_selectbox = et2_inputWidget.extend({
|
|
|
|
|
|
|
|
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"
|
|
|
|
},
|
|
|
|
"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": "",
|
|
|
|
"description": "Textual label for first row, eg: 'All' or 'None'. ID will be ''"
|
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
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
"type": "any" // Can be string or integer
|
2013-02-07 15:36:19 +01:00
|
|
|
},
|
|
|
|
// Type specific legacy options. Avoid using.
|
|
|
|
"other": {
|
|
|
|
"ignore": true,
|
|
|
|
"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
|
|
|
|
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;
|
2012-06-06 16:21:38 +02:00
|
|
|
this.value = '';
|
2012-07-11 00:20:13 +02:00
|
|
|
|
|
|
|
// Grab value if already available
|
|
|
|
if(typeof this.options.value != 'undefined')
|
|
|
|
{
|
|
|
|
this.value = this.options.value;
|
|
|
|
}
|
2011-09-27 02:16:00 +02: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
|
|
|
|
2011-08-23 02:12:01 +02: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")
|
|
|
|
{
|
|
|
|
if(isNaN(this.options.rows))
|
|
|
|
{
|
|
|
|
this.options.empty_label = this.egw().lang(this.options.rows);
|
|
|
|
this.options.rows = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.options.rows = parseInt(this.options.rows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.options.rows > 1)
|
|
|
|
{
|
|
|
|
this.options.multiple = true;
|
|
|
|
this.createMultiSelect();
|
|
|
|
}
|
|
|
|
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() {
|
|
|
|
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
|
|
|
|
if(this.options && this.options.select_options && !jQuery.isEmptyObject(this.options.select_options))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-14 00:02:21 +01:00
|
|
|
var name_parts = this.id.replace(/[/g,'[').replace(/]|]/g,'').split('[');
|
2011-10-19 23:03:22 +02:00
|
|
|
|
2011-08-21 10:48:53 +02:00
|
|
|
// Try to find the options inside the "sel-options" array
|
2011-09-26 18:01:42 +02:00
|
|
|
if(this.getArrayMgr("sel_options"))
|
|
|
|
{
|
2012-03-23 00:19:13 +01:00
|
|
|
var content_options = {};
|
|
|
|
|
|
|
|
// Try first according to ID
|
|
|
|
content_options = this.getArrayMgr("sel_options").getEntry(this.id);
|
2012-06-06 19:00:15 +02:00
|
|
|
// ID can get set to an array with 0 => ' ' - not useful
|
|
|
|
if(content_options && content_options.length == 1 && typeof content_options[0] != 'undefined' && content_options[0].trim() == '')
|
|
|
|
{
|
|
|
|
content_options = null;
|
|
|
|
}
|
2013-02-06 14:49:40 +01:00
|
|
|
// We could wind up too far inside options if label,title are defined
|
2013-02-06 18:08:12 +01:00
|
|
|
if(content_options && !isNaN(name_parts[name_parts.length -1]) && content_options.label && content_options.title)
|
2013-02-06 14:49:40 +01:00
|
|
|
{
|
|
|
|
name_parts.pop();
|
|
|
|
content_options = this.getArrayMgr("sel_options").getEntry(name_parts.join('['));
|
|
|
|
delete content_options["$row"];
|
|
|
|
}
|
2012-03-23 00:19:13 +01:00
|
|
|
|
2012-06-06 19:00:15 +02:00
|
|
|
// Select options tend to be defined once, at the top level, so try that
|
2012-04-25 00:48:39 +02:00
|
|
|
if(!content_options || content_options.length == 0)
|
2012-03-23 00:19:13 +01:00
|
|
|
{
|
|
|
|
content_options = this.getArrayMgr("sel_options").getRoot().getEntry(name_parts[name_parts.length-1]);
|
|
|
|
}
|
2011-10-19 23:03:22 +02:00
|
|
|
|
2012-05-07 19:40:59 +02:00
|
|
|
// Try in correct namespace (inside a grid or something)
|
|
|
|
if(!content_options || content_options.length == 0)
|
|
|
|
{
|
|
|
|
content_options = this.getArrayMgr("sel_options").getEntry(name_parts[name_parts.length-1]);
|
|
|
|
}
|
|
|
|
|
2012-03-23 00:19:13 +01:00
|
|
|
// Maybe in a row, and options got stuck in ${row} instead of top level
|
2012-07-05 22:01:54 +02:00
|
|
|
var row_stuck = ['${row}','{$row}'];
|
|
|
|
for(var i = 0; i < row_stuck.length; i++)
|
2012-03-23 00:19:13 +01:00
|
|
|
{
|
2012-07-05 22:01:54 +02:00
|
|
|
if((!content_options || content_options.length == 0) && (
|
|
|
|
// perspectiveData.row in nm, data["${row}"] in an auto-repeat grid
|
|
|
|
this.getArrayMgr("sel_options").perspectiveData.row || this.getArrayMgr("sel_options").data[row_stuck[i]]))
|
|
|
|
{
|
|
|
|
var row_id = this.id.replace(/[0-9]+/,row_stuck[i]);
|
|
|
|
content_options = this.getArrayMgr("sel_options").getEntry(row_id);
|
2013-02-07 15:36:19 +01:00
|
|
|
if(!content_options || content_options.length == 0)
|
|
|
|
{
|
|
|
|
content_options = this.getArrayMgr("sel_options").getEntry(row_stuck[i] + '[' + this.id + ']');
|
|
|
|
}
|
2012-07-05 22:01:54 +02:00
|
|
|
}
|
2012-03-23 00:19:13 +01:00
|
|
|
}
|
2011-10-12 22:56:11 +02:00
|
|
|
if(_attrs["select_options"] && content_options)
|
|
|
|
{
|
2011-10-13 18:06:56 +02:00
|
|
|
_attrs["select_options"] = jQuery.extend({},_attrs["select_options"],content_options);
|
2011-10-12 22:56:11 +02:00
|
|
|
} else if (content_options) {
|
|
|
|
_attrs["select_options"] = content_options;
|
|
|
|
}
|
2011-09-26 18:01:42 +02:00
|
|
|
}
|
2011-08-16 19:02:09 +02:00
|
|
|
|
2011-08-21 10:48:53 +02:00
|
|
|
// Check whether the options entry was found, if not read it from the
|
|
|
|
// content array.
|
|
|
|
if (_attrs["select_options"] == null)
|
|
|
|
{
|
2011-10-19 23:03:22 +02:00
|
|
|
// Again, try last name part at top level
|
|
|
|
var content_options = this.getArrayMgr('content').getRoot().getEntry(name_parts[name_parts.length-1]);
|
|
|
|
// If that didn't work, check according to ID
|
|
|
|
_attrs["select_options"] = content_options ? content_options : this.getArrayMgr('content')
|
2011-09-08 20:36:09 +02:00
|
|
|
.getEntry("options-" + this.id)
|
2011-08-16 19:02:09 +02:00
|
|
|
}
|
|
|
|
|
2011-08-21 10:48:53 +02:00
|
|
|
// Default to an empty object
|
|
|
|
if (_attrs["select_options"] == null)
|
|
|
|
{
|
|
|
|
_attrs["select_options"] = {};
|
|
|
|
}
|
2011-08-16 19:02:09 +02:00
|
|
|
},
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
/**
|
|
|
|
* Add an option to regular drop-down select
|
|
|
|
*/
|
2011-08-31 18:58:44 +02:00
|
|
|
_appendOptionElement: function(_value, _label, _title) {
|
2011-09-09 17:47:38 +02:00
|
|
|
if(_value == "" && (_label == null || _label == "")) {
|
|
|
|
_label = this.options.empty_label;
|
|
|
|
}
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
if(this.input == null)
|
|
|
|
{
|
|
|
|
return this._appendMultiOption(_value, _label, _title);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2012-03-19 20:22:21 +01:00
|
|
|
if(_label == this.options.empty_label || this.options.empty_label == "" && _value == "")
|
|
|
|
{
|
|
|
|
// Make sure empty / all option is first
|
|
|
|
option.prependTo(this.input);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
option.appendTo(this.input);
|
|
|
|
}
|
2011-08-16 22:32:13 +02:00
|
|
|
},
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
/**
|
|
|
|
* Append a value to multi-select
|
|
|
|
*/
|
|
|
|
_appendMultiOption: function(_value, _label, _title) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
var opt_id = this.id + "_opt_" + _value;
|
|
|
|
var label = jQuery(document.createElement("label"))
|
|
|
|
.attr("for", opt_id)
|
|
|
|
.hover(
|
|
|
|
function() {jQuery(this).addClass("ui-state-hover")},
|
|
|
|
function() {jQuery(this).removeClass("ui-state-hover")}
|
|
|
|
);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
label.append(jQuery("<span>"+_label+"</span>"))
|
|
|
|
var li = jQuery(document.createElement("li")).append(label);
|
|
|
|
|
|
|
|
li.appendTo(this.multiOptions);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2011-08-21 10:48:53 +02:00
|
|
|
this._appendOptionElement("" == this.getValue() ? "selected" : "",
|
2011-08-23 02:12:01 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
if(this.options.rows >= 5)
|
|
|
|
{
|
|
|
|
// Check / uncheck all
|
|
|
|
var header_controls = {
|
|
|
|
check: {
|
|
|
|
icon_class: 'ui-icon-check',
|
|
|
|
label: 'Check all',
|
|
|
|
click: function(e) {
|
|
|
|
jQuery("input",e.data).attr("checked", true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
uncheck: {
|
|
|
|
icon_class: 'ui-icon-closethick',
|
|
|
|
label: 'Uncheck all',
|
|
|
|
click: function(e) {
|
|
|
|
jQuery("input",e.data).attr("checked", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(var key in header_controls)
|
|
|
|
{
|
|
|
|
jQuery(document.createElement("li"))
|
|
|
|
.addClass("et2_clickable")
|
|
|
|
.click(options, header_controls[key].click)
|
|
|
|
.append('<span class="ui-icon ' + header_controls[key].icon_class + '"/>')
|
|
|
|
.append("<span>"+this.egw().lang(header_controls[key].label)+"</span>")
|
|
|
|
.appendTo(controls);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (header[0].childNodes.length == 0)
|
|
|
|
{
|
|
|
|
// Hide header - nothing there but padding
|
|
|
|
header.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setDOMNode(node[0]);
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
var legacy;
|
|
|
|
if(legacy = _node.getAttribute("options"))
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2012-05-02 21:45:35 +02:00
|
|
|
this.set_select_options(this.options.select_options);
|
2011-08-31 18:58:44 +02:00
|
|
|
},
|
|
|
|
|
2011-09-26 18:01:42 +02:00
|
|
|
set_value: function(_value) {
|
2012-06-05 23:09:16 +02:00
|
|
|
if(typeof _value == "string" && this.options.multiple && _value.match(/[,0-9]+$/) !== null)
|
2012-03-15 23:57:55 +01:00
|
|
|
{
|
|
|
|
_value = _value.split(',');
|
|
|
|
}
|
|
|
|
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
|
|
|
|
return;
|
|
|
|
}
|
2011-09-26 18:01:42 +02:00
|
|
|
jQuery("option",this.input).attr("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++)
|
|
|
|
{
|
|
|
|
jQuery("option[value='"+_value[i]+"']", this.input).attr("selected", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (typeof _value == "object")
|
|
|
|
{
|
|
|
|
for(var i in _value)
|
|
|
|
{
|
|
|
|
jQuery("option[value='"+_value[i]+"']", this.input).attr("selected", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(jQuery("option[value='"+_value+"']", this.input).attr("selected", true).length == 0)
|
|
|
|
{
|
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);
|
|
|
|
}
|
2012-03-05 14:07:38 +01:00
|
|
|
this.egw().debug("warning", "Tried to set value that isn't an option", this, _value);
|
2011-09-29 21:20:20 +02:00
|
|
|
}
|
2011-09-26 18:01:42 +02:00
|
|
|
}
|
2012-06-05 23:09:16 +02:00
|
|
|
|
2012-05-08 20:02:56 +02:00
|
|
|
this.value = _value;
|
2011-09-26 18:01:42 +02:00
|
|
|
},
|
|
|
|
|
2012-03-15 23:57:55 +01:00
|
|
|
set_multi_value: function(_value) {
|
|
|
|
jQuery("input",this.multiOptions).attr("checked", false);
|
|
|
|
if(typeof _value == "array")
|
|
|
|
{
|
|
|
|
for(var i = 0; i < _value.length; i++)
|
|
|
|
{
|
|
|
|
jQuery("input[value='"+_value[i]+"']", this.multiOptions).attr("checked", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (typeof _value == "object")
|
|
|
|
{
|
|
|
|
for(var i in _value)
|
|
|
|
{
|
|
|
|
jQuery("input[value='"+_value[i]+"']", this.multiOptions).attr("checked", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(jQuery("input[value='"+_value+"']", this.multiOptions).attr("checked", true).length == 0)
|
|
|
|
{
|
|
|
|
this.egw().debug("warning", "Tried to set value that isn't an option", this, _value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort selected to the top
|
|
|
|
if(this.selected_first)
|
|
|
|
{
|
|
|
|
this.multiOptions.find("li:has(input:checked)").prependTo(this.multiOptions);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
// Re-add empty, it's usually not there
|
2012-05-02 21:45:35 +02:00
|
|
|
if(this.options.empty_label)
|
2012-04-30 19:00:50 +02:00
|
|
|
{
|
2012-06-13 17:15:31 +02:00
|
|
|
this._appendOptionElement('', this.options.no_lang ? this.options.empty_label : 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)
|
|
|
|
{
|
2012-03-06 14:22:01 +01:00
|
|
|
if (typeof _options[key] === 'object')
|
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
|
|
|
|
2012-03-06 14:22:01 +01:00
|
|
|
if (typeof _options[key] === 'object')
|
2011-08-22 10:58:20 +02:00
|
|
|
{
|
2012-03-15 23:57:55 +01:00
|
|
|
if(this.input == null)
|
|
|
|
{
|
|
|
|
// Allow some special extras for objects by passing the whole thing
|
|
|
|
_options[key]["label"] = _options[key]["label"] ? _options[key]["label"] : "";
|
|
|
|
this._appendMultiOption(key, _options[key], _options[key]["title"]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._appendOptionElement(key,
|
|
|
|
_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
|
|
|
}
|
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);});
|
2012-07-11 00:20:13 +02:00
|
|
|
this.value = value;
|
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;
|
2011-08-16 19:02:09 +02:00
|
|
|
}
|
2011-08-21 10:48:53 +02:00
|
|
|
});
|
2011-08-20 20:34:14 +02:00
|
|
|
|
2011-09-26 18:01:42 +02:00
|
|
|
et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select", "select-cat",
|
2012-06-06 06:06:48 +02:00
|
|
|
"select-percent", 'select-priority', 'select-access',
|
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
|
|
|
|
2011-08-23 02:12:01 +02:00
|
|
|
/**
|
|
|
|
* et2_selectbox_ro is the readonly implementation of the selectbox.
|
|
|
|
*/
|
2011-10-19 23:03:22 +02:00
|
|
|
var et2_selectbox_ro = et2_selectbox.extend([et2_IDetachedDOM], {
|
2011-08-23 02:12:01 +02:00
|
|
|
|
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)] =
|
|
|
|
{
|
|
|
|
"label": options[i].textContent,
|
|
|
|
"title": et2_readAttrWithDefault(options[i], "title", "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
this.optionValues[key] = _options[key];
|
|
|
|
}
|
2011-08-23 02:12:01 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
set_value: function(_value) {
|
2012-05-01 01:29:31 +02:00
|
|
|
if(typeof _value == "string" && _value.match(/[,0-9]+$/) !== null && this.options.multiple)
|
|
|
|
{
|
|
|
|
_value = _value.split(',');
|
|
|
|
}
|
2011-08-23 02:12:01 +02:00
|
|
|
this.value = _value;
|
2012-05-01 01:29:31 +02:00
|
|
|
if(typeof _value == "object")
|
|
|
|
{
|
|
|
|
this.span.empty();
|
2012-05-03 00:12:42 +02:00
|
|
|
if(_value)
|
|
|
|
{
|
|
|
|
for(var i = 0; i < _value.length; i++)
|
2012-05-01 01:29:31 +02:00
|
|
|
{
|
2012-05-03 00:12:42 +02:00
|
|
|
var option = this.optionValues[_value[i]];
|
|
|
|
if(typeof option === "object")
|
|
|
|
{
|
|
|
|
option = option.label;
|
|
|
|
}
|
|
|
|
this.span.append("<li>"+option+"</li>");
|
2012-05-01 01:29:31 +02:00
|
|
|
}
|
2012-05-03 00:12:42 +02:00
|
|
|
}
|
2012-05-01 01:29:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-08-23 11:45:45 +02:00
|
|
|
var option = this.optionValues[_value];
|
2012-05-24 01:54:30 +02:00
|
|
|
if (typeof option === 'object' && option != null)
|
2011-08-23 11:45:45 +02:00
|
|
|
{
|
|
|
|
this.span.text(option.label);
|
|
|
|
this.set_statustext(option.title);
|
|
|
|
}
|
2012-03-06 14:22:01 +01:00
|
|
|
else if (typeof option === 'string')
|
2011-08-23 11:45:45 +02:00
|
|
|
{
|
|
|
|
this.span.text(option);
|
|
|
|
}
|
2011-10-18 16:13:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this.span.text("");
|
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
var et2_menulist = et2_DOMWidget.extend({
|
|
|
|
|
|
|
|
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"]);
|
|
|
|
|
2011-08-16 19:02:09 +02:00
|
|
|
|