X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/2e4974b1f5600a3a446d5b0844a8d63d9fb5fbb3..ad481d9335cb91f56adfffda3999284f37d37942:/redmine/redmine_publications/lib/issue_publication_hook.rb?ds=inline
diff --git a/redmine/redmine_publications/lib/issue_publication_hook.rb b/redmine/redmine_publications/lib/issue_publication_hook.rb
index 4cfc3ba5..6d2101cf 100644
--- a/redmine/redmine_publications/lib/issue_publication_hook.rb
+++ b/redmine/redmine_publications/lib/issue_publication_hook.rb
@@ -1,16 +1,55 @@
# Provides a link to the document on the platform
class IssuesPublicationHook < Redmine::Hook::ViewListener
- def view_issues_show_details_bottom(context)
- result = "
Source File(s): | "
- names = context[:issue].source_files.map {|name| "" + name + ""}
- result << names.join(', ')
- result + " |
"
+
+ def self.render_on(hook, options={})
+ define_method hook do |context|
+ if !options.include?(:if) || evaluate_if_option(options[:if], context)
+ context[:controller].send(:render_to_string, {:locals => context}.merge(options))
+ end
+ end
+ end
+
+ private
+
+ def evaluate_if_option(if_option, context)
+ case if_option
+ when Symbol
+ send(if_option, context)
+ when Method, Proc
+ if_option.call(context)
+ end
+ end
+
+ def is_pticket?(context)
+ context[:issue].tracker_id == Setting.plugin_redmine_publications[:tracker].to_i
end
+ public
+
+ render_on :view_issues_show_details_bottom, :partial => 'issue_view_pub', :if => :is_pticket?
+ render_on :view_issues_form_details_bottom, :partial => 'issue_form_pub', :if => :is_pticket?
+
+ # names = context[:issue].publication_names {|name| "" + name + ""}
+ # result << names.join(', ')
+
def controller_issues_edit_before_save(context)
- pub_field = context[:params][:issue_source_files]
- context[:issue].source_files = pub_field
+ if is_pticket?context
+ old_value = context[:issue].publication_names
+ new_value = context[:params][:publications].split(',').map { |n| n.strip }
+ context[:journal].details << JournalDetail.new(
+ :property => 'attr', :prop_key => "publications",
+ :old_value => old_value.join(', '),
+ :value => new_value.join(', ') ) unless new_value==old_value
+ context[:issue].publication_names = new_value
+ end
end
- render_on :view_issues_form_details_bottom, :partial => 'issue_form_pub'
+
+ def controller_issues_new_after_save(context)
+ if is_pticket?context
+ value = context[:params][:publications].split(',').map { |n| n.strip }
+ context[:issue].publication_names = value
+ context[:issue].save
+ end
+ end
end