mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-26 15:59:07 +01:00
Adapted selectbox widget code to new etemplate2 js core scheme
This commit is contained in:
parent
7c7a8230cf
commit
127e629eef
@ -6,6 +6,7 @@
|
|||||||
* @subpackage api
|
* @subpackage api
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Nathan Gray
|
* @author Nathan Gray
|
||||||
|
* @author Andreas Stöckel
|
||||||
* @copyright Nathan Gray 2011
|
* @copyright Nathan Gray 2011
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
@ -37,6 +38,9 @@ var et2_selectbox = et2_inputWidget.extend({
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
"description": "Textual label for first row, eg: 'All' or 'None'. ID will be ''"
|
"description": "Textual label for first row, eg: 'All' or 'None'. ID will be ''"
|
||||||
|
},
|
||||||
|
"select_options": {
|
||||||
|
"ignore": true // Just include "select_options" here to have it copied from the parseArrayMgrAttrs to the options-object
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -45,100 +49,73 @@ var et2_selectbox = et2_inputWidget.extend({
|
|||||||
init: function(_parent) {
|
init: function(_parent) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
this.input = null;
|
|
||||||
this.id = "";
|
|
||||||
|
|
||||||
this.createInputWidget();
|
this.createInputWidget();
|
||||||
},
|
},
|
||||||
|
|
||||||
createInputWidget: function() {
|
parseArrayMgrAttrs: function(_attrs) {
|
||||||
if(this.type == "menupopup") {
|
// Try to find the options inside the "sel-options" array
|
||||||
return;
|
_attrs["select_options"] = this.getArrayMgr("sel_options").getValueForID(this.id);
|
||||||
} else {
|
|
||||||
this.input = $j(document.createElement("select"));
|
|
||||||
|
|
||||||
this.input.addClass("et2_selectbox");
|
// 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]);
|
this.setDOMNode(this.input[0]);
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
// Add the empty label
|
||||||
* Override parent to get the select options.
|
if(this.options.empty_label)
|
||||||
* Can't get them before this, because the ID is not set when createInputWidget() is called.
|
{
|
||||||
*/
|
this._appendOptionElement("" == this.getValue() ? "selected" : "",
|
||||||
set_id: function() {
|
this.empty_label);
|
||||||
this._super.apply(this,arguments);
|
}
|
||||||
|
|
||||||
// Get select options from the manager(s)
|
// Add the select_options
|
||||||
var options = null;
|
for(var key in this.options.select_options)
|
||||||
|
{
|
||||||
// Check the sel_options (from managers)
|
this._appendOptionElement(key, this.options.select_options[key]);
|
||||||
this.set_select_options(null);
|
}
|
||||||
},
|
|
||||||
|
// Set multiselect
|
||||||
set_select_options: function(_options) {
|
if(this.options.multiselect)
|
||||||
if(_options == null) {
|
|
||||||
var mgr = this.getArrayMgr('sel_options');
|
|
||||||
if(mgr) {
|
|
||||||
_options = mgr.getValueForID(this.id);
|
|
||||||
}
|
|
||||||
if(_options == null) {
|
|
||||||
// Check in the content
|
|
||||||
var mgr = this.getArrayMgr('content');
|
|
||||||
if(mgr) {
|
|
||||||
_options = mgr.getValueForID('options-'+this.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.input.children().remove();
|
|
||||||
if(this.empty_label) {
|
|
||||||
this.input.append("<option value=''" + ("" == this.getValue() ? "selected":"") +">"+this.empty_label+"</option>");
|
|
||||||
}
|
|
||||||
if(_options == null) return;
|
|
||||||
for(var key in _options) {
|
|
||||||
this.input.append("<option value='"+key+"'" + (key == this.getValue() ? "selected":"") +">"+_options[key]+"</option>");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
set_multiselect: function(_value) {
|
|
||||||
if (_value != this.multiselect)
|
|
||||||
{
|
{
|
||||||
this.multiselect = _value;
|
|
||||||
if(this.multiselect) {
|
|
||||||
this.input.attr("multiple", "multiple");
|
this.input.attr("multiple", "multiple");
|
||||||
} else {
|
|
||||||
this.input.removeAttr("multiple");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
set_rows: function(_rows) {
|
|
||||||
if (_rows != this.rows)
|
|
||||||
{
|
|
||||||
this.rows = _rows;
|
|
||||||
this.input.attr("size",this.rows);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
set_empty_label: function(_label) {
|
|
||||||
if(_label != this.empty_label) {
|
|
||||||
this.empty_label = _label;
|
|
||||||
this.set_select_options(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select-cat", "select-account"]);
|
et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select-cat",
|
||||||
|
"select-account"]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which just implements the menulist container
|
* Class which just implements the menulist container
|
||||||
*/
|
*/
|
||||||
var et2_menulist = et2_DOMWidget.extend({
|
var et2_menulist = et2_DOMWidget.extend({
|
||||||
|
|
||||||
createNamespace: true,
|
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user