More changes to use chosen for fancy selectboxes - apply to egw multi-select and select user too

This commit is contained in:
Nathan Gray 2012-11-13 22:14:00 +00:00
parent 052897fcd8
commit 8b55a21206
10 changed files with 69 additions and 1065 deletions

View File

@ -1586,8 +1586,9 @@ class etemplate_old extends boetemplate
{
$enhance = $cell['enhance'];
}
else if (count($c_options >= 8))
else if (count($c_options) >= 8)
{
// 8 or more optionsu - #7 is enhance flag
$enhance = ($c_options[7] == '1' || $c_options[7] == 'true');
}
@ -1641,7 +1642,8 @@ class etemplate_old extends boetemplate
if ($multiple && is_numeric($multiple)) // eg. "3+" would give a regular multiselectbox
{
$html .= html::checkbox_multiselect($form_name.($multiple > 1 ? '[]' : ''),$value,$sels,
$cell['no_lang'],$options,$multiple,$multiple[0]!=='0',$extraStyleMultiselect);
$cell['no_lang'],$options,$multiple,$multiple[0]!=='0',
$extraStyleMultiselect,$enhance);
}
else
{

View File

@ -484,6 +484,8 @@ class nextmatch_widget
if (is_object($nextmatch))
{
$size =& $nextmatch->get_cell_attribute('selectcols','size');
// Don't change to fancy multi-select here
$nextmatch->set_cell_attribute('selectcols','enhance',false);
if ($size > count($value['options-selectcols'])) $size = '0'.count($value['options-selectcols']);
if (!$GLOBALS['egw_info']['user']['apps']['admin'])
{

View File

@ -51,6 +51,11 @@ class html
*/
static $api_js_url;
/**
* Automatically turn on enhanced selectboxes if there's more than this many options
*/
const SELECT_ENHANCED_ROW_COUNT = 12;
/**
* initialise our static vars
*/
@ -224,7 +229,7 @@ class html
*/
static function select($name, $key, $arr=0,$no_lang=false,$options='',$multiple=0,$enhanced=null)
{
if(is_null($enhanced)) $enhanced = (count($arr) > 12);
if(is_null($enhanced)) $enhanced = (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
if (!is_array($arr))
{
@ -288,7 +293,7 @@ class html
$out .= "</select>\n";
if($enhanced) {
egw_framework::validate_file('/phpgwapi/js/jquery/chosen/chosen.jquery.min.js');
egw_framework::validate_file('/phpgwapi/js/jquery/chosen/chosen.jquery.js');
egw_framework::includeCSS('/phpgwapi/js/jquery/chosen/chosen.css',null,false);
$out .= "<script>\$j(function() {\$j('select[name=\"$name\"]').chosen();});</script>\n";
}
@ -311,9 +316,11 @@ class html
* @param string $style='' extra style settings like "width: 100%", default '' none
* @return string to set for a template or to echo into html page
*/
static function checkbox_multiselect($name, $key, $arr=0,$no_lang=false,$options='',$multiple=3,$selected_first=true,$style='')
static function checkbox_multiselect($name, $key, $arr=0,$no_lang=false,$options='',$multiple=3,$selected_first=true,$style='',$enhanced = null)
{
//echo "<p align=right>checkbox_multiselect('$name',".array2string($key).",".array2string($arr).",$no_lang,'$options',$multiple,$selected_first,'$style')</p>\n";
if(is_null($enhanced)) $enhanced = (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
if (!is_array($arr))
{
$arr = array('no','yes');
@ -326,6 +333,8 @@ class html
}
$base_name = substr($name,0,-2);
if($enhanced) return self::select($name, $key, $arr,$no_lang,$options,$multiple,$enhanced);
if (!is_array($key))
{
// explode on ',' only if multiple values expected and the key contains just numbers and commas

View File

@ -52,6 +52,10 @@ class uiaccountsel
{
$this->account_selection = 'primary_group';
}
// Include these here, framework may have already sent header by the time the account select is made
egw_framework::validate_file('/phpgwapi/js/jquery/chosen/chosen.jquery.js');
egw_framework::includeCSS('/phpgwapi/js/jquery/chosen/chosen.css',null,false);
}
/**
@ -292,7 +296,11 @@ class uiaccountsel
}
elseif (!$only_groups && ($lines == 1 || $lines > 0 && $this->account_selection == 'primary_group'))
{
$js = "if (selectBox = document.getElementById('$element_id')) if (!selectBox.multiple) {selectBox.size=$multi_size; selectBox.multiple=true; if (selectBox.options[0].value=='') selectBox.options[0] = null;";
$js = "if (selectBox = document.getElementById('$element_id')) if (!selectBox.multiple) { if(\$j(selectBox).unchosen) \$j(selectBox).unchosen(); selectBox.size=$multi_size; selectBox.multiple=true; if (selectBox.options[0].value=='') selectBox.options[0] = null;";
if(count($select) > html::SELECT_ENHANCED_ROW_COUNT)
{
$js .= "\$j(selectBox).css('width','100%').chosen({placeholder_text: '".lang('Select multiple accounts')."'}); ";
}
if (!in_array($this->account_selection,array('groupmembers','selectbox'))) // no popup!
{
$js .= " this.src='".common::image('phpgwapi','search')."'; this.title='".
@ -301,7 +309,7 @@ class uiaccountsel
}
else
{
$js .= " this.style.display='none'; selectBox.style.width='100%';";
$js .= "this.style.display='none'; selectBox.style.width='100%';";
}
$js .= "} return false;";
$html .= html::submit_button('search','Select multiple accounts',$js,false,
@ -329,6 +337,7 @@ function addOption(id,label,value,do_onchange)
selectBox.options[selectBox.length] = new Option(label,value,false,true);
}
if (selectBox.onchange && do_onchange) selectBox.onchange();
$j(selectBox).trigger("liszt:updated");
}
</script>';
$GLOBALS['egw_info']['flags']['uiaccountsel']['addOption_installed'] = True;

View File

@ -1,3 +0,0 @@
.DS_Store
node_modules
.project

View File

@ -156,7 +156,7 @@
border: 0 !important;
font-family: sans-serif;
font-size: 100%;
height: 15px;
height: 12px;
padding: 5px;
margin: 1px 0;
outline: 0;
@ -186,9 +186,9 @@
box-shadow : 0 0 2px #ffffff inset, 0 1px 0 rgba(0,0,0,0.05);
color: #333;
border: 1px solid #aaaaaa;
line-height: 13px;
line-height: 12px;
padding: 3px 20px 3px 5px;
margin: 3px 0 3px 5px;
margin: 2px 0 2px 1px;
position: relative;
cursor: default;
}
@ -230,7 +230,7 @@
.chzn-container .chzn-results {
margin: 0 4px 4px 0;
max-height: 240px;
padding: 0 0 0 4px;
padding: 0 0 0 0px;
position: relative;
overflow-x: hidden;
overflow-y: auto;
@ -242,8 +242,7 @@
}
.chzn-container .chzn-results li {
display: none;
line-height: 15px;
padding: 5px 6px;
padding: 3px 6px;
margin: 0;
list-style: none;
}

View File

@ -249,10 +249,7 @@ Copyright (c) 2011 by Harvest
};
AbstractChosen.prototype.generate_field_id = function() {
var new_id;
new_id = this.generate_random_id();
this.form_field.id = new_id;
return new_id;
return this.generate_random_id();
};
AbstractChosen.prototype.generate_random_char = function() {
@ -296,6 +293,18 @@ Copyright (c) 2011 by Harvest
return $this.data('chosen', new Chosen(this, options));
}
});
},
unchosen: function() {
return $(this).each(function(input_field) {
var chosen, element;
element = $(this);
chosen = element.data("chosen");
if (chosen) {
chosen.remove();
element.data("chosen", null);
}
return element;
});
}
});
@ -419,6 +428,15 @@ Copyright (c) 2011 by Harvest
}
};
Chosen.prototype.unregister_observers = function() {
return this.form_field_jq.unbind();
};
Chosen.prototype.remove_html = function() {
this.form_field_jq.show().removeClass('chzn-done');
return this.container.remove();
};
Chosen.prototype.search_field_disabled = function() {
this.is_disabled = this.form_field_jq[0].disabled;
if (this.is_disabled) {
@ -619,6 +637,13 @@ Copyright (c) 2011 by Harvest
}
};
Chosen.prototype.reset_tab_index = function() {
var tabbed_item;
tabbed_item = this.is_multiple ? this.search_field : this.selected_item;
this.form_field_jq.attr("tabindex",tabbed_item.attr("tabindex"));
return tabbed_item.attr("tabindex") - 1;
};
Chosen.prototype.show_search_field_default = function() {
if (this.is_multiple && this.choices < 1 && !this.active_field) {
this.search_field.val(this.default_text);
@ -888,6 +913,12 @@ Copyright (c) 2011 by Harvest
return this.search_results.find(".no-results").remove();
};
Chosen.prototype.remove = function() {
this.reset_tab_index();
this.unregister_observers();
return this.remove_html();
};
Chosen.prototype.keydown_arrow = function() {
var first_active, next_sib;
if (!this.result_highlight) {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long