forked from extern/egroupware
209 lines
4.3 KiB
JavaScript
209 lines
4.3 KiB
JavaScript
/**
|
|
* 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
|
|
* @author Andreas Stöckel
|
|
* @copyright Nathan Gray 2011
|
|
* @version $Id$
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
/*egw:uses
|
|
lib/tooltip;
|
|
jquery.jquery;
|
|
et2_DOMWidget;
|
|
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 ''"
|
|
},
|
|
"select_options": {
|
|
"type": "any",
|
|
"name": "Select options",
|
|
"default": {},
|
|
"description": "Internaly used to hold the select options."
|
|
}
|
|
},
|
|
|
|
legacyOptions: ["rows"],
|
|
|
|
init: function(_parent) {
|
|
this._super.apply(this, arguments);
|
|
|
|
// Only allow options inside this element
|
|
this.supportedWidgetClasses = [et2_option];
|
|
|
|
this.createInputWidget();
|
|
},
|
|
|
|
destroy: function() {
|
|
this._super.apply(this, arguments);
|
|
|
|
this.input = null;
|
|
},
|
|
|
|
parseArrayMgrAttrs: function(_attrs) {
|
|
// Try to find the options inside the "sel-options" array
|
|
_attrs["select_options"] = this.getArrayMgr("sel_options").getValueForID(this.id);
|
|
|
|
// 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)
|
|
}
|
|
|
|
// Default to an empty object
|
|
if (_attrs["select_options"] == null)
|
|
{
|
|
_attrs["select_options"] = {};
|
|
}
|
|
},
|
|
|
|
_appendOptionElement: function(_value, _label) {
|
|
$j(document.createElement("option"))
|
|
.attr("value", _value)
|
|
.text(_label)
|
|
.appendTo(this.input);
|
|
},
|
|
|
|
createInputWidget: function() {
|
|
// Create the base input widget
|
|
this.input = $j(document.createElement("select"))
|
|
.addClass("et2_selectbox")
|
|
.attr("size", this.options.rows);
|
|
|
|
this.setDOMNode(this.input[0]);
|
|
|
|
// Add the empty label
|
|
if(this.options.empty_label)
|
|
{
|
|
this._appendOptionElement("" == this.getValue() ? "selected" : "",
|
|
this.empty_label);
|
|
}
|
|
|
|
// Set multiselect
|
|
if(this.options.multiselect)
|
|
{
|
|
this.input.attr("multiple", "multiple");
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 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]);
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select-cat",
|
|
"select-account"]);
|
|
|
|
/**
|
|
* 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"]);
|
|
|
|
|
|
/**
|
|
* 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) {
|
|
if (_sender != this._parent && _sender != this)
|
|
{
|
|
return this._parent.getDOMNode(this);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
});
|
|
|
|
et2_register_widget(et2_menulist, ["menulist"]);
|
|
|
|
|