2012-03-14 20:02:28 +01:00
|
|
|
/**
|
2012-03-15 09:29:45 +01:00
|
|
|
* EGroupware eTemplate2 - JS Select account widget
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-04-17 01:08:28 +02:00
|
|
|
var et2_selectAccount_ro = et2_link_string.extend([et2_IDetachedDOM], {
|
2012-03-14 20:02:28 +01:00
|
|
|
|
2012-05-08 00:09:54 +02:00
|
|
|
attributes: {
|
|
|
|
"empty_label": {
|
|
|
|
"name": "Empty label",
|
|
|
|
"type": "string",
|
|
|
|
"default": "",
|
|
|
|
"description": "Textual label for first row, eg: 'All' or 'None'. ID will be ''"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
legacyOptions: ["empty_label"],
|
|
|
|
|
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
|
|
|
|
selectAccount extends link, link is in a file that needs select,
|
|
|
|
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
|
|
|
|
2012-05-08 00:09:54 +02:00
|
|
|
// Legacy options could have row count or empty label in first slot
|
|
|
|
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
|
|
|
|
|
|
|
// 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");
|
|
|
|
},
|
|
|
|
|
|
|
|
set_value: function(_value) {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Don't make it look like a link though
|
|
|
|
jQuery('li',this.list).removeClass("et2_link et2_link_string");
|
2012-05-08 00:09:54 +02:00
|
|
|
|
|
|
|
// Empty label from selectbox
|
|
|
|
if(this.options.empty_label)
|
|
|
|
{
|
|
|
|
if(!_value)
|
|
|
|
{
|
|
|
|
this.list.append("<li>"+this.options.empty_label+"</li>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 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-03-15 09:29:45 +01:00
|
|
|
}
|
2012-03-14 20:02:28 +01:00
|
|
|
});
|
|
|
|
et2_register_widget(et2_selectAccount_ro, ["select-account_ro"]);
|