Fix account/group select search dialog

- Broken group expansion
 - Broken styling / indents
 - Use unique IDs & data-id for account ID
This commit is contained in:
Nathan Gray 2013-09-30 16:54:25 +00:00
parent 28c2737c9f
commit 83741673c3
3 changed files with 70 additions and 50 deletions

View File

@ -789,7 +789,7 @@ var et2_link_entry = et2_inputWidget.extend(
if(!this.options.query(request, response)) return false; if(!this.options.query(request, response)) return false;
} }
if(request.term in this.cache) { if((typeof request.no_cache == 'undefined' && !request.no_cache) && request.term in this.cache) {
return response(this.cache[request.term]); return response(this.cache[request.term]);
} }

View File

@ -221,7 +221,7 @@ var et2_selectAccount = et2_selectbox.extend(
this.setDOMNode(div[0]); this.setDOMNode(div[0]);
var select_col = jQuery('#selection_col',dialog).children(); var select_col = jQuery('#selection_col',dialog).children();
var selected = jQuery('#selected', select_col); var selected = jQuery('#'+this.getInstanceManager().uniqueId + "_selected", select_col);
// Re-do to get it to work around/through the select box // Re-do to get it to work around/through the select box
this.set_value = function(_value) { this.set_value = function(_value) {
@ -243,14 +243,15 @@ var et2_selectAccount = et2_selectbox.extend(
// Update widget with selected // Update widget with selected
var ids = []; var ids = [];
var data = {}; var data = {};
jQuery('#selected li',select_col).each(function() { jQuery('#'+this.getInstanceManager().uniqueId + '_selected li',select_col).each(function() {
// Remove sel_ prefix and add to list var id = $j(this).attr("data-id");
ids.push(this.id.substr(4)); // Add to list
ids.push(id);
// Make sure option is there // Make sure option is there
if(jQuery('input[id$="_opt_'+this.id.substr(4)+'"]',widget.multiOptions).length == 0) if(jQuery('input[data-id="'+id+'"]',widget.multiOptions).length == 0)
{ {
widget._appendMultiOption(this.id.substr(4),jQuery('label',this).text()); widget._appendMultiOption(id,jQuery('label',this).text());
} }
}); });
@ -301,14 +302,15 @@ var et2_selectAccount = et2_selectbox.extend(
// Update widget with selected // Update widget with selected
var ids = []; var ids = [];
var data = {}; var data = {};
jQuery('#selected li',select_col).each(function() { jQuery('#'+widget.getInstanceManager().uniqueId + '_selected li',select_col).each(function() {
// Remove sel_ prefix and add to list var id = $j(this).attr("data-id");
ids.push(this.id.substr(4)); // Add to list
ids.push(id);
// Make sure option is there // Make sure option is there
if(jQuery('input[id$="_opt_'+this.id.substr(4)+'"]',widget.multiOptions).length == 0) if(jQuery('input[id$="_opt_'+id+'"]',widget.multiOptions).length == 0)
{ {
widget._appendMultiOption(this.id.substr(4),jQuery('label',this).text()); widget._appendMultiOption(id,jQuery('label',this).text());
} }
}); });
@ -427,7 +429,7 @@ var et2_selectAccount = et2_selectbox.extend(
var self = this; var self = this;
// (containter of) Currently selected users / groups // (containter of) Currently selected users / groups
var selected = jQuery('#selected', this.dialog); var selected = jQuery('#'+this.getInstanceManager().uniqueId + "_selected", this.dialog);
// Group // Group
if(item.value && item.value < 0) if(item.value && item.value < 0)
@ -439,7 +441,9 @@ var et2_selectAccount = et2_selectbox.extend(
jQuery('<span class="ui-icon ui-icon-circlesmall-plus et2_clickable"/>') jQuery('<span class="ui-icon ui-icon-circlesmall-plus et2_clickable"/>')
.css("float", "left") .css("float", "left")
.appendTo(node) .appendTo(node)
.toggle(function() { .click(function() {
if(jQuery(this).hasClass("ui-icon-circlesmall-plus"))
{
jQuery(this).removeClass("ui-icon-circlesmall-plus") jQuery(this).removeClass("ui-icon-circlesmall-plus")
.addClass("ui-icon-circlesmall-minus"); .addClass("ui-icon-circlesmall-minus");
@ -449,7 +453,11 @@ var et2_selectAccount = et2_selectbox.extend(
if(group.children("li").length == 0) if(group.children("li").length == 0)
{ {
// Fetch group members // Fetch group members
self.search_widget.query({term:"",options: {filter:{group: item.value}}}, function(items) { self.search_widget.query({
term:"",
options: {filter:{group: item.value}},
no_cache:true
}, function(items) {
jQuery(items).each(function(index,item) { jQuery(items).each(function(index,item) {
self._add_search_result(node, item); self._add_search_result(node, item);
}); });
@ -461,17 +469,20 @@ var et2_selectAccount = et2_selectbox.extend(
// Only show children that are not selected // Only show children that are not selected
.each(function(index, item) { .each(function(index, item) {
var j = jQuery(item); var j = jQuery(item);
if(jQuery('#sel_'+j.attr("id").substr(5),selected).length == 0) if(jQuery('[data-id="'+j.attr("data-id")+'"]',selected).length == 0)
{ {
j.show(); j.show();
} }
}); });
} }
},function() { }
else
{
jQuery(this).addClass("ui-icon-circlesmall-plus") jQuery(this).addClass("ui-icon-circlesmall-plus")
.removeClass("ui-icon-circlesmall-minus"); .removeClass("ui-icon-circlesmall-minus");
var group = jQuery(this).parent().children("li").hide(); var group = jQuery(this).parent().children("li").hide();
}
}); });
} }
@ -481,14 +492,14 @@ var et2_selectAccount = et2_selectbox.extend(
{ {
node = jQuery(document.createElement('li')); node = jQuery(document.createElement('li'));
} }
node.attr("id", "list_"+item.value); node.attr("data-id", item.value);
jQuery('<span class="ui-icon ui-icon-arrow-1-e et2_clickable"/>') jQuery('<span class="ui-icon ui-icon-arrow-1-e et2_clickable"/>')
.css("float", "right") .css("float", "right")
.appendTo(node) .appendTo(node)
.click(function() { .click(function() {
var button = jQuery(this); var button = jQuery(this);
self._add_selected(selected, button.parent().attr("id").substr(5)); self._add_selected(selected, button.parent().attr("data-id"));
// Hide user, but only hide button for group // Hide user, but only hide button for group
if(button.parent().is('li')) if(button.parent().is('li'))
{ {
@ -501,7 +512,7 @@ var et2_selectAccount = et2_selectbox.extend(
}); });
// If already in list, hide it // If already in list, hide it
if(jQuery('#sel_'+item.value,selected).length != 0) if(jQuery('[data-id="'+item.value+'"]',selected).length != 0)
{ {
node.hide(); node.hide();
} }
@ -509,6 +520,7 @@ var et2_selectAccount = et2_selectbox.extend(
var label = jQuery(document.createElement('label')) var label = jQuery(document.createElement('label'))
.addClass("loading") .addClass("loading")
.appendTo(node); .appendTo(node);
this.egw().link_title('home-accounts', item.value, function(name) { this.egw().link_title('home-accounts', item.value, function(name) {
label.text(name).removeClass("loading"); label.text(name).removeClass("loading");
}, label); }, label);
@ -526,7 +538,7 @@ var et2_selectAccount = et2_selectbox.extend(
var selected = jQuery(document.createElement("ul")) var selected = jQuery(document.createElement("ul"))
.addClass("ui-multiselect-checkboxes ui-helper-reset") .addClass("ui-multiselect-checkboxes ui-helper-reset")
.attr("id", "selected") .attr("id", this.getInstanceManager().uniqueId + "_selected")
.css("height", "230px") .css("height", "230px")
.appendTo(node); .appendTo(node);
@ -562,17 +574,25 @@ var et2_selectAccount = et2_selectbox.extend(
*/ */
_add_selected: function(list, value) { _add_selected: function(list, value) {
// Each option only once
var there = jQuery('[data-id="' + value + '"]',list);
if(there.length)
{
there.show();
return;
}
var option = jQuery(document.createElement('li')) var option = jQuery(document.createElement('li'))
.attr("id",'sel_'+value) .attr("data-id",value)
.appendTo(list); .appendTo(list);
jQuery('<div class="ui-icon ui-icon-close et2_clickable"/>') jQuery('<div class="ui-icon ui-icon-close et2_clickable"/>')
.css("float", "right") .css("float", "right")
.appendTo(option) .appendTo(option)
.click(function() { .click(function() {
var id = jQuery(this).parent().attr("id").substr(4); var id = jQuery(this).parent().attr("data-id");
jQuery(this).parent().remove(); jQuery(this).parent().remove();
// Add 'add' button back, if in results list // Add 'add' button back, if in results list
list.parents("tr").find("#list_"+id).show() list.parents("tr").find("[data-id='"+id+"']").show()
// Show button(s) for group // Show button(s) for group
.children('span').show(); .children('span').show();
}); });

View File

@ -291,7 +291,7 @@ button.et2_button_text:focus, input[type=button]:focus {
.et2_selectbox .ui-multiselect-checkboxes li { .et2_selectbox .ui-multiselect-checkboxes li {
margin: 0px; margin: 0px;
clear: both; clear: both;
padding-left: 22px; padding-left: 26px;
padding-right: 3px; padding-right: 3px;
text-decoration: none; text-decoration: none;
list-style-image: none; list-style-image: none;
@ -315,7 +315,7 @@ button.et2_button_text:focus, input[type=button]:focus {
border: 1px solid transparent; border: 1px solid transparent;
} }
.et2_selectbox input[type="checkbox"] { .et2_selectbox input[type="checkbox"] {
margin: 3px; margin: 3px 3px 3px -1px;
} }
.et2_selectbox .ui-multiselect-checkboxes img { .et2_selectbox .ui-multiselect-checkboxes img {
height: 1.0em; height: 1.0em;