retain group_by order

git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1804 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
j.wollert 14 years ago
parent 4fdc35cdfe
commit 88f6ecde38
  1. 8
      app/views/cost_reports/_group_by.rhtml
  2. 23
      assets/javascripts/reporting.js
  3. 11
      assets/javascripts/select_list_move_optgroup.js

@ -13,8 +13,8 @@
<option value=""></option>
<% grouped_gbs.each do |label , group_by_ary| %>
<optgroup label="<%= l(label) %>">
<% group_by_ary.select(&:display?).sort_by {|gb| l(gb.label)}.each do |group_by| %>
<option value="<%= group_by.underscore_name %>"><%= l(group_by.label)%></option>
<% group_by_ary.select(&:display?).sort_by {|gb| l(gb.label)}.each_with_index do |group_by, ix| %>
<option data-sort_by="<%= ix %>" value="<%= group_by.underscore_name %>"><%= l(group_by.label)%></option>
<% end %>
</optgroup>
<% end %>
@ -26,8 +26,8 @@
<option value=""></option>
<% grouped_gbs.each do |label , group_by_ary| %>
<optgroup label="<%= l(label) %>">
<% group_by_ary.select(&:display?).sort_by {|gb| l(gb.label)}.each do |group_by| %>
<option value="<%= group_by.underscore_name %>"><%= l(group_by.label)%></option>
<% group_by_ary.select(&:display?).sort_by {|gb| l(gb.label)}.each_with_index do |group_by, ix| %>
<option data-sort_by="<%= ix %>" value="<%= group_by.underscore_name %>"><%= l(group_by.label)%></option>
<% end %>
</optgroup>
<% end %>

@ -192,14 +192,31 @@ function restore_select_values(select, values) {
}
function select_active_group_bys() {
[$('group_by_columns'), $('group_by_rows')].each(function(select) {
selects = [$('group_by_columns'), $('group_by_rows')];
for (var j = 0; j < selects.length; j++) {
select = selects[j];
select.multiple = true;
var group_bys = new Array();
children = select.up().childNodes;
for (var i = 0; i < children.length; i++) {
if (children.item(i).className.include('group_by')) {
group_bys.push(children.item(i));
}
}
sort_group_bys(select, group_bys);
}
}
function sort_group_bys(select, group_bys) {
for (var k = 0; k < group_bys.length; k++) {
for (var i = 0; i < select.options.length; i++) {
if ($(select.options[i].value + "_" + select.id) !== null) {
if (group_bys[k].getAttribute('value') == select.options[i].value) {
select.options[i].setAttribute('data-sort_by', k);
select.options[i].selected = true;
sortOptions(select);
}
}
});
}
}
function reset_group_by_selects() {

@ -101,8 +101,15 @@ function selectAllOptions(select) {
// Returns true if the given select-box has optgroups.
// We assume that a possibly present optgroup is the first child element of the select-box.
function has_optgroups(theSel) {
theSel = $(theSel);
return (theSel.childElements().length > 0) && (theSel.down(0).tagName == "OPTGROUP");
theSel = $(theSel);
var hit;
for (var i = 0; i < theSel.childNodes.length; i++) {
if (theSel.childNodes.item(i).tagName == "OPTGROUP") {
hit = true;
break;
}
}
return (hit) && (theSel.childElements().length > 0);
}
// Compares two option elements (return -1 if a < b, if not return 1).

Loading…
Cancel
Save