From 05501f3eb6c7d50c8e1872a5c78dbe83538c99a5 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 21 Jan 2009 12:15:44 -0800 Subject: [PATCH] Ported the basics for the Rate form from the Budget plugin. #1923 --- lib/rate_project_hook.rb | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/rate_project_hook.rb b/lib/rate_project_hook.rb index 874af57..f7b3dce 100644 --- a/lib/rate_project_hook.rb +++ b/lib/rate_project_hook.rb @@ -1,6 +1,6 @@ # Hooks to attach to the Redmine Projects. class RateProjectHook < Redmine::Hook::ViewListener - + def protect_against_forgery? false end @@ -14,5 +14,42 @@ class RateProjectHook < Redmine::Hook::ViewListener return "#{l(:rate_label_rate)} #{l(:rate_label_currency)}" end + # Renders an AJAX from to update the member's billing rate + # + # Context: + # * :project => Current project + # * :member => Current Member record + # + def view_projects_settings_members_table_row(context = { }) + member = context[:member] + project = context[:project] + rate = Rate.for(member.user, project) + + url = { + :controller => 'rates', + :action => 'create', + :method => :post, + :protocol => Setting.protocol, + :host => Setting.host_name + } + # Build a form_remote_tag by hand since this isn't in the scope of a controller + # and url_rewriter doesn't like that fact. + form = form_tag(url, :onsubmit => remote_function(:url => url, + :host => Setting.host_name, + :protocol => Setting.protocol, + :form => true, + :method => 'post', + :return => 'false' )+ '; return false;') + + form << text_field(:rate, :amount) + form << hidden_field(:rate,:date_in_effect, :value => Date.today.to_s) + form << hidden_field(:rate, :project_id, :value => project.id) + form << hidden_field(:rate, :user_id, :value => member.user.id) + form << hidden_field_tag("back_url", url_for(:controller => 'projects', :action => 'settings', :id => project, :tab => 'members', :protocol => Setting.protocol, :host => Setting.host_name)) + + form << submit_tag(l(:rate_label_set_rate), :class => "small") + + return content_tag(:td, form, :align => 'center' ) + end end