Ported plugin hooks to the final Redmine Plugin hook API. #1431

This commit is contained in:
Eric Davis
2008-09-09 18:39:11 -07:00
parent 52873f5b9b
commit 802df93318
3 changed files with 27 additions and 34 deletions

11
init.rb
View File

@@ -6,6 +6,7 @@ require_dependency 'query_patch'
# Hooks
require_dependency 'budget_issue_hook'
require_dependency 'budget_project_hook'
RAILS_DEFAULT_LOGGER.info 'Starting Budget plugin for RedMine'
@@ -28,14 +29,4 @@ Redmine::Plugin.register :budget_plugin do
end
menu :project_menu, :budget, :controller => "deliverables", :action => 'index'
add_hook(:issue_show, Proc.new { |context| BudgetIssueHook.issue_show(context) })
add_hook(:issue_edit, Proc.new { |context| BudgetIssueHook.issue_edit(context) })
add_hook(:issue_bulk_edit, Proc.new { |context| BudgetIssueHook.issue_bulk_edit(context) })
add_hook(:issue_bulk_edit_save, Proc.new { |context| BudgetIssueHook.issue_bulk_edit_save(context) })
add_hook(:project_member_list_header, Proc.new { |context| BudgetProjectHook.member_list_header(context) })
add_hook(:project_member_list_column_three, Proc.new { |context| BudgetProjectHook.member_list_column_three(context) })
add_hook(:issues_helper_show_details, Proc.new { |context| BudgetIssueHook.issue_helper_show_details(context) })
end

View File

@@ -1,15 +1,14 @@
# Hooks to attach to the Redmine Issues. They are attached in init.rb by the
# +add_hook+ method
class BudgetIssueHook < Redmine::Plugin::Hook::Base
# Hooks to attach to the Redmine Issues.
class BudgetIssueHook < Redmine::Hook::ViewListener
# Renders the Deliverable subject
#
# Context:
# * :issue => Issue being rendered
#
def self.issue_show(context = { })
def view_issues_show_details_bottom(context = { })
if context[:project].module_enabled?('budget_module')
data = "<td><b>Deliverable :</b></td><td>#{help.html_escape context[:issue].deliverable.subject unless context[:issue].deliverable.nil?}</td>"
data = "<td><b>Deliverable :</b></td><td>#{html_escape context[:issue].deliverable.subject unless context[:issue].deliverable.nil?}</td>"
return "<tr>#{data}<td></td></tr>"
else
return ''
@@ -22,7 +21,7 @@ class BudgetIssueHook < Redmine::Plugin::Hook::Base
# * :form => Edit form
# * :project => Current project
#
def self.issue_edit(context = { })
def view_issues_form_details_bottom(context = { })
if context[:project].module_enabled?('budget_module')
select = context[:form].select :deliverable_id, Deliverable.find_all_by_project_id(context[:project], :order => 'subject ASC').collect { |d| [d.subject, d.id] }, :include_blank => true
return "<p>#{select}</p>"
@@ -36,14 +35,14 @@ class BudgetIssueHook < Redmine::Plugin::Hook::Base
# Context:
# * :project => Current project
#
def self.issue_bulk_edit(context = { })
def view_issues_bulk_edit_details_bottom(context = { })
if context[:project].module_enabled?('budget_module')
select = help.select_tag('deliverable_id',
help.content_tag('option', GLoc.l(:label_no_change_option), :value => '') +
help.content_tag('option', GLoc.l(:label_none), :value => 'none') +
help.options_from_collection_for_select(Deliverable.find_all_by_project_id(context[:project].id, :order => 'subject ASC'), :id, :subject))
select = select_tag('deliverable_id',
content_tag('option', GLoc.l(:label_no_change_option), :value => '') +
content_tag('option', GLoc.l(:label_none), :value => 'none') +
options_from_collection_for_select(Deliverable.find_all_by_project_id(context[:project].id, :order => 'subject ASC'), :id, :subject))
return help.content_tag(:p, "<label>#{GLoc.l(:field_deliverable)}: " + select + "</label>")
return content_tag(:p, "<label>#{GLoc.l(:field_deliverable)}: " + select + "</label>")
else
return ''
end
@@ -55,7 +54,7 @@ class BudgetIssueHook < Redmine::Plugin::Hook::Base
# * :issue => Issue being saved
# * :params => HTML parameters
#
def self.issue_bulk_edit_save(context = { })
def controller_issues_bulk_edit_before_save(context = { })
case true
when context[:params][:deliverable_id].blank?
@@ -76,7 +75,7 @@ class BudgetIssueHook < Redmine::Plugin::Hook::Base
# Context:
# * :detail => Detail about the journal change
#
def self.issue_helper_show_details(context = { })
def helper_issues_show_detail_after_setting(context = { })
# TODO Later: Overwritting the caller is bad juju
if context[:detail].prop_key == 'deliverable_id'
d = Deliverable.find_by_id(context[:detail].value)

View File

@@ -1,11 +1,14 @@
# Hooks to attach to the Redmine Projects. They are attached in init.rb by the
# +add_hook+ method
class BudgetProjectHook < Redmine::Plugin::Hook::Base
# Hooks to attach to the Redmine Projects.
class BudgetProjectHook < Redmine::Hook::ViewListener
def protect_against_forgery?
false
end
# Renders an additional table header to the membership setting
#
# Context: none
def self.member_list_header(context ={ })
def view_projects_settings_members_table_header(context ={ })
if context[:project].module_enabled?('budget_module')
return "<th>#{GLoc.l(:label_member_rate) }</th>"
else
@@ -18,11 +21,11 @@ class BudgetProjectHook < Redmine::Plugin::Hook::Base
# Context:
# * :member => Current Member record
#
def self.member_list_column_three(context = { })
def view_projects_settings_members_table_row(context = { })
if context[:project].module_enabled?('budget_module')
# Build a form_remote_tag by hand since this isn't in the scope of a controller
form = help.form_tag({:controller => 'members', :action => 'edit', :id => context[:member].id, :protocol => Setting.protocol, :host => Setting.host_name},
:onsubmit => help.remote_function(:url => {
form = form_tag({:controller => 'members', :action => 'edit', :id => context[:member].id, :protocol => Setting.protocol, :host => Setting.host_name},
:onsubmit => remote_function(:url => {
:controller => 'members',
:action => 'edit',
:id => context[:member].id,
@@ -34,10 +37,10 @@ class BudgetProjectHook < Redmine::Plugin::Hook::Base
:form => true,
:method => 'post',
:return => 'false' )+ '; return false;') +
help.text_field_tag('member[rate]', help.number_with_precision(context[:member].rate, 0), :class => "small") +
help.submit_tag(GLoc.l(:button_change), :class => "small") + "</form>"
text_field_tag('member[rate]', number_with_precision(context[:member].rate, 0), :class => "small") +
submit_tag(GLoc.l(:button_change), :class => "small") + "</form>"
return help.content_tag(:td, form, :align => 'center' )
return content_tag(:td, form, :align => 'center' )
else
return ''
end