1 # Provides a link to the document on the platform
2 class IssuesPublicationHook < Redmine::Hook::ViewListener
4 def self.render_on(hook, options={})
5 define_method hook do |context|
6 if !options.include?(:if) || evaluate_if_option(options[:if], context)
7 context[:controller].send(:render_to_string, {:locals => context}.merge(options))
14 def evaluate_if_option(if_option, context)
17 send(if_option, context)
19 if_option.call(context)
23 def is_pticket?(context)
24 context[:issue].project_id == Setting.plugin_redmine_publications[:project].to_i
29 render_on :view_issues_show_details_bottom, :partial => 'issue_view_pub', :if => :is_pticket?
30 render_on :view_issues_form_details_bottom, :partial => 'issue_form_pub', :if => :is_pticket?
32 # names = context[:issue].publication_names {|name| "<span>" + name + "</span>"}
33 # result << names.join(', ')
35 def controller_issues_edit_before_save(context)
37 old_value = context[:issue].publication_names
38 new_value = context[:params][:publications].split(',').map { |n| n.strip }
39 context[:journal].details << JournalDetail.new(
40 :property => 'attr', :prop_key => "publications",
41 :old_value => old_value.join(', '),
42 :value => new_value.join(', ') ) unless new_value==old_value
43 context[:issue].publication_names = new_value
48 def controller_issues_new_after_save(context)
50 value = context[:params][:publications].split(',').map { |n| n.strip }
51 context[:issue].publication_names = value