From 9a66fe30af923817e9b46a14043ff4dadfa20fc6 Mon Sep 17 00:00:00 2001 From: jwollert Date: Thu, 11 Nov 2010 18:51:13 +0100 Subject: [PATCH] ajax action to save queries --- .../controllers/cost_reports_controller.rb | 12 +++++++-- .../app/views/cost_reports/index.rhtml | 25 +++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/redmine_reporting/app/controllers/cost_reports_controller.rb b/redmine_reporting/app/controllers/cost_reports_controller.rb index 15f0aaa41f..e6b84ab0fc 100644 --- a/redmine_reporting/app/controllers/cost_reports_controller.rb +++ b/redmine_reporting/app/controllers/cost_reports_controller.rb @@ -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 diff --git a/redmine_reporting/app/views/cost_reports/index.rhtml b/redmine_reporting/app/views/cost_reports/index.rhtml index c96e50323e..8ec20e5d2d 100644 --- a/redmine_reporting/app/views/cost_reports/index.rhtml +++ b/redmine_reporting/app/views/cost_reports/index.rhtml @@ -29,18 +29,21 @@ <%= render :partial => 'restore_query', :locals => {:f => query_form, :query => @query} %>

<%= link_to_remote "#{l(:button_apply)}", - { :url => { :set_filter => 1 }, - :before => 'selectAllOptions("group_by_rows");selectAllOptions("group_by_columns");', - :condition => 'Ajax.activeRequestCount === 0', - :update => "content", - :with => "Form.serialize('query_form')", - :eval_scripts => true - }, :class => 'button apply' %> + { :url => { :set_filter => 1 }, + :before => 'selectAllOptions("group_by_rows");selectAllOptions("group_by_columns");', + :condition => 'Ajax.activeRequestCount === 0', + :update => "content", + :with => "Form.serialize('query_form')", + :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 %>