From b6bffb2c056c460effda3607c78d079b64e02dff Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 21 Jan 2009 12:35:55 -0800 Subject: [PATCH] Added the rest of the form for setting a rate on a project. #1923 --- lang/en.yml | 2 +- lib/rate_project_hook.rb | 65 ++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/lang/en.yml b/lang/en.yml index d731175..ddae1a4 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -6,4 +6,4 @@ rate_label_new_rate: New Rate rate_label_currency: $ rate_error_user_not_found: User not found rate_label_set_rate: Set Rate - +rate_label_default: Default Rate diff --git a/lib/rate_project_hook.rb b/lib/rate_project_hook.rb index 6aef975..503363d 100644 --- a/lib/rate_project_hook.rb +++ b/lib/rate_project_hook.rb @@ -25,31 +25,50 @@ class RateProjectHook < Redmine::Hook::ViewListener 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;') + content = '' - 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)) + if rate.nil? || rate.default? + if rate && rate.default? + content << "#{number_to_currency(rate.amount)} " + end - form << submit_tag(l(:rate_label_set_rate), :class => "small") - - return content_tag(:td, form, :align => 'left', :id => "rate_#{project.id}_#{member.user.id}" ) + 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") + + content << form + else + content << content_tag(:strong, link_to(number_to_currency(rate.amount), { + :controller => 'users', + :action => 'edit', + :id => member.user, + :tab => 'rates', + :protocol => Setting.protocol, + :host => Setting.host_name + })) + + end + return content_tag(:td, content, :align => 'left', :id => "rate_#{project.id}_#{member.user.id}" ) end end