ajax action to save queries

pull/6827/head
jwollert 14 years ago
parent 06d352035e
commit 9a66fe30af
  1. 12
      redmine_reporting/app/controllers/cost_reports_controller.rb
  2. 11
      redmine_reporting/app/views/cost_reports/index.rhtml

@ -3,6 +3,7 @@ class CostReportsController < ApplicationController
before_filter :find_optional_project, :only => [:index, :drill_down]
before_filter :generate_query, :only => [:index, :drill_down]
before_filter :set_cost_types, :only => [:index, :drill_down]
before_filter :save_query, :only => [:index, :drill_down]
rescue_from Exception do |exception|
session.delete(:cost_query)
@ -15,8 +16,7 @@ class CostReportsController < ApplicationController
include ReportingHelper
def index
@valid = valid_query?
if @valid
if @valid = valid_query?
if @query.group_bys.empty?
@table_partial = "cost_entry_table"
elsif @query.depth_of(:column) + @query.depth_of(:row) == 1
@ -206,6 +206,14 @@ class CostReportsController < ApplicationController
end
end
def save_query
return unless params[:save_query].to_i == 1 || !User.current.allowed_to?(:save_queries, @project, :global => true)
# TODO render some form instead of just guessing values!
@query.name ||= @query.hash
@query.user_id ||= User.current.id
@query.save!
end
def load_all
CostQuery::GroupBy.all
CostQuery::Filter.all

@ -37,10 +37,13 @@
:eval_scripts => true
}, :class => 'button apply' %>
<%= link_to_function l(:button_clear), "disable_all_filters(); disable_all_group_bys();", :class => 'icon icon-reload' %>
<% if User.current.allowed_to?(:save_queries, @project, :global => true) %>
<%
#link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save'
%>
<% if User.current.allowed_to?(:save_queries, @project, :global => true) && @valid %>
<%= link_to_remote l(:button_save),
{ :url => { :save_query => 1 },
:before => 'selectAllOptions("group_by_rows");selectAllOptions("group_by_columns");',
:with => "Form.serialize('query_form')",
:eval_scripts => true
}, :class => 'icon icon-save' %>
<% end %>
</p>
</div>

Loading…
Cancel
Save