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
|
2011-08-21 15:24:20 +02:00
|
|
|
lib/tooltip;
|
2011-08-16 19:02:09 +02:00
|
|
|
jquery.jquery;
|
2011-08-23 11:45:45 +02:00
|
|
|
et2_xml;
|
2011-08-21 15:24:20 +02:00
|
|
|
et2_DOMWidget;
|
2011-08-16 19:02:09 +02:00
|
|
|
et2_inputWidget;
|
|
|
|
*/
|
|
|
|
|
|
|
|
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."
|
2011-08-16 19:02:09 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
legacyOptions: ["rows"],
|
|
|
|
|
2011-08-23 02:12:01 +02:00
|
|
|
init: function(_parent, _attrs) {
|
2011-08-16 19:02:09 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
// Only allow options inside this element
|
|
|
|
this.supportedWidgetClasses = [et2_option];
|
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
|
|
|
|
if(typeof _attrs.rows == "string" && isNaN(_attrs.rows)) {
|
|
|
|
this.options.empty_label = _attrs.rows;
|
|
|
|
this.options.rows = 1;
|
|
|
|
}
|
|
|
|
if(this.options.rows > 1) this.options.multiple = true;
|
2011-08-16 19:02:09 +02:00
|
|
|
this.createInputWidget();
|
|
|
|
},
|
|
|
|
|
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-08-21 10:48:53 +02:00
|
|
|
// Try to find the options inside the "sel-options" array
|
|
|
|
_attrs["select_options"] = this.getArrayMgr("sel_options").getValueForID(this.id);
|
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)
|
|
|
|
{
|
|
|
|
_attrs["select_options"] = this.getArrayMgr('content')
|
|
|
|
.getValueForID("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
|
|
|
},
|
|
|
|
|
2011-08-21 10:48:53 +02:00
|
|
|
_appendOptionElement: function(_value, _label) {
|
|
|
|
$j(document.createElement("option"))
|
|
|
|
.attr("value", _value)
|
|
|
|
.text(_label)
|
|
|
|
.appendTo(this.input);
|
2011-08-16 22:32:13 +02:00
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The set_select_optons function is added, as the select options have to be
|
|
|
|
* added after the "option"-widgets were added to selectbox.
|
|
|
|
*/
|
|
|
|
set_select_options: function(_options) {
|
2011-08-22 10:58:20 +02:00
|
|
|
|
|
|
|
var root = this;
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
// Add the select_options
|
|
|
|
for (var key in _options)
|
|
|
|
{
|
2011-08-22 10:58:20 +02:00
|
|
|
var attrs = {
|
|
|
|
"value": key
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_options[key] instanceof Object)
|
|
|
|
{
|
|
|
|
attrs["label"] = _options[key]["label"] ? _options[key]["label"] : "";
|
|
|
|
attrs["statustext"] = _options[key]["title"] ? _options[key]["title"] : "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attrs["label"] = _options[key]
|
|
|
|
}
|
|
|
|
|
2011-08-23 11:45:45 +02:00
|
|
|
// Create the widget and add it as a child
|
|
|
|
this.addChild(et2_createWidget("option", attrs));
|
2011-08-21 15:24:20 +02:00
|
|
|
}
|
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-08-21 10:48:53 +02:00
|
|
|
et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select-cat",
|
2011-08-22 18:56:45 +02:00
|
|
|
"select-account", "select-percent", 'select-priority', 'select-access',
|
|
|
|
'select-country', 'select-state', 'select-year', 'select-month',
|
2011-08-22 20:18:29 +02:00
|
|
|
'select-day', 'select-dow', 'select-hour', 'date-houronly', '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.
|
|
|
|
*/
|
|
|
|
var et2_selectbox_ro = et2_selectbox.extend({
|
|
|
|
|
|
|
|
init: function(_parent, _attrs) {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.supportedWidgetClasses = [];
|
2011-08-23 11:45:45 +02:00
|
|
|
this.optionValues = {};
|
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
|
|
|
|
|
|
|
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) {
|
|
|
|
this.value = _value;
|
2011-08-23 11:45:45 +02:00
|
|
|
|
|
|
|
var option = this.optionValues[_value];
|
|
|
|
if (option instanceof Object)
|
|
|
|
{
|
|
|
|
this.span.text(option.label);
|
|
|
|
this.set_statustext(option.title);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.span.text(option);
|
|
|
|
}
|
2011-08-23 02:12:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_selectbox_ro, ["menupopup_ro", "listbox_ro", "select-cat_ro",
|
|
|
|
"select-account_ro", "select-percent_ro", 'select-priority_ro', 'select-access_ro',
|
|
|
|
'select-country_ro', 'select-state_ro', 'select-year_ro', 'select-month_ro',
|
|
|
|
'select-day_ro', 'select-dow_ro', 'select-hour_ro', 'date-houronly_ro', 'select-number_ro', 'select-app_ro',
|
|
|
|
'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
|
|
|
|
*/
|
|
|
|
var et2_option = et2_baseWidget.extend({
|
|
|
|
|
|
|
|
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"))
|
|
|
|
.attr("value", this.options.value);
|
|
|
|
|
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-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
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_option, ["option"]);
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_menulist, ["menulist"]);
|
|
|
|
|
2011-08-16 19:02:09 +02:00
|
|
|
|