available_values are now loaded on user request (ajax) - fixes #3490

git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1813 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
p.tessenow 14 years ago committed by jwollert
parent 74863dd77e
commit b2e571738c
  1. 10
      app/controllers/cost_reports_controller.rb
  2. 10
      app/helpers/reporting_helper.rb
  3. 5
      app/views/cost_reports/available_values.rhtml
  4. 11
      app/views/cost_reports/filters/_available_value.rhtml
  5. 8
      app/views/cost_reports/filters/_multi_values.rhtml
  6. 49
      assets/javascripts/reporting.js

@ -27,6 +27,16 @@ class CostReportsController < ApplicationController
redirect_to :action => :index
end
def available_values
filter = filter_class(params[:filter_name].to_s)
render_404 unless filter
@available_values = filter.available_values
respond_to do |format|
format.html { render :layout => !request.xhr? }
end
end
##
# Determines if the request contains filters to set
def set_filter? #FIXME: rename to set_query?

@ -144,4 +144,14 @@ module ReportingHelper
def show_row(row)
link_to_details(row) << row.render { |k,v| show_field(k,v) }
end
##
# Finds the Filter-Class for as specific filter name while being careful with the filter_name parameter as it is user input.
def filter_class(filter_name)
klass = CostQuery::Filter.const_get(filter_name.to_s.camelize)
return klass if klass.is_a? Class
nil
rescue NameError
return nil
end
end

@ -0,0 +1,5 @@
<% @available_values.each do |name, id, *args| %>
<%= render :partial => 'cost_reports/filters/available_value',
:locals => { :name => name, :id => id, :level => args.first },
:layout => !request.xhr? %>
<% end %>

@ -0,0 +1,11 @@
<%#
This partial requires the following locals:
name String: The displayed name of the option
id Integer: The id the option refers to
level Integer: The indendation level of this option
%>
<% name_prefix = ((level && level > 0) ? ('&nbsp;' * 2 * level + '&#187; ') : '') %>
<option value="<%= id %>">
<%= name_prefix + h(name) %>
</option>

@ -14,13 +14,7 @@
id="<%= element[:filter_name] %>_arg_1_val"
class="select-small"
multiple="multiple"> <%# multiple will be disabled/enabled later by JavaScript anyhow. We need to specify multiple here because of a IE6-bug. %>
<% element[:values].each do |name, id, *args| %>
<% level = args.first #nesting_level is optional for values %>
<% name_prefix = ((level && level > 0) ? ('&nbsp;' * 2 * level + '&#187; ') : '') %>
<option value="<%= id %>">
<%= name_prefix + h(name) %>
</option>
<% end %>
<%# content will be inserted on filter activation %>
</select>
<%= link_to_function image_tag('bullet_toggle_plus.png'), "toggle_multi_select($('#{element[:filter_name]}_arg_1_val'));", :style => "vertical-align: bottom;" %>
</div>

@ -89,6 +89,7 @@ function show_filter(field) {
var field_el = $('tr_' + field);
register_remove_hover(field);
if (field_el !== null) {
load_available_values_for_filter(field);
field_el.show();
toggle_filter(field);
$('rm_' + field).value = field;
@ -270,6 +271,54 @@ function disable_all_group_bys() {
});
}
function serialize_filter_and_group_by() {
var ret_str = Form.serialize('query_form');
var rows = Sortable.serialize('group_rows');
var columns = Sortable.serialize('group_columns');
if (rows !== null && rows != "") {
ret_str += "&" + rows;
}
if(columns !== null && columns != "") {
ret_str += "&" + columns;
}
return ret_str;
}
function init_group_bys() {
var options = {
tag:'span',
overlap:'horizontal',
constraint:'horizontal',
containment: ['group_columns','group_rows'],
//only: "group_by",
dropOnEmpty: true,
format: /^(.*)$/,
hoverclass: 'drag_container_accept'
};
Sortable.create('group_columns', options);
Sortable.create('group_rows', options);
}
function load_available_values_for_filter(filter_name) {
var select;
select = $('' + filter_name + '_arg_1_val');
if (select.childElements().length == 0) {
new Ajax.Updater({ success: select }, '/cost_reports/available_values', {
parameters: { filter_name: filter_name },
insertion: 'bottom',
evalScripts: false,
onCreate: function (a,b) {
$('operators_' + filter_name).disable();
$('' + filter_name + '_arg_1_val').disable();
},
onComplete: function (a,b) {
$('operators_' + filter_name).enable();
$('' + filter_name + '_arg_1_val').enable();
}
});
}
}
function defineElementGetter() {
if (document.getElementsByClassName == undefined) {
document.getElementsByClassName = function(className)

Loading…
Cancel
Save