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
|