To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vendor / plugins / redmine_bibliography / app / helpers / publications_helper.rb @ 1072:872db7098cb9
History | View | Annotate | Download (4.61 KB)
| 1 | 615:c4ddb9531f4c | chris | # -*- coding: utf-8 -*-
|
|---|---|---|---|
| 2 | 407:96910efbd45e | luis | require 'bibtex'
|
| 3 | |||
| 4 | 328:aed18b463206 | luis | module PublicationsHelper |
| 5 | 702:3eb64cb3c7ac | chris | include AuthorshipsHelper
|
| 6 | 616:156bd1153f47 | luis | |
| 7 | def link_to_publication(publication, options={}, html_options = nil) |
||
| 8 | url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
|
||
| 9 | link_to(h(publication.title), url, html_options) |
||
| 10 | end
|
||
| 11 | |||
| 12 | 462:b02b2eb2a312 | luis | def projects_check_box_tags(name, projects) |
| 13 | s = ''
|
||
| 14 | projects.sort.each do |project|
|
||
| 15 | 1068:e11d8d13ebc5 | luis | if User.current.allowed_to?(:edit_publication, project) |
| 16 | 713:ebca856bd627 | luis | s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
|
| 17 | s << '<br />'
|
||
| 18 | end
|
||
| 19 | 462:b02b2eb2a312 | luis | end
|
| 20 | 712:a1e0728d1e02 | luis | |
| 21 | 1068:e11d8d13ebc5 | luis | s |
| 22 | 462:b02b2eb2a312 | luis | end
|
| 23 | 1068:e11d8d13ebc5 | luis | |
| 24 | 595:84e8d34d024c | luis | def choose_author_link(object_name, items) |
| 25 | 592:68c6b060385c | luis | # called by autocomplete_for_author (publications' action/view)
|
| 26 | # creates the select list based on the results array
|
||
| 27 | # results is an array with both Users and Authorships objects
|
||
| 28 | 1068:e11d8d13ebc5 | luis | |
| 29 | 594:7234e0a90c62 | luis | @author_options = []
|
| 30 | 592:68c6b060385c | luis | @results.each do |result| |
| 31 | 647:525f48af3f54 | chris | email_bit = result.mail.partition('@')[2] |
| 32 | if email_bit != "": |
||
| 33 | email_bit = "(@#{email_bit})"
|
||
| 34 | end
|
||
| 35 | @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"] |
||
| 36 | 592:68c6b060385c | luis | end
|
| 37 | 1068:e11d8d13ebc5 | luis | |
| 38 | 595:84e8d34d024c | luis | if @results.size > 0 |
| 39 | s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(@author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} ) |
||
| 40 | s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q') |
||
| 41 | else
|
||
| 42 | s = "<em>No Authors found that match your search… sorry!</em>"
|
||
| 43 | 1068:e11d8d13ebc5 | luis | end
|
| 44 | 478:7097dc91e58e | luis | end
|
| 45 | |||
| 46 | 469:ae87ae455cfb | luis | def link_to_remove_fields(name, f) |
| 47 | 573:aed210f6095b | chris | f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') |
| 48 | 469:ae87ae455cfb | luis | end
|
| 49 | 1068:e11d8d13ebc5 | luis | |
| 50 | 705:b6f9f005c0b6 | luis | def link_to_add_author_fields(name, f, association, action) |
| 51 | 468:0bb9c7baed07 | luis | new_object = f.object.class.reflect_on_association(association).klass.new |
| 52 | fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| |
||
| 53 | render(association.to_s.singularize + "_fields", :f => builder) |
||
| 54 | 1068:e11d8d13ebc5 | luis | end
|
| 55 | 705:b6f9f005c0b6 | luis | link_to_function(name, h("add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')"), { :class => 'icon icon-add', :id => "add_another_author" }) |
| 56 | 1068:e11d8d13ebc5 | luis | end
|
| 57 | 481:dd242ea99fd3 | luis | |
| 58 | def sanitized_object_name(object_name) |
||
| 59 | object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") |
||
| 60 | end
|
||
| 61 | |||
| 62 | def sanitized_method_name(method_name) |
||
| 63 | method_name.sub(/\?$/, "") |
||
| 64 | end
|
||
| 65 | 1068:e11d8d13ebc5 | luis | |
| 66 | 595:84e8d34d024c | luis | def form_tag_name(object_name, method_name) |
| 67 | str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
|
||
| 68 | 1068:e11d8d13ebc5 | luis | str.to_sym |
| 69 | 595:84e8d34d024c | luis | end
|
| 70 | 1068:e11d8d13ebc5 | luis | |
| 71 | def form_tag_id(object_name, method_name) |
||
| 72 | 481:dd242ea99fd3 | luis | str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
|
| 73 | str.to_sym |
||
| 74 | end
|
||
| 75 | 1068:e11d8d13ebc5 | luis | |
| 76 | 596:fcff84e1c1ce | luis | def form_object_id(object_name) |
| 77 | str = object_name.split("\[").last().gsub("\]","") |
||
| 78 | str.to_sym |
||
| 79 | end
|
||
| 80 | 693:5163e3ec00b8 | luis | |
| 81 | 1068:e11d8d13ebc5 | luis | def render_authorships_list(publication) |
| 82 | 693:5163e3ec00b8 | luis | s = '<p>'
|
| 83 | 1068:e11d8d13ebc5 | luis | |
| 84 | 693:5163e3ec00b8 | luis | publication.authorships.each do |authorship|
|
| 85 | 702:3eb64cb3c7ac | chris | s << link_to_authorship(authorship) |
| 86 | 693:5163e3ec00b8 | luis | s << "<br /><em>#{authorship.institution}</em></p>"
|
| 87 | 1068:e11d8d13ebc5 | luis | end
|
| 88 | 693:5163e3ec00b8 | luis | |
| 89 | 1068:e11d8d13ebc5 | luis | s |
| 90 | 693:5163e3ec00b8 | luis | end
|
| 91 | 1068:e11d8d13ebc5 | luis | |
| 92 | def render_projects_list(publication, show_delete_icon) |
||
| 93 | 691:f8d7e85ccd4e | luis | s= ""
|
| 94 | 1068:e11d8d13ebc5 | luis | |
| 95 | 691:f8d7e85ccd4e | luis | publication.projects.visible.each do |proj|
|
| 96 | 629:f9470a59e5da | luis | s << link_to_project(proj, {}, :class => 'publication_project')
|
| 97 | 1068:e11d8d13ebc5 | luis | |
| 98 | if show_delete_icon
|
||
| 99 | 691:f8d7e85ccd4e | luis | if User.current.allowed_to?(:edit_publication, @project) |
| 100 | if @project == proj |
||
| 101 | 945:75351d69e2ba | luis | # todo: move this message to yml file
|
| 102 | 691:f8d7e85ccd4e | luis | confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
|
| 103 | else
|
||
| 104 | confirm_msg = false
|
||
| 105 | 1068:e11d8d13ebc5 | luis | end
|
| 106 | |||
| 107 | s << link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_project', :id => publication, :remove_project_id => proj, :project_id => @project }, :method => :post, :confirm => confirm_msg }, :class => 'icon icon-del') |
||
| 108 | 691:f8d7e85ccd4e | luis | end
|
| 109 | 629:f9470a59e5da | luis | end
|
| 110 | 691:f8d7e85ccd4e | luis | |
| 111 | 1068:e11d8d13ebc5 | luis | s << "<br />"
|
| 112 | end
|
||
| 113 | |||
| 114 | s |
||
| 115 | 541:c3abeb11bc2e | luis | end
|
| 116 | 1068:e11d8d13ebc5 | luis | |
| 117 | def print_ieee_format(publication) |
||
| 118 | Rails.cache.fetch("publication-#{publication.id}-ieee") do |
||
| 119 | publication.print_entry(:ieee)
|
||
| 120 | end
|
||
| 121 | 946:a0c9cc95bcf3 | luis | end
|
| 122 | 1068:e11d8d13ebc5 | luis | |
| 123 | def print_bibtex_format(publication) |
||
| 124 | Rails.cache.fetch("publication-#{publication.id}-bibtex") do |
||
| 125 | publication.print_entry(:bibtex)
|
||
| 126 | end
|
||
| 127 | 945:75351d69e2ba | luis | end
|
| 128 | 1068:e11d8d13ebc5 | luis | |
| 129 | |||
| 130 | 544:f05f3a9ef569 | luis | def show_bibtex_fields(bibtex_entry) |
| 131 | s = ""
|
||
| 132 | 615:c4ddb9531f4c | chris | bibtex_entry.attributes.keys.sort.each do |key|
|
| 133 | value = bibtex_entry.attributes[key].to_s |
||
| 134 | next if key == 'id' or key == 'publication_id' or value == "" |
||
| 135 | 1068:e11d8d13ebc5 | luis | s << "<h4>" + l("field_#{key}") + "</h4>" |
| 136 | 615:c4ddb9531f4c | chris | s << "<p>"
|
| 137 | if key == "entry_type" |
||
| 138 | s << bibtex_entry.entry_type_label |
||
| 139 | else
|
||
| 140 | s << value |
||
| 141 | 544:f05f3a9ef569 | luis | end
|
| 142 | 615:c4ddb9531f4c | chris | s << "</p>"
|
| 143 | 544:f05f3a9ef569 | luis | end
|
| 144 | s |
||
| 145 | 1068:e11d8d13ebc5 | luis | end
|
| 146 | 328:aed18b463206 | luis | end
|