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-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: {
|
|
|
|
"multiselect": {
|
|
|
|
"name": "multiselect",
|
|
|
|
"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"],
|
|
|
|
|
|
|
|
init: function(_parent) {
|
|
|
|
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-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-21 17:22:00 +02:00
|
|
|
transformAttributes: function(_attrs) {
|
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" : "",
|
|
|
|
this.empty_label);
|
2011-08-16 19:02:09 +02:00
|
|
|
}
|
2011-08-20 20:34:14 +02:00
|
|
|
|
2011-08-21 10:48:53 +02:00
|
|
|
// Set multiselect
|
|
|
|
if(this.options.multiselect)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
// Add the select_options
|
|
|
|
for (var key in _options)
|
|
|
|
{
|
|
|
|
this._appendOptionElement(key, _options[key]);
|
|
|
|
}
|
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",
|
|
|
|
"select-account"]);
|
2011-08-20 20:34:14 +02:00
|
|
|
|
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."
|
|
|
|
},
|
|
|
|
"width": {
|
|
|
|
"ignore": true
|
|
|
|
},
|
|
|
|
"height": {
|
|
|
|
"ignore": true
|
|
|
|
},
|
|
|
|
"align": {
|
|
|
|
"ignore": true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Allow no other widgets inside of this one.
|
|
|
|
this.supportedWidgetClasses = [];
|
|
|
|
|
|
|
|
this.option = $j(document.createElement("option"))
|
|
|
|
.attr("value", this.options.value);
|
|
|
|
|
|
|
|
this.setDOMNode(this.option[0]);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.option = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadContent: function(_data) {
|
|
|
|
this.option.text(_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
this.supportedWidgetClasses = [et2_selectbox];
|
|
|
|
},
|
|
|
|
|
|
|
|
// 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
|
|
|
|