comparison vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb @ 677:ec6c2f6a33c4 feature_36

Transplant rev fccacd8505e3 from live branch
author Chris Cannam
date Tue, 13 Sep 2011 17:18:00 +0100
parents 4fcd6ca1825c
children 31739bb8e563 c3e6c51170fa
comparison
equal deleted inserted replaced
676:4fcd6ca1825c 677:ec6c2f6a33c4
3 3
4 class PublicationsController < ApplicationController 4 class PublicationsController < ApplicationController
5 unloadable 5 unloadable
6 6
7 model_object Publication 7 model_object Publication
8 before_filter :find_model_object, :except => [:new, :create, :index, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ] 8 before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
9 before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ] 9 before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ]
10 10
11 def new 11 def new
12 find_project_by_project_id 12 find_project_by_project_id
13 @publication = Publication.new 13 @publication = Publication.new
60 if bibtex_entry 60 if bibtex_entry
61 parse_bibtex_list bibtex_entry 61 parse_bibtex_list bibtex_entry
62 end 62 end
63 end 63 end
64 64
65 def get_bibtex_required_fields
66 all_fields = ["editor", "publisher", "chapter", "pages", "volume", "series", "address", "edition", "year", "note", "institution", "type", "number", "month", "journal", "howpublished", "key", "school"]
67
68 fields = Hash.new
69 fields[ 'article' ] = [ 'journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ]
70 fields[ 'book' ] = [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ]
71 fields[ 'booklet' ] = [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ]
72 fields[ 'conference' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
73 fields[ 'inbook' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
74 fields[ 'incollection' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
75 fields[ 'inproceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
76 fields[ 'manual' ] = [ 'organization', 'address', 'edition', 'month', 'year', 'note' ]
77 fields[ 'masterthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
78 fields[ 'misc' ] = [ 'howpublished', 'month', 'year', 'note' ]
79 fields[ 'phdthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
80 fields[ 'proceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
81 fields[ 'techreport' ] = [ 'institution', 'year', 'type', 'number', 'address', 'month', 'note' ]
82 fields[ 'unpublished' ] = [ 'note', 'month', 'year' ]
83
84 entrytype = BibtexEntryType.find(params[:value]).name
85
86 respond_to do |format|
87 format.js {
88 render(:update) {|page|
89 all_fields.each do |field|
90
91
92
93 unless fields[entrytype].include? field
94 page["publication_bibtex_entry_attributes_#{field}"].up('p').hide()
95 else
96 page["publication_bibtex_entry_attributes_#{field}"].up('p').show()
97 end
98 end
99 }
100 }
101 end
102 end
103
65 def add_author 104 def add_author
66 if (request.xhr?) 105 if (request.xhr?)
67 render :text => User.find(params[:user_id]).name 106 render :text => User.find(params[:user_id]).name
68 else 107 else
69 # No? Then render an action. 108 # No? Then render an action.
70 #render :action => 'view_attribute', :attr => @name 109 #render :action => 'view_attribute', :attr => @name
71 logger.error { "ERRO ADD AUTHOR" } 110 logger.error { "Error while adding Author to publication." }
72 end 111 end
73 end 112 end
74 113
75 def edit 114 def edit
76 find_project_by_project_id unless params[:project_id].nil? 115 find_project_by_project_id unless params[:project_id].nil?
247 institution_field = "publication_authorships_attributes_#{object_id}_institution".to_sym 286 institution_field = "publication_authorships_attributes_#{object_id}_institution".to_sym
248 287
249 yes_radio = "publication_authorships_attributes_#{object_id}_identify_author_yes".to_sym 288 yes_radio = "publication_authorships_attributes_#{object_id}_identify_author_yes".to_sym
250 289
251 respond_to do |format| 290 respond_to do |format|
252 format.js {logger.error { "JS" } 291 format.js {
253 render(:update) {|page| 292 render(:update) {|page|
254 page[name_field].value = item.name 293 page[name_field].value = item.name
255 page[email_field].value = item.mail 294 page[email_field].value = item.mail
256 page[institution_field].value = item.institution 295 page[institution_field].value = item.institution
257 296