Before Width: | Height: | Size: 51 B |
Before Width: | Height: | Size: 50 B |
Before Width: | Height: | Size: 51 B |
Before Width: | Height: | Size: 49 B |
Before Width: | Height: | Size: 51 B |
Before Width: | Height: | Size: 53 B |
Before Width: | Height: | Size: 53 B |
Before Width: | Height: | Size: 52 B |
Before Width: | Height: | Size: 937 B |
Before Width: | Height: | Size: 937 B |
Before Width: | Height: | Size: 937 B |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 3.0 KiB |
@ -1,151 +0,0 @@ |
||||
var NS4 = (navigator.appName === "Netscape" && parseInt(navigator.appVersion, 10) < 5); |
||||
|
||||
function createOption(theText, theValue, theCategory) { |
||||
var newOpt = document.createElement('option'); |
||||
newOpt.text = theText; |
||||
newOpt.value = theValue; |
||||
newOpt.setAttribute("data-category", theCategory); |
||||
return newOpt; |
||||
} |
||||
|
||||
function addOption(theSel, newOpt) |
||||
{ |
||||
var theCategory, opt_groups, i; |
||||
theCategory = newOpt.getAttribute("data-category"); |
||||
theSel = $(theSel); |
||||
if (theCategory && (theSel.childElements().length > 0) && theSel.down(0).tagName === "OPTGROUP") { // add the opt to the given category
|
||||
opt_groups = theSel.childElements(); |
||||
for (i = 0; i < opt_groups.length; i += 1) { |
||||
if (opt_groups[i].getAttribute("data-category") === theCategory) { |
||||
opt_groups[i].appendChild(newOpt); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
else { // no category given, just add the opt to the end of the select list
|
||||
theSel.appendChild(newOpt); |
||||
} |
||||
} |
||||
|
||||
function swapOptions(theSel, index1, index2) |
||||
{ |
||||
theSel = $(theSel); |
||||
var text, value, category; |
||||
text = theSel.options[index1].text; |
||||
value = theSel.options[index1].value; |
||||
category = theSel.options[index1].getAttribute("data-category"); |
||||
theSel.options[index1].text = theSel.options[index2].text; |
||||
theSel.options[index1].value = theSel.options[index2].value; |
||||
theSel.options[index1].setAttribute("data-category", theSel.options[index2].getAttribute("data-category")); |
||||
theSel.options[index2].text = text; |
||||
theSel.options[index2].value = value; |
||||
theSel.options[index2].setAttribute("data-category", category); |
||||
} |
||||
|
||||
function deleteOption(theSel, theIndex) |
||||
{ |
||||
theSel = $(theSel); |
||||
var selLength = theSel.length; |
||||
if (selLength > 0) |
||||
{ |
||||
theSel.options[theIndex] = null; |
||||
} |
||||
} |
||||
|
||||
// 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"); |
||||
} |
||||
|
||||
// Compares two option elements (return -1 if a < b, if not return 1).
|
||||
// If those elements have a 'data-sort_by' attribute, we compare that attribute.
|
||||
// If this is not the case we just compare their labels.
|
||||
function compareOptions(a, b) { |
||||
var a_cmp, b_cmp; |
||||
a_cmp = a.getAttribute("data-sort_by") ? a.getAttribute("data-sort_by") : a.text.toLowerCase(); |
||||
b_cmp = b.getAttribute("data-sort_by") ? b.getAttribute("data-sort_by") : b.text.toLowerCase(); |
||||
return (a_cmp < b_cmp) ? -1 : 1; |
||||
} |
||||
|
||||
// Sorts all elements of the given select-box.
|
||||
// If that select-box contains optgroups, the options are sorted for each optgroup separately.
|
||||
function sortOptions(theSel) { |
||||
theSel = $(theSel); |
||||
if (has_optgroups(theSel)) { |
||||
// handle each optgroup separately
|
||||
theSel.childElements().each(function (group) { |
||||
var sorted_elements; |
||||
// get all elements of this optgroup and sort them
|
||||
sorted_elements = $A(group.childElements()).sort(compareOptions); |
||||
// make optgroup empty
|
||||
$A(group.childElements()).each(function (o) { |
||||
$(o).remove(); |
||||
}); |
||||
// insert sorted elements into opgroup
|
||||
sorted_elements.each(function (o) { |
||||
$(group).insert({'bottom' : o}); |
||||
}); |
||||
}); |
||||
} |
||||
else { |
||||
// there is no optgroup, so just sort the options
|
||||
$A(theSel.options).sort(compareOptions).each(function (o, i) { |
||||
theSel.options[i] = o; |
||||
}); |
||||
} |
||||
} |
||||
|
||||
function moveOptions(theSelFrom, theSelTo) |
||||
{ |
||||
var selLength, selectedText, selectedValues, selectedCategories, selectedCount, i; |
||||
theSelFrom = $(theSelFrom); |
||||
theSelTo = $(theSelTo); |
||||
selLength = theSelFrom.length; |
||||
selectedText = []; |
||||
selectedValues = []; |
||||
selectedCategories = []; |
||||
selectedCount = 0; |
||||
|
||||
for (i = selLength - 1; i >= 0; i -= 1) { |
||||
if (theSelFrom.options[i].selected) |
||||
{ |
||||
addOption(theSelTo, theSelFrom.options[i].cloneNode(true)); |
||||
deleteOption(theSelFrom, i); |
||||
} |
||||
} |
||||
|
||||
if (has_optgroups(theSelTo)) { |
||||
sortOptions(theSelTo); |
||||
} |
||||
if (NS4) { |
||||
history.go(0); |
||||
} |
||||
} |
||||
|
||||
function moveOptionUp(theSel) { |
||||
theSel = $(theSel); |
||||
var index = theSel.selectedIndex; |
||||
if (index > 0) { |
||||
swapOptions(theSel, index - 1, index); |
||||
theSel.selectedIndex = index - 1; |
||||
} |
||||
} |
||||
|
||||
function moveOptionDown(theSel) { |
||||
theSel = $(theSel); |
||||
var index = theSel.selectedIndex; |
||||
if (index < theSel.length - 1) { |
||||
swapOptions(theSel, index, index + 1); |
||||
theSel.selectedIndex = index + 1; |
||||
} |
||||
} |
||||
|
||||
function selectAllOptions(select) |
||||
{ |
||||
select = $(select); |
||||
for (var i = 0; i < select.options.length; i += 1) { |
||||
select.options[i].selected = true; |
||||
} |
||||
} |
@ -1,114 +1,46 @@ |
||||
class Widget::GroupBys < Widget::Base |
||||
extend ProactiveAutoloader |
||||
|
||||
def render_row_1_with_columns |
||||
content_tag :tr do |
||||
tr = content_tag :td, " ", :colspan => "2" |
||||
tr += content_tag :td, :align => "center", :valign => "right" do |
||||
render_up_down_buttons("columns") |
||||
end |
||||
tr += content_tag :td, :valign => "middle" do |
||||
content_tag(:h3, "Columns") + selected_group_bys("columns") |
||||
end |
||||
end |
||||
end |
||||
|
||||
def render_row_2_with_up_down |
||||
content_tag :tr do |
||||
tr = content_tag :td, " " |
||||
tr += content_tag :td, :valign => "bottom", :style => "padding-bottom: 0;" do |
||||
content_tag :h3, "Rows" |
||||
end |
||||
tr += content_tag :td, " " |
||||
tr += content_tag :td, :align => "left", :valign => "left" do |
||||
render_move_buttons("columns", "Up", "Down") |
||||
end |
||||
end |
||||
end |
||||
|
||||
def render_row_3_with_rows_and_group_bys |
||||
content_tag :tr do |
||||
tr = content_tag :td, :align => "center", :valign => "top" do |
||||
render_up_down_buttons("rows") |
||||
end |
||||
tr += content_tag :td ,:style => "padding-left: 0pt;", :valign => "top" do |
||||
selected_group_bys("rows") |
||||
end |
||||
tr += content_tag :td, :align => "center", :valign => "top" do |
||||
render_move_buttons("rows", "Left", "Right", true) |
||||
end |
||||
tr += content_tag :td do |
||||
render_grouped_group_bys |
||||
end |
||||
end |
||||
end |
||||
|
||||
#TODO: replace me with a drag&drop group_by selector |
||||
def render |
||||
content_tag :div do |
||||
content_tag :table, :style => "border-collapse: collapse; border: 0pt none;", |
||||
:id => "group_by_table" do |
||||
content_tag :tbody do |
||||
render_row_1_with_columns + |
||||
render_row_2_with_up_down + |
||||
render_row_3_with_rows_and_group_bys |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
def selected_group_bys(axis) |
||||
content_tag :select, "", :style => "width: 180px;", :size => "4", |
||||
:name => "groups[#{axis}][]", :multiple => "multiple", |
||||
:id => "group_by_#{axis}" |
||||
end |
||||
|
||||
def render_up_down_buttons(axis) |
||||
render_sort_button(axis, "Up") + tag(:br) + render_sort_button(axis, "Down") |
||||
end |
||||
|
||||
def render_sort_button(axis, dir) |
||||
tag :input, :type => "button", :class => "buttons group_by sort sort#{dir} sort-#{axis}" |
||||
def render_options(group_by_ary) |
||||
group_by_ary.sort_by do |group_by| |
||||
l(group_by.label) |
||||
end.collect do |group_by| |
||||
next unless group_by.selectable? |
||||
content_tag :option, :value => group_by.underscore_name, :'data-label' => "#{l(group_by.label)}" do |
||||
l(group_by.label) |
||||
end |
||||
|
||||
def render_move_buttons(axis, to, from, br = false) |
||||
canvas = render_move_option_button(axis, to) |
||||
canvas += tag(:br) if br |
||||
canvas + render_move_option_button(axis, from) |
||||
end.join.html_safe |
||||
end |
||||
|
||||
def render_move_option_button(axis, dir) |
||||
tag :input, :type => "button", :class => "buttons group_by move move#{dir}" |
||||
def render_group(type, initially_selected) |
||||
initially_selected = initially_selected.map do |group_by| |
||||
[group_by.class.underscore_name, l(group_by.class.label)] |
||||
end |
||||
|
||||
def render_grouped_group_bys |
||||
content_tag :select, :style => "width: 180px;", :size => "9", :multiple => "multiple", :id => "group_by_container" do |
||||
engine::GroupBy.all_grouped.sort_by do |label, group_by_ary| |
||||
content_tag :div, |
||||
:id => "group_by_#{type}", |
||||
:class => 'drag_target drag_container', |
||||
:'data-initially-selected' => initially_selected.to_json.gsub('"', "'") do |
||||
content_tag :select, :id => "add_group_by_#{type}", :class => 'select-small' do |
||||
content = tag :option, :value => '' |
||||
content += engine::GroupBy.all_grouped.sort_by do |label, group_by_ary| |
||||
l(label) |
||||
end.collect do |label, group_by_ary| |
||||
content_tag :optgroup, :label => l(label), :"data-category" => label.to_s do |
||||
render_group_bys_for(group_by_ary, label) |
||||
content_tag :optgroup, :label => l(label) do |
||||
render_options group_by_ary |
||||
end |
||||
end.join.html_safe |
||||
content |
||||
end.html_safe |
||||
end |
||||
end |
||||
|
||||
def render_group_bys_for(group_by_ary, label) |
||||
group_by_ary.sort_by do |g| |
||||
l(g.label) |
||||
end.collect do |group_by| |
||||
next unless group_by.selectable? |
||||
render_group_by(group_by, :value => group_by.underscore_name, :"data-category" => label.to_s) |
||||
end.compact.join.html_safe |
||||
end |
||||
|
||||
def render_group_by(group_by, option_tag_options) |
||||
if grby = @query.group_bys.detect {|g| g.class == group_by } |
||||
option_tag_options[:"data-selected-axis"] = grby.type.to_s |
||||
option_tag_options[:"data-selected-index"] = @query.group_bys.index(grby) |
||||
end |
||||
content_tag :option, option_tag_options do |
||||
l(group_by.label) |
||||
def render |
||||
content_tag :div, :id => 'group_by_area' do |
||||
out = l(:label_columns) |
||||
out += render_group 'columns', @query.group_bys(:column) |
||||
out += l(:label_rows) |
||||
out += render_group 'rows', @query.group_bys(:row) |
||||
out.html_safe |
||||
end |
||||
end |
||||
end |
||||
|
@ -0,0 +1,114 @@ |
||||
class Widget::OldGroupBys < Widget::Base |
||||
extend ProactiveAutoloader |
||||
|
||||
def render_row_1_with_columns |
||||
content_tag :tr do |
||||
tr = content_tag :td, " ", :colspan => "2" |
||||
tr += content_tag :td, :align => "center", :valign => "right" do |
||||
render_up_down_buttons("columns") |
||||
end |
||||
tr += content_tag :td, :valign => "middle" do |
||||
content_tag(:h3, "Columns") + selected_group_bys("columns") |
||||
end |
||||
end |
||||
end |
||||
|
||||
def render_row_2_with_up_down |
||||
content_tag :tr do |
||||
tr = content_tag :td, " " |
||||
tr += content_tag :td, :valign => "bottom", :style => "padding-bottom: 0;" do |
||||
content_tag :h3, "Rows" |
||||
end |
||||
tr += content_tag :td, " " |
||||
tr += content_tag :td, :align => "left", :valign => "left" do |
||||
render_move_buttons("columns", "Up", "Down") |
||||
end |
||||
end |
||||
end |
||||
|
||||
def render_row_3_with_rows_and_group_bys |
||||
content_tag :tr do |
||||
tr = content_tag :td, :align => "center", :valign => "top" do |
||||
render_up_down_buttons("rows") |
||||
end |
||||
tr += content_tag :td ,:style => "padding-left: 0pt;", :valign => "top" do |
||||
selected_group_bys("rows") |
||||
end |
||||
tr += content_tag :td, :align => "center", :valign => "top" do |
||||
render_move_buttons("rows", "Left", "Right", true) |
||||
end |
||||
tr += content_tag :td do |
||||
render_grouped_group_bys |
||||
end |
||||
end |
||||
end |
||||
|
||||
#TODO: replace me with a drag&drop group_by selector |
||||
def render |
||||
content_tag :div do |
||||
content_tag :table, :style => "border-collapse: collapse; border: 0pt none;", |
||||
:id => "group_by_table" do |
||||
content_tag :tbody do |
||||
render_row_1_with_columns + |
||||
render_row_2_with_up_down + |
||||
render_row_3_with_rows_and_group_bys |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
def selected_group_bys(axis) |
||||
content_tag :select, "", :style => "width: 180px;", :size => "4", |
||||
:name => "groups[#{axis}][]", :multiple => "multiple", |
||||
:id => "group_by_#{axis}" |
||||
end |
||||
|
||||
def render_up_down_buttons(axis) |
||||
render_sort_button(axis, "Up") + tag(:br) + render_sort_button(axis, "Down") |
||||
end |
||||
|
||||
def render_sort_button(axis, dir) |
||||
tag :input, :type => "button", :class => "buttons group_by sort sort#{dir} sort-#{axis}" |
||||
end |
||||
|
||||
def render_move_buttons(axis, to, from, br = false) |
||||
canvas = render_move_option_button(axis, to) |
||||
canvas += tag(:br) if br |
||||
canvas + render_move_option_button(axis, from) |
||||
end |
||||
|
||||
def render_move_option_button(axis, dir) |
||||
tag :input, :type => "button", :class => "buttons group_by move move#{dir}" |
||||
end |
||||
|
||||
def render_grouped_group_bys |
||||
content_tag :select, :style => "width: 180px;", :size => "9", :multiple => "multiple", :id => "group_by_container" do |
||||
engine::GroupBy.all_grouped.sort_by do |label, group_by_ary| |
||||
l(label) |
||||
end.collect do |label, group_by_ary| |
||||
content_tag :optgroup, :label => l(label), :"data-category" => label.to_s do |
||||
render_group_bys_for(group_by_ary, label) |
||||
end |
||||
end.join.html_safe |
||||
end |
||||
end |
||||
|
||||
def render_group_bys_for(group_by_ary, label) |
||||
group_by_ary.sort_by do |g| |
||||
l(g.label) |
||||
end.collect do |group_by| |
||||
next unless group_by.selectable? |
||||
render_group_by(group_by, :value => group_by.underscore_name, :"data-category" => label.to_s) |
||||
end.compact.join.html_safe |
||||
end |
||||
|
||||
def render_group_by(group_by, option_tag_options) |
||||
if grby = @query.group_bys.detect {|g| g.class == group_by } |
||||
option_tag_options[:"data-selected-axis"] = grby.type.to_s |
||||
option_tag_options[:"data-selected-index"] = @query.group_bys.index(grby) |
||||
end |
||||
content_tag :option, option_tag_options do |
||||
l(group_by.label) |
||||
end |
||||
end |
||||
end |