From 6835ec59dceefc7d5572d58bc910a70a02027f70 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 27 May 2008 16:47:00 -0700 Subject: [PATCH] Registering hooks for the issues. #1147 --- init.rb | 12 ++++++++++-- lib/budget_issue_hook.rb | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 lib/budget_issue_hook.rb diff --git a/init.rb b/init.rb index 4d94f7a..6cb49ab 100644 --- a/init.rb +++ b/init.rb @@ -4,6 +4,9 @@ require 'redmine' require_dependency 'issue_patch' require_dependency 'query_patch' +# Hooks +require_dependency 'budget_issue_hook' + RAILS_DEFAULT_LOGGER.info 'Starting Budget plugin for RedMine' Redmine::Plugin.register :budget_plugin do @@ -25,6 +28,11 @@ 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(:project_member_list_header, BudgetProjectHook.member_list_header) +# add_hook(:project_member_list_column_three, BudgetProjectHook.member_list_column_three) end - - diff --git a/lib/budget_issue_hook.rb b/lib/budget_issue_hook.rb new file mode 100644 index 0000000..53fff54 --- /dev/null +++ b/lib/budget_issue_hook.rb @@ -0,0 +1,35 @@ +class BudgetIssueHook + + # http://snippets.dzone.com/posts/show/1799 + def self.help + Helper.instance + end + + class Helper + include Singleton + include ActionView::Helpers::TagHelper + include ActionView::Helpers::FormHelper + include ActionView::Helpers::FormTagHelper + include ActionView::Helpers::FormOptionsHelper + end + + def self.issue_show(context = { }) + # TODO: Escape + data = "Deliverable :#{context[:issue].deliverable.subject unless context[:issue].deliverable.nil?}" + return "#{data}" + end + + def self.issue_edit(context = { }) + select = context[:form].select :deliverable_id, Deliverable.find_all_by_project_id(context[:project]).collect { |d| [d.subject, d.id] }, :include_blank => true + return "

#{select}

" + end + + def self.issue_bulk_edit(context = { }) + 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, :id, :subject), :id, :subject)) + + return help.content_tag(:p, "") + end +end