2012-03-14 20:02:28 +01:00
|
|
|
/**
|
2012-03-15 09:29:45 +01:00
|
|
|
* EGroupware eTemplate2 - JS Select account widget
|
2014-03-18 14:22:15 +01:00
|
|
|
*
|
2012-03-14 20:02:28 +01:00
|
|
|
* Selecting accounts needs special UI, and displaying needs special consideration
|
|
|
|
* to avoid sending the entire user list to the client.
|
|
|
|
*
|
|
|
|
* @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
|
2012-03-15 09:29:45 +01:00
|
|
|
* @copyright Nathan Gray 2012
|
2012-03-14 20:02:28 +01:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
2012-03-15 09:29:45 +01:00
|
|
|
et2_widget_link;
|
2012-03-14 20:02:28 +01:00
|
|
|
*/
|
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
/**
|
|
|
|
* Account selection widget
|
|
|
|
* Changes according to the user's account_selection preference
|
|
|
|
* - 'none' => Server-side: the read-only widget is used
|
|
|
|
* - 'groupmembers' => Non admins can only select groupmembers (Server side - normal selectbox)
|
|
|
|
* - 'selectbox' => Selectbox with all accounts and groups (Server side - normal selectbox)
|
|
|
|
* - 'primary_group' => Selectbox with primary group and search
|
2012-06-19 01:28:51 +02:00
|
|
|
* - 'popup' => No selectbox, just search. No popup, the search replaces the selectbox
|
2012-05-30 00:47:21 +02:00
|
|
|
*
|
|
|
|
* Only primary_group and popup need anything different from a normal selectbox
|
2014-03-18 14:22:15 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_selectbox
|
2012-05-30 00:47:21 +02:00
|
|
|
*/
|
2013-04-13 21:00:13 +02:00
|
|
|
var et2_selectAccount = et2_selectbox.extend(
|
|
|
|
{
|
2012-05-30 00:47:21 +02:00
|
|
|
attributes: {
|
|
|
|
'account_type': {
|
|
|
|
'name': 'Account type',
|
|
|
|
'default': 'accounts',
|
|
|
|
'type': 'string',
|
|
|
|
'description': 'Limit type of accounts. One of {accounts,groups,both,owngroups}.'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
legacyOptions: ['empty_label','account_type'],
|
|
|
|
|
|
|
|
account_types: ['accounts','groups','both','owngroups'],
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-03-18 14:22:15 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @param _parent
|
|
|
|
* @param _attrs
|
|
|
|
* @memberOf et2_selectAccount
|
|
|
|
* @returns
|
|
|
|
*/
|
2012-05-30 00:47:21 +02:00
|
|
|
init: function(_parent, _attrs) {
|
|
|
|
|
|
|
|
// Type in rows or somewhere else?
|
|
|
|
if(jQuery.inArray(_attrs['empty_label'], this.account_types) > 0 && (
|
2014-03-18 14:22:15 +01:00
|
|
|
jQuery.inArray(_attrs['account_type'], this.account_types) < 0 ||
|
2013-04-13 21:00:13 +02:00
|
|
|
_attrs['account_type'] == this.attributes.account_type['default'])
|
2012-05-30 00:47:21 +02:00
|
|
|
)
|
|
|
|
{
|
2013-04-13 21:00:13 +02:00
|
|
|
_attrs['account_type'] = _attrs['empty_label'];
|
2012-05-30 00:47:21 +02:00
|
|
|
_attrs['empty_label'] = '';
|
|
|
|
}
|
|
|
|
if(jQuery.inArray(_attrs['account_type'], this.account_types) < 0)
|
|
|
|
{
|
|
|
|
this.egw().debug("warn", "Invalid account_type: %s Valid options:",_attrs['account_type'], this.account_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Holder for search jQuery nodes
|
|
|
|
this.search = null;
|
|
|
|
|
|
|
|
// Reference to object with dialog
|
|
|
|
this.dialog = null;
|
2013-06-06 00:45:19 +02:00
|
|
|
|
2013-10-10 12:23:37 +02:00
|
|
|
this._super.call(this, _parent, _attrs);
|
2013-11-18 19:47:25 +01:00
|
|
|
|
|
|
|
// Allow certain widgets inside this one
|
|
|
|
this.supportedWidgetClasses = [et2_link_entry];
|
2012-05-30 00:47:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2013-10-10 12:23:37 +02:00
|
|
|
this._super.apply(this, arguments);
|
2012-05-30 00:47:21 +02:00
|
|
|
},
|
|
|
|
|
2013-06-06 00:45:19 +02:00
|
|
|
/**
|
|
|
|
* Tell et2 widget framework where to go
|
2014-05-14 12:00:31 +02:00
|
|
|
*
|
|
|
|
* @param {object} _sender
|
2013-06-06 00:45:19 +02:00
|
|
|
*/
|
|
|
|
getDOMNode: function(_sender) {
|
2013-06-11 00:07:31 +02:00
|
|
|
if(this.search_widget != null && _sender == this.search_widget)
|
2013-06-06 00:45:19 +02:00
|
|
|
{
|
|
|
|
return this.search != null ? this.search[0] : this.search_widget._parent.getDOMNode();
|
|
|
|
}
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
/**
|
|
|
|
* Single selection - override to add search button
|
|
|
|
*/
|
2014-03-18 14:22:15 +01:00
|
|
|
createInputWidget: function()
|
2013-10-10 12:23:37 +02:00
|
|
|
{
|
2012-05-30 00:47:21 +02:00
|
|
|
var type = this.egw().preference('account_selection', 'common');
|
2012-06-19 01:28:51 +02:00
|
|
|
|
2014-04-23 21:00:59 +02:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case 'none':
|
|
|
|
case 'selectbox':
|
|
|
|
case 'groupmembers':
|
|
|
|
default:
|
2014-05-13 20:40:31 +02:00
|
|
|
this.options.select_options = this._get_accounts();
|
2014-04-23 21:00:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._super.apply(this, arguments);
|
2014-05-07 17:51:45 +02:00
|
|
|
|
2012-06-19 01:28:51 +02:00
|
|
|
// Add search button
|
|
|
|
if(type == 'primary_group')
|
2012-05-30 00:47:21 +02:00
|
|
|
{
|
|
|
|
var button = jQuery(document.createElement("span"))
|
|
|
|
.addClass("et2_clickable")
|
2014-03-24 21:20:25 +01:00
|
|
|
.click(this, this.options.multiple ? this._open_multi_search : this._open_search)
|
2013-08-19 22:21:56 +02:00
|
|
|
.attr("title", egw.lang("popup with search"))
|
2013-04-13 21:00:13 +02:00
|
|
|
.append('<span class="ui-icon ui-icon-search" style="display:inline-block"/>');
|
2012-05-30 00:47:21 +02:00
|
|
|
|
|
|
|
this.getSurroundings().insertDOMNode(button[0]);
|
|
|
|
}
|
2012-06-19 01:28:51 +02:00
|
|
|
else if (type == 'popup')
|
|
|
|
{
|
2013-02-08 11:38:09 +01:00
|
|
|
// Allow search 'inside' this widget
|
|
|
|
this.supportedWidgetClasses = [et2_link_entry];
|
|
|
|
|
2012-06-19 01:28:51 +02:00
|
|
|
this._create_search();
|
|
|
|
// Use empty label as blur
|
|
|
|
if(this.options.empty_label) this.search_widget.set_blur(this.options.empty_label);
|
|
|
|
|
|
|
|
// Rework to go around / through the selectbox
|
|
|
|
if(this.input)
|
|
|
|
{
|
|
|
|
this.getValue = function() {return this.value;};
|
|
|
|
this.set_value = function(_value) {
|
|
|
|
this.value = _value;
|
|
|
|
this.search_widget.set_value(_value);
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2012-06-19 01:28:51 +02:00
|
|
|
this.search_widget.search.change(this, function(event) {
|
|
|
|
var value = event.data.search_widget.getValue();
|
2013-02-08 11:38:09 +01:00
|
|
|
event.data.value = typeof value == 'object' && value ? value.id : value;
|
2012-06-19 01:28:51 +02:00
|
|
|
event.data.input.trigger("change");
|
|
|
|
});
|
|
|
|
}
|
2013-02-08 11:38:09 +01:00
|
|
|
var div = jQuery(document.createElement("div")).append(this.search_widget.getDOMNode());
|
|
|
|
this.setDOMNode(div[0]);
|
2012-06-19 01:28:51 +02:00
|
|
|
}
|
2012-05-30 00:47:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiple selection - override to add search button
|
|
|
|
*/
|
|
|
|
createMultiSelect: function() {
|
2012-06-19 01:28:51 +02:00
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
var type = this.egw().preference('account_selection', 'common');
|
2014-05-13 20:40:31 +02:00
|
|
|
|
2014-05-13 20:44:59 +02:00
|
|
|
this.options.select_options = this._get_accounts();
|
2014-05-13 20:40:31 +02:00
|
|
|
|
2012-06-19 01:28:51 +02:00
|
|
|
if(type == 'primary_group')
|
|
|
|
{
|
2013-06-06 00:45:19 +02:00
|
|
|
// Allow search 'inside' this widget
|
|
|
|
this.supportedWidgetClasses = [et2_link_entry];
|
|
|
|
|
|
|
|
// Add quick search - turn off multiple to get normal result list
|
|
|
|
this.options.multiple = false;
|
|
|
|
this._create_search();
|
|
|
|
|
|
|
|
// Clear search box after select
|
|
|
|
var old_select = this.search_widget.select;
|
2013-06-10 18:53:41 +02:00
|
|
|
var self = this;
|
|
|
|
this.search_widget.select = function(e, selected) {
|
|
|
|
var current = self.getValue();
|
2014-01-20 14:45:33 +01:00
|
|
|
|
|
|
|
// Fix ID as sent from server - must be numeric
|
|
|
|
selected.item.value = parseInt(selected.item.value);
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2013-06-10 18:53:41 +02:00
|
|
|
// This one is important, it makes sure the option is there
|
2013-06-06 00:45:19 +02:00
|
|
|
old_select.apply(this, arguments);
|
2013-06-10 18:53:41 +02:00
|
|
|
|
|
|
|
// Add quick search selection into current selection
|
|
|
|
current.push(selected.item.value);
|
|
|
|
|
|
|
|
// Clear search
|
2013-06-06 00:45:19 +02:00
|
|
|
this.search.val('');
|
2013-06-10 18:53:41 +02:00
|
|
|
|
|
|
|
self.set_value(current);
|
2013-06-06 00:45:19 +02:00
|
|
|
};
|
2012-06-19 01:28:51 +02:00
|
|
|
|
2013-06-06 00:45:19 +02:00
|
|
|
// Put search results as a DOM sibling of the options, for proper display
|
|
|
|
this.search_widget.search.on("autocompleteopen", jQuery.proxy(function() {
|
2013-08-21 01:08:35 +02:00
|
|
|
this.search_widget.search.data("ui-autocomplete").menu.element
|
|
|
|
.appendTo(this.node)
|
2014-05-14 12:00:31 +02:00
|
|
|
.position({my: 'left top', at: 'left bottom', of: this.multiOptions.prev()});
|
2013-06-06 00:45:19 +02:00
|
|
|
},this));
|
|
|
|
this.search = jQuery(document.createElement("li"))
|
|
|
|
.appendTo(this.multiOptions.prev().find('ul'));
|
|
|
|
this.options.multiple = true;
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2012-06-19 01:28:51 +02:00
|
|
|
// Add search button
|
|
|
|
var button = jQuery(document.createElement("li"))
|
|
|
|
.addClass("et2_clickable")
|
|
|
|
.click(this, this._open_multi_search)
|
2013-08-19 22:21:56 +02:00
|
|
|
.attr("title", egw.lang("popup with search"))
|
2014-05-14 12:00:31 +02:00
|
|
|
.append('<span class="ui-icon ui-icon-search"/>');
|
2012-06-19 01:28:51 +02:00
|
|
|
var type = this.egw().preference('account_selection', 'common');
|
|
|
|
|
2013-06-06 00:45:19 +02:00
|
|
|
// Put it last so check/uncheck doesn't move around
|
|
|
|
this.multiOptions.prev().find('ul')
|
|
|
|
.append(button);
|
2012-06-19 01:28:51 +02:00
|
|
|
}
|
|
|
|
else if (type == 'popup')
|
|
|
|
{
|
2013-02-08 11:38:09 +01:00
|
|
|
// Allow search 'inside' this widget
|
|
|
|
this.supportedWidgetClasses = [et2_link_entry];
|
|
|
|
|
2012-06-19 01:28:51 +02:00
|
|
|
/**
|
|
|
|
* Popup takes the dialog and embeds it in place of the selectbox
|
|
|
|
*/
|
|
|
|
var dialog = this._open_multi_search();
|
|
|
|
dialog.dialog("close");
|
2013-02-08 11:38:09 +01:00
|
|
|
var div = jQuery(document.createElement("div")).append(this.dialog);
|
|
|
|
this.setDOMNode(div[0]);
|
2012-06-19 01:28:51 +02:00
|
|
|
|
|
|
|
var select_col = jQuery('#selection_col',dialog).children();
|
2013-09-30 18:54:25 +02:00
|
|
|
var selected = jQuery('#'+this.getInstanceManager().uniqueId + "_selected", select_col);
|
2012-06-19 01:28:51 +02:00
|
|
|
|
|
|
|
// Re-do to get it to work around/through the select box
|
|
|
|
this.set_value = function(_value) {
|
|
|
|
selected.empty();
|
|
|
|
if(typeof _value == 'string')
|
|
|
|
{
|
|
|
|
_value = _value.split(',');
|
|
|
|
}
|
|
|
|
if(typeof _value == 'object')
|
|
|
|
{
|
|
|
|
for(var key in _value)
|
|
|
|
{
|
|
|
|
this._add_selected(selected, _value[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var widget = this;
|
|
|
|
this.getValue = function() {
|
|
|
|
// Update widget with selected
|
|
|
|
var ids = [];
|
|
|
|
var data = {};
|
2013-09-30 18:54:25 +02:00
|
|
|
jQuery('#'+this.getInstanceManager().uniqueId + '_selected li',select_col).each(function() {
|
|
|
|
var id = $j(this).attr("data-id");
|
|
|
|
// Add to list
|
|
|
|
ids.push(id);
|
2012-06-19 01:28:51 +02:00
|
|
|
|
|
|
|
// Make sure option is there
|
2013-09-30 18:54:25 +02:00
|
|
|
if(jQuery('input[data-id="'+id+'"]',widget.multiOptions).length == 0)
|
2012-06-19 01:28:51 +02:00
|
|
|
{
|
2013-09-30 18:54:25 +02:00
|
|
|
widget._appendMultiOption(id,jQuery('label',this).text());
|
2012-06-19 01:28:51 +02:00
|
|
|
}
|
|
|
|
});
|
2012-05-30 00:47:21 +02:00
|
|
|
|
2012-06-19 01:28:51 +02:00
|
|
|
this.set_multi_value(ids);
|
|
|
|
return ids;
|
|
|
|
};
|
|
|
|
}
|
2012-05-30 00:47:21 +02:00
|
|
|
},
|
|
|
|
|
2014-05-13 20:40:31 +02:00
|
|
|
/**
|
|
|
|
* Override parent to make sure accounts are there as options.
|
|
|
|
*
|
|
|
|
* Depending on the widget's attributes and the user's preferences, not all selected
|
|
|
|
* accounts may be in the cache as options, so we fetch the extras to make sure
|
|
|
|
* we don't lose any.
|
2014-05-14 12:00:31 +02:00
|
|
|
*
|
|
|
|
* As fetching them might only work asynchron (if they are not yet loaded),
|
|
|
|
* we have to call set_value again, once all labels have arrived from server.
|
|
|
|
*
|
|
|
|
* @param {string|array} _value
|
2014-05-13 20:40:31 +02:00
|
|
|
*/
|
|
|
|
set_value: function(_value)
|
|
|
|
{
|
2014-07-13 11:14:58 +02:00
|
|
|
if(typeof _value == "string" && this.options.multiple && _value.match(this._is_multiple_regexp) !== null)
|
2014-05-13 20:40:31 +02:00
|
|
|
{
|
|
|
|
_value = _value.split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_value)
|
|
|
|
{
|
|
|
|
var search = _value;
|
|
|
|
if (!jQuery.isArray(search))
|
|
|
|
{
|
|
|
|
search = [_value];
|
|
|
|
}
|
|
|
|
var update_options = false;
|
2014-05-14 12:00:31 +02:00
|
|
|
var num_calls = 0;
|
|
|
|
var current_call = 0;
|
2014-05-13 20:40:31 +02:00
|
|
|
for(var j = 0; j < search.length; j++)
|
|
|
|
{
|
2014-05-14 12:00:31 +02:00
|
|
|
var found = false;
|
2014-05-27 17:33:26 +02:00
|
|
|
|
|
|
|
// Not having a value to look up causes an infinite loop
|
|
|
|
if(!search[j]) continue;
|
2014-07-13 11:14:58 +02:00
|
|
|
|
2014-05-13 20:40:31 +02:00
|
|
|
// Options are not indexed, so we must look
|
2014-05-14 12:00:31 +02:00
|
|
|
for(var i = 0; !found && i < this.options.select_options.length; i++)
|
2014-05-13 20:40:31 +02:00
|
|
|
{
|
2014-05-14 12:00:31 +02:00
|
|
|
if(this.options.select_options[i].value == search[j]) found = true;
|
2014-05-13 20:40:31 +02:00
|
|
|
}
|
2014-05-14 12:00:31 +02:00
|
|
|
if(!found)
|
2014-05-13 20:40:31 +02:00
|
|
|
{
|
|
|
|
// Add it in
|
2014-05-14 12:00:31 +02:00
|
|
|
var name = this.egw().link_title('home-accounts', search[j]);
|
|
|
|
if (name) // was already cached on client-side
|
|
|
|
{
|
|
|
|
update_options = true;
|
|
|
|
this.options.select_options.push({value: search[j], label:name});
|
|
|
|
}
|
|
|
|
else // not available: need to call set_value again, after all arrived from server
|
|
|
|
{
|
|
|
|
++num_calls;
|
|
|
|
this.egw().link_title('home-accounts', search[j], function(name)
|
|
|
|
{
|
|
|
|
if (++current_call >= num_calls) // only run last callback
|
|
|
|
{
|
|
|
|
this.set_value(_value);
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
2014-05-13 20:40:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(update_options)
|
|
|
|
{
|
|
|
|
this.set_select_options(this.options.select_options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get account info for select options from common client-side account cache
|
|
|
|
*
|
|
|
|
* @return {Array} select options
|
|
|
|
*/
|
|
|
|
_get_accounts: function()
|
|
|
|
{
|
|
|
|
if (!jQuery.isArray(this.options.select_options))
|
|
|
|
{
|
|
|
|
var options = jQuery.extend({}, this.options.select_options);
|
|
|
|
this.options.select_options = [];
|
|
|
|
for(var key in options)
|
|
|
|
{
|
|
|
|
if (typeof options[key] == 'object')
|
|
|
|
{
|
|
|
|
if (typeof(options[key].key) == 'undefined')
|
|
|
|
{
|
|
|
|
options[key].value = key;
|
|
|
|
}
|
|
|
|
this.options.select_options.push(options[key]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-09 10:36:34 +02:00
|
|
|
this.options.select_options.push({value: key, label: options[key]});
|
2014-05-13 20:40:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.options.select_options.concat(this.egw().accounts(this.options.account_type));
|
|
|
|
},
|
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
/**
|
|
|
|
* Create & display a way to search & select a single account / group
|
|
|
|
* Single selection is just link widget
|
2014-05-14 12:00:31 +02:00
|
|
|
*
|
|
|
|
* @param e event
|
2012-05-30 00:47:21 +02:00
|
|
|
*/
|
|
|
|
_open_search: function(e) {
|
|
|
|
var widget = e.data;
|
|
|
|
var search = widget._create_search();
|
|
|
|
|
|
|
|
// Selecting a single user closes the dialog, this only used if user cleared
|
|
|
|
var ok_click = function() {
|
|
|
|
jQuery(this).dialog("close");
|
|
|
|
widget.set_value([]);
|
2012-06-19 01:28:51 +02:00
|
|
|
// Fire change event
|
|
|
|
if(widget.input) widget.input.trigger("change");
|
2012-05-30 00:47:21 +02:00
|
|
|
// Free it up, it will be re-created, if ever needed again
|
|
|
|
jQuery(this).dialog("destroy");
|
|
|
|
};
|
|
|
|
widget._create_dialog(search, ok_click);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create & display a way to search & select multiple accounts / groups
|
2014-05-14 12:00:31 +02:00
|
|
|
*
|
|
|
|
* @param e event
|
2012-05-30 00:47:21 +02:00
|
|
|
*/
|
|
|
|
_open_multi_search: function(e) {
|
2012-06-19 01:28:51 +02:00
|
|
|
var widget = e && e.data ? e.data : this;
|
2012-05-30 00:47:21 +02:00
|
|
|
var table = widget.search = jQuery('<table><tbody><tr valign="top"><td id="search_col"/><td id="selection_col"/></tr></tbody></table>');
|
|
|
|
table.css("width", "100%").css("height", "100%");
|
|
|
|
var search_col = jQuery('#search_col',table);
|
|
|
|
var select_col = jQuery('#selection_col',table);
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
// Search / Selection
|
|
|
|
search_col.append(widget._create_search());
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
// Currently selected
|
|
|
|
select_col.append(widget._create_selected());
|
2014-03-18 14:22:15 +01:00
|
|
|
|
|
|
|
var ok_click = function() {
|
2012-05-30 00:47:21 +02:00
|
|
|
jQuery(this).dialog("close");
|
|
|
|
// Update widget with selected
|
|
|
|
var ids = [];
|
|
|
|
var data = {};
|
2013-09-30 18:54:25 +02:00
|
|
|
jQuery('#'+widget.getInstanceManager().uniqueId + '_selected li',select_col).each(function() {
|
|
|
|
var id = $j(this).attr("data-id");
|
|
|
|
// Add to list
|
|
|
|
ids.push(id);
|
2012-05-30 00:47:21 +02:00
|
|
|
|
|
|
|
// Make sure option is there
|
2014-03-24 21:20:25 +01:00
|
|
|
if(!widget.options.multiple && jQuery('input[id$="_opt_'+id+'"]',widget.multiOptions).length == 0)
|
2012-05-30 00:47:21 +02:00
|
|
|
{
|
2013-09-30 18:54:25 +02:00
|
|
|
widget._appendMultiOption(id,jQuery('label',this).text());
|
2012-05-30 00:47:21 +02:00
|
|
|
}
|
2014-03-24 21:20:25 +01:00
|
|
|
else if (widget.options.multiple && jQuery('option[value="'+id+'"]',widget.node).length == 0)
|
|
|
|
{
|
|
|
|
widget._appendOptionElement(id,jQuery('label',this).text());
|
|
|
|
}
|
2012-05-30 00:47:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
widget.set_value(ids);
|
|
|
|
|
|
|
|
// Free it up, it will be re-created, if ever needed again
|
|
|
|
jQuery(this).dialog("destroy");
|
2012-06-05 23:03:00 +02:00
|
|
|
|
|
|
|
// Fire change event
|
2012-06-13 17:16:01 +02:00
|
|
|
if(widget.input) widget.input.trigger("change");
|
2012-05-30 00:47:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var container = jQuery(document.createElement("div")).append(table);
|
|
|
|
return widget._create_dialog(container, ok_click);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create / display popup with search / selection widgets
|
2014-05-14 12:00:31 +02:00
|
|
|
*
|
|
|
|
* @param {et2_dialog} widgets
|
|
|
|
* @param {function} update_function
|
2012-05-30 00:47:21 +02:00
|
|
|
*/
|
|
|
|
_create_dialog: function(widgets, update_function) {
|
|
|
|
this.dialog = widgets;
|
|
|
|
widgets.dialog({
|
|
|
|
title: this.options.label ? this.options.label : this.egw().lang('Select'),
|
|
|
|
modal: true,
|
|
|
|
// Static size for easier layout
|
|
|
|
width: "500",
|
|
|
|
height: "350",
|
|
|
|
buttons: [{
|
|
|
|
text: this.egw().lang("ok"),
|
|
|
|
click: update_function
|
|
|
|
},{
|
|
|
|
text: this.egw().lang("cancel"),
|
2014-03-18 14:22:15 +01:00
|
|
|
click: function() {
|
2012-05-30 00:47:21 +02:00
|
|
|
jQuery(this).dialog("close");
|
|
|
|
jQuery(this).dialog("destroy");
|
|
|
|
}}
|
|
|
|
]
|
|
|
|
});
|
2012-06-19 01:28:51 +02:00
|
|
|
return widgets;
|
2012-05-30 00:47:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search is a link-entry widget, with some special display for multi-select
|
|
|
|
*/
|
|
|
|
_create_search: function() {
|
|
|
|
var self = this;
|
|
|
|
var search = this.search = jQuery(document.createElement("div"));
|
|
|
|
|
|
|
|
var search_widget = this.search_widget = et2_createWidget('link-entry', {
|
2013-02-08 11:38:09 +01:00
|
|
|
'only_app': 'home-accounts',
|
2012-05-30 00:47:21 +02:00
|
|
|
'query': function(request, response) {
|
|
|
|
// Clear previous search results for multi-select
|
|
|
|
if(!request.options)
|
|
|
|
{
|
|
|
|
search.find('#search_results').empty();
|
|
|
|
}
|
|
|
|
// Restrict to specified account type
|
2014-04-17 14:24:03 +02:00
|
|
|
if(!request.options || !request.options.filter)
|
2012-05-30 00:47:21 +02:00
|
|
|
{
|
2014-04-17 14:24:03 +02:00
|
|
|
request.options = {account_type: self.options.account_type};
|
2012-05-30 00:47:21 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
'select': function(e, selected) {
|
|
|
|
// Make sure option is there
|
2014-01-20 14:45:33 +01:00
|
|
|
var already_there = false;
|
|
|
|
var last_key = null;
|
|
|
|
for(last_key in self.options.select_options)
|
|
|
|
{
|
|
|
|
var option = self.options.select_options[last_key];
|
|
|
|
already_there = already_there || (typeof option.value != 'undefined' && option.value == selected.item.value);
|
|
|
|
}
|
|
|
|
if(!already_there)
|
2012-05-30 00:47:21 +02:00
|
|
|
{
|
2014-01-20 14:45:33 +01:00
|
|
|
self.options.select_options[parseInt(last_key)+1] = selected.item;
|
2012-05-30 00:47:21 +02:00
|
|
|
self._appendOptionElement(selected.item.value, selected.item.label);
|
|
|
|
}
|
|
|
|
self.set_value(selected.item.value);
|
|
|
|
if(self.dialog)
|
|
|
|
{
|
|
|
|
self.dialog.dialog("close");
|
|
|
|
self.dialog.dialog("destroy");
|
|
|
|
}
|
2012-06-05 23:03:00 +02:00
|
|
|
// Fire change event
|
2012-06-19 01:28:51 +02:00
|
|
|
if(self.input) self.input.trigger("change");
|
|
|
|
return true;
|
2012-05-30 00:47:21 +02:00
|
|
|
}
|
|
|
|
}, this);
|
2012-06-05 23:03:00 +02:00
|
|
|
// add it where we want it
|
2012-05-30 00:47:21 +02:00
|
|
|
search.append(search_widget.getDOMNode());
|
|
|
|
|
|
|
|
if(!this.options.multiple) return search;
|
|
|
|
|
|
|
|
// Multiple is more complicated. It uses a custom display for results to
|
|
|
|
// allow choosing multiples from a match
|
|
|
|
var results = jQuery(document.createElement("ul"))
|
|
|
|
.attr("id", "search_results")
|
|
|
|
.css("height", "230px")
|
|
|
|
.addClass("ui-multiselect-checkboxes ui-helper-reset");
|
|
|
|
jQuery(document.createElement("div"))
|
|
|
|
.addClass("et2_selectbox")
|
|
|
|
.css("height", "100%")
|
|
|
|
.append(results)
|
|
|
|
.appendTo(search);
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
// Override link-entry auto-complete for custom display
|
|
|
|
// Don't show normal drop-down
|
2013-07-20 19:20:55 +02:00
|
|
|
search_widget.search.data("ui-autocomplete")._suggest = function(items) {
|
2012-05-30 00:47:21 +02:00
|
|
|
jQuery.each(items, function (index, item) {
|
2014-01-20 14:45:33 +01:00
|
|
|
// Make sure value is numeric
|
|
|
|
item.value = parseInt(item.value);
|
|
|
|
self._add_search_result(results, item);
|
2012-05-30 00:47:21 +02:00
|
|
|
});
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2012-05-30 00:47:21 +02:00
|
|
|
|
|
|
|
return search;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the selected result to the list of search results
|
2014-05-14 12:00:31 +02:00
|
|
|
*
|
|
|
|
* @param list
|
|
|
|
* @param item
|
2012-05-30 00:47:21 +02:00
|
|
|
*/
|
|
|
|
_add_search_result: function(list, item) {
|
|
|
|
|
|
|
|
var node = null;
|
|
|
|
var self = this;
|
2014-04-17 14:24:03 +02:00
|
|
|
|
2014-03-24 21:20:25 +01:00
|
|
|
// Make sure value is numeric
|
|
|
|
if(item.value) item.value = parseInt(item.value);
|
2012-05-30 00:47:21 +02:00
|
|
|
|
|
|
|
// (containter of) Currently selected users / groups
|
2013-09-30 18:54:25 +02:00
|
|
|
var selected = jQuery('#'+this.getInstanceManager().uniqueId + "_selected", this.dialog);
|
2012-05-30 00:47:21 +02:00
|
|
|
|
|
|
|
// Group
|
|
|
|
if(item.value && item.value < 0)
|
|
|
|
{
|
|
|
|
node = jQuery(document.createElement('ul'));
|
|
|
|
// Add button to show users
|
|
|
|
if(this.options.account_type != 'groups')
|
|
|
|
{
|
|
|
|
jQuery('<span class="ui-icon ui-icon-circlesmall-plus et2_clickable"/>')
|
|
|
|
.css("float", "left")
|
|
|
|
.appendTo(node)
|
2013-09-30 18:54:25 +02:00
|
|
|
.click(function() {
|
|
|
|
if(jQuery(this).hasClass("ui-icon-circlesmall-plus"))
|
2012-05-30 00:47:21 +02:00
|
|
|
{
|
2013-09-30 18:54:25 +02:00
|
|
|
jQuery(this).removeClass("ui-icon-circlesmall-plus")
|
|
|
|
.addClass("ui-icon-circlesmall-minus");
|
|
|
|
|
|
|
|
var group = jQuery(this).parent()
|
|
|
|
.addClass("expanded");
|
|
|
|
|
|
|
|
if(group.children("li").length == 0)
|
|
|
|
{
|
|
|
|
// Fetch group members
|
|
|
|
self.search_widget.query({
|
|
|
|
term:"",
|
|
|
|
options: {filter:{group: item.value}},
|
|
|
|
no_cache:true
|
|
|
|
}, function(items) {
|
|
|
|
jQuery(items).each(function(index,item) {
|
|
|
|
self._add_search_result(node, item);
|
|
|
|
});
|
2012-05-30 00:47:21 +02:00
|
|
|
});
|
2013-09-30 18:54:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
group.children("li")
|
|
|
|
// Only show children that are not selected
|
|
|
|
.each(function(index, item) {
|
|
|
|
var j = jQuery(item);
|
|
|
|
if(jQuery('[data-id="'+j.attr("data-id")+'"]',selected).length == 0)
|
|
|
|
{
|
|
|
|
j.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-05-30 00:47:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-30 18:54:25 +02:00
|
|
|
jQuery(this).addClass("ui-icon-circlesmall-plus")
|
|
|
|
.removeClass("ui-icon-circlesmall-minus");
|
|
|
|
|
|
|
|
var group = jQuery(this).parent().children("li").hide();
|
2012-05-30 00:47:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// User
|
|
|
|
else if (item.value)
|
|
|
|
{
|
|
|
|
node = jQuery(document.createElement('li'));
|
|
|
|
}
|
2013-09-30 18:54:25 +02:00
|
|
|
node.attr("data-id", item.value);
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
jQuery('<span class="ui-icon ui-icon-arrow-1-e et2_clickable"/>')
|
|
|
|
.css("float", "right")
|
|
|
|
.appendTo(node)
|
|
|
|
.click(function() {
|
|
|
|
var button = jQuery(this);
|
2013-09-30 18:54:25 +02:00
|
|
|
self._add_selected(selected, button.parent().attr("data-id"));
|
2012-05-30 00:47:21 +02:00
|
|
|
// Hide user, but only hide button for group
|
|
|
|
if(button.parent().is('li'))
|
|
|
|
{
|
|
|
|
button.parent().hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
button.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// If already in list, hide it
|
2013-09-30 18:54:25 +02:00
|
|
|
if(jQuery('[data-id="'+item.value+'"]',selected).length != 0)
|
2012-05-30 00:47:21 +02:00
|
|
|
{
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
var label = jQuery(document.createElement('label'))
|
|
|
|
.addClass("loading")
|
|
|
|
.appendTo(node);
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
this.egw().link_title('home-accounts', item.value, function(name) {
|
2013-04-13 21:00:13 +02:00
|
|
|
label.text(name).removeClass("loading");
|
2012-05-30 00:47:21 +02:00
|
|
|
}, label);
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
node.appendTo(list);
|
2012-05-30 00:47:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_create_selected: 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);
|
|
|
|
|
|
|
|
var selected = jQuery(document.createElement("ul"))
|
|
|
|
.addClass("ui-multiselect-checkboxes ui-helper-reset")
|
2013-09-30 18:54:25 +02:00
|
|
|
.attr("id", this.getInstanceManager().uniqueId + "_selected")
|
2012-05-30 00:47:21 +02:00
|
|
|
.css("height", "230px")
|
|
|
|
.appendTo(node);
|
|
|
|
|
|
|
|
jQuery(document.createElement("span"))
|
|
|
|
.text(this.egw().lang("Selection"))
|
|
|
|
.addClass("ui-multiselect-header")
|
|
|
|
.appendTo(header);
|
|
|
|
|
|
|
|
var controls = jQuery(document.createElement("ul"))
|
|
|
|
.addClass('ui-helper-reset')
|
|
|
|
.appendTo(header);
|
|
|
|
|
|
|
|
jQuery(document.createElement("li"))
|
|
|
|
.addClass("et2_clickable")
|
|
|
|
.click(selected, function(e) {jQuery("li",e.data).remove();})
|
|
|
|
.append('<span class="ui-icon ui-icon-closethick"/>')
|
|
|
|
.appendTo(controls);
|
|
|
|
|
|
|
|
// Add in currently selected
|
|
|
|
if(this.getValue())
|
|
|
|
{
|
|
|
|
var value = this.getValue();
|
|
|
|
for(var i = 0; i < value.length; i++) {
|
|
|
|
this._add_selected(selected, value[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an option to the list of selected accounts
|
|
|
|
* value is the account / group ID
|
2014-05-14 12:00:31 +02:00
|
|
|
*
|
|
|
|
* @param list
|
|
|
|
* @param value
|
2012-05-30 00:47:21 +02:00
|
|
|
*/
|
|
|
|
_add_selected: function(list, value) {
|
|
|
|
|
2013-09-30 18:54:25 +02:00
|
|
|
// Each option only once
|
|
|
|
var there = jQuery('[data-id="' + value + '"]',list);
|
|
|
|
if(there.length)
|
|
|
|
{
|
|
|
|
there.show();
|
|
|
|
return;
|
|
|
|
}
|
2014-03-18 14:22:15 +01:00
|
|
|
|
2012-05-30 00:47:21 +02:00
|
|
|
var option = jQuery(document.createElement('li'))
|
2013-09-30 18:54:25 +02:00
|
|
|
.attr("data-id",value)
|
2012-05-30 00:47:21 +02:00
|
|
|
.appendTo(list);
|
2013-06-06 00:45:19 +02:00
|
|
|
jQuery('<div class="ui-icon ui-icon-close et2_clickable"/>')
|
2012-05-30 00:47:21 +02:00
|
|
|
.css("float", "right")
|
|
|
|
.appendTo(option)
|
|
|
|
.click(function() {
|
2013-09-30 18:54:25 +02:00
|
|
|
var id = jQuery(this).parent().attr("data-id");
|
2012-05-30 00:47:21 +02:00
|
|
|
jQuery(this).parent().remove();
|
|
|
|
// Add 'add' button back, if in results list
|
2013-09-30 18:54:25 +02:00
|
|
|
list.parents("tr").find("[data-id='"+id+"']").show()
|
2012-05-30 00:47:21 +02:00
|
|
|
// Show button(s) for group
|
|
|
|
.children('span').show();
|
|
|
|
});
|
|
|
|
|
|
|
|
var label = jQuery(document.createElement('label'))
|
|
|
|
.addClass("loading")
|
|
|
|
.appendTo(option);
|
2013-04-13 21:00:13 +02:00
|
|
|
this.egw().link_title('home-accounts', value, function(name) {this.text(name).removeClass("loading");}, label);
|
2014-07-02 16:36:47 +02:00
|
|
|
},
|
2014-07-13 11:14:58 +02:00
|
|
|
|
2014-07-02 16:36:47 +02:00
|
|
|
/**
|
|
|
|
* Overwritten attachToDOM metod to modify attachToDOM
|
|
|
|
*/
|
|
|
|
attachToDOM: function ()
|
|
|
|
{
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
//Chosen needs to be set after widget dettached from DOM (eg. validation_error), because chosen is not part of the widget node
|
|
|
|
if (this.egw().preference('account_selection', 'common') == 'primary_group')
|
|
|
|
{
|
|
|
|
jQuery(this.node).removeClass('chzn-done');
|
|
|
|
this.set_tags(this.options.tags, this.options.width);
|
|
|
|
}
|
2012-05-30 00:47:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
et2_register_widget(et2_selectAccount, ["select-account"]);
|
|
|
|
|
2012-03-14 20:02:28 +01:00
|
|
|
/**
|
|
|
|
* et2_selectAccount_ro is the readonly implementation of select account
|
|
|
|
* It extends et2_link to avoid needing the whole user list on the client.
|
|
|
|
* Instead, it just asks for the names of the ones needed, as needed.
|
2014-03-18 14:22:15 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_link_string
|
2012-03-14 20:02:28 +01:00
|
|
|
*/
|
2014-03-18 14:22:15 +01:00
|
|
|
var et2_selectAccount_ro = et2_link_string.extend([et2_IDetachedDOM],
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2012-05-08 00:09:54 +02:00
|
|
|
attributes: {
|
|
|
|
"empty_label": {
|
2013-10-10 12:23:37 +02:00
|
|
|
"name": "Empty label",
|
|
|
|
"type": "string",
|
|
|
|
"default": "",
|
|
|
|
"description": "Textual label for first row, eg: 'All' or 'None'. ID will be ''",
|
2014-05-07 14:23:02 +02:00
|
|
|
translate:true
|
2014-05-14 12:00:31 +02:00
|
|
|
}
|
2012-05-08 00:09:54 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
legacyOptions: ["empty_label"],
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-03-18 14:22:15 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @param _parent
|
|
|
|
* @param options
|
|
|
|
* @memberOf et2_selectAccount_ro
|
|
|
|
*/
|
2012-03-15 09:29:45 +01:00
|
|
|
init: function(_parent, options) {
|
2012-03-14 20:02:28 +01:00
|
|
|
/**
|
|
|
|
Resolve some circular dependency problems here
|
2014-03-18 14:22:15 +01:00
|
|
|
selectAccount extends link, link is in a file that needs select,
|
2012-03-14 20:02:28 +01:00
|
|
|
select has menulist wrapper, which needs to know about selectAccount before it allows it
|
|
|
|
*/
|
|
|
|
if(_parent.supportedWidgetClasses.indexOf(et2_selectAccount_ro) < 0)
|
|
|
|
{
|
|
|
|
_parent.supportedWidgetClasses.push(et2_selectAccount_ro);
|
|
|
|
}
|
|
|
|
|
2012-03-15 09:29:45 +01:00
|
|
|
this._super.apply(this, arguments);
|
2012-03-14 20:02:28 +01:00
|
|
|
|
2014-03-18 14:22:15 +01:00
|
|
|
// Legacy options could have row count or empty label in first slot
|
2012-05-08 00:09:54 +02:00
|
|
|
if(typeof this.options.empty_label == "string")
|
|
|
|
{
|
|
|
|
if(isNaN(this.options.empty_label))
|
|
|
|
{
|
|
|
|
this.options.empty_label = this.egw().lang(this.options.empty_label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-15 09:29:45 +01:00
|
|
|
this.options.application = 'home-accounts';
|
2012-03-14 20:02:28 +01:00
|
|
|
|
2014-05-05 19:25:01 +02:00
|
|
|
// Editable version allows app to set options that aren't accounts, so allow for them
|
|
|
|
var options = et2_selectbox.find_select_options(this,options['select_options']);
|
|
|
|
if(!jQuery.isEmptyObject(options))
|
|
|
|
{
|
|
|
|
this.options.select_options = options;
|
|
|
|
}
|
|
|
|
|
2012-03-14 20:02:28 +01:00
|
|
|
// Don't make it look like a link though
|
2012-04-17 01:08:28 +02:00
|
|
|
this.list.removeClass("et2_link_string").addClass("et2_selectbox");
|
|
|
|
},
|
|
|
|
|
2012-06-06 06:05:21 +02:00
|
|
|
transformAttributes: function(_attrs) {
|
|
|
|
et2_selectbox.prototype.transformAttributes.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
2012-04-17 01:08:28 +02:00
|
|
|
set_value: function(_value) {
|
2012-06-06 23:07:19 +02:00
|
|
|
// Explode csv
|
2014-03-18 14:22:15 +01:00
|
|
|
if(typeof _value == 'string' && _value.indexOf(',') > 0)
|
2012-06-06 23:07:19 +02:00
|
|
|
{
|
|
|
|
_value = _value.split(',');
|
|
|
|
}
|
|
|
|
|
2012-06-06 20:47:04 +02:00
|
|
|
// Don't bother to lookup if it's not an array, or a number
|
2014-05-05 19:25:01 +02:00
|
|
|
if(typeof _value == 'object' || !isNaN(_value) && _value != "")
|
2012-06-06 20:47:04 +02:00
|
|
|
{
|
|
|
|
this._super.apply(this, arguments);
|
2012-06-06 23:07:19 +02:00
|
|
|
// Don't make it look like a link though
|
2014-04-07 16:59:01 +02:00
|
|
|
jQuery('li',this.list).removeClass("et2_link et2_link_string")
|
|
|
|
// No clicks either
|
|
|
|
.off();
|
2012-06-06 23:07:19 +02:00
|
|
|
return;
|
2012-06-06 20:47:04 +02:00
|
|
|
}
|
2012-04-17 01:08:28 +02:00
|
|
|
|
2012-06-06 23:07:19 +02:00
|
|
|
// Don't make it look like a link
|
2014-04-07 16:59:01 +02:00
|
|
|
jQuery('li',this.list).removeClass("et2_link et2_link_string")
|
|
|
|
// No clicks either
|
|
|
|
.off();
|
2012-05-08 00:09:54 +02:00
|
|
|
|
2014-07-15 17:40:22 +02:00
|
|
|
if(this.options.select_options && !jQuery.isEmptyObject(this.options.select_options) || this.options.empty_label)
|
2012-05-08 00:09:54 +02:00
|
|
|
{
|
|
|
|
if(!_value)
|
|
|
|
{
|
2012-06-06 06:05:21 +02:00
|
|
|
// Empty label from selectbox
|
2012-05-08 00:09:54 +02:00
|
|
|
this.list.append("<li>"+this.options.empty_label+"</li>");
|
|
|
|
}
|
2012-06-06 06:05:21 +02:00
|
|
|
else if (typeof _value == 'object')
|
2012-05-08 00:09:54 +02:00
|
|
|
{
|
|
|
|
// An array with 0 / empty in it?
|
|
|
|
for(var i = 0; i < _value.length; i++)
|
|
|
|
{
|
|
|
|
if(!_value[i] || !parseInt(_value[i]))
|
|
|
|
{
|
|
|
|
this.list.append("<li>"+this.options.empty_label+"</li>");
|
|
|
|
return;
|
|
|
|
}
|
2012-06-06 06:05:21 +02:00
|
|
|
else if (this.options.select_options[_value])
|
|
|
|
{
|
|
|
|
this.list.append("<li>"+this.options.select_options[_value]+"</li>");
|
|
|
|
}
|
2012-05-08 00:09:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-15 17:40:22 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Options are not indexed, so we must look
|
|
|
|
var search = _value;
|
|
|
|
if (!jQuery.isArray(search))
|
|
|
|
{
|
|
|
|
search = [_value];
|
|
|
|
}
|
|
|
|
for(var j = 0; j < search.length; j++)
|
|
|
|
{
|
|
|
|
var found = false;
|
|
|
|
|
|
|
|
// Not having a value to look up causes an infinite loop
|
|
|
|
if(!search[j]) continue;
|
|
|
|
|
|
|
|
for(var i in this.options.select_options)
|
|
|
|
{
|
|
|
|
if(this.options.select_options[i].value == search[j])
|
|
|
|
{
|
|
|
|
this.list.append("<li>"+this.options.select_options[i].label+"</li>");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2012-05-08 00:09:54 +02:00
|
|
|
}
|
2012-03-15 09:29:45 +01:00
|
|
|
}
|
2012-03-14 20:02:28 +01:00
|
|
|
});
|
|
|
|
et2_register_widget(et2_selectAccount_ro, ["select-account_ro"]);
|