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