diff vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb @ 675:fccacd8505e3 live

Incomplete solution for Feature #238 - some issues in toggling (specially in the edit view).
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 13 Sep 2011 17:02:51 +0100
parents f3e35d639aa4
children 31739bb8e563 c3e6c51170fa
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Sep 09 21:09:56 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Sep 13 17:02:51 2011 +0100
@@ -5,7 +5,7 @@
   unloadable
   
   model_object Publication
-  before_filter :find_model_object, :except => [:new, :create, :index, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]  
+  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 ]  
   before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ]
     
   def new
@@ -62,13 +62,52 @@
     end
   end
 
+  def get_bibtex_required_fields
+    all_fields = ["editor", "publisher", "chapter", "pages", "volume", "series", "address", "edition", "year", "note", "institution", "type", "number", "month", "journal", "howpublished", "key", "school"]
+
+    fields = Hash.new
+    fields[ 'article' ] = [ 'journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ]
+    fields[ 'book' ] = [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ]
+    fields[ 'booklet' ] = [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ]
+    fields[ 'conference' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
+    fields[ 'inbook' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
+    fields[ 'incollection' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
+    fields[ 'inproceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
+    fields[ 'manual' ] = [ 'organization', 'address', 'edition', 'month', 'year', 'note' ]
+    fields[ 'masterthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
+    fields[ 'misc' ] = [ 'howpublished', 'month', 'year', 'note' ]
+    fields[ 'phdthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
+    fields[ 'proceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
+    fields[ 'techreport' ] = [ 'institution', 'year', 'type', 'number', 'address', 'month', 'note' ]
+    fields[ 'unpublished' ] = [ 'note', 'month', 'year' ]
+
+    entrytype = BibtexEntryType.find(params[:value]).name
+    
+    respond_to do |format|
+      format.js {
+        render(:update) {|page| 
+          all_fields.each do |field|
+            
+            
+            
+            unless fields[entrytype].include? field
+                page["publication_bibtex_entry_attributes_#{field}"].up('p').hide()
+              else
+                page["publication_bibtex_entry_attributes_#{field}"].up('p').show()
+            end            
+          end
+        }
+      }
+    end
+  end
+
   def add_author
     if (request.xhr?)
       render :text => User.find(params[:user_id]).name
     else
       # No?  Then render an action.
       #render :action => 'view_attribute', :attr => @name
-      logger.error { "ERRO ADD AUTHOR" }
+      logger.error { "Error while adding Author to publication." }
     end
   end
 
@@ -249,7 +288,7 @@
     yes_radio = "publication_authorships_attributes_#{object_id}_identify_author_yes".to_sym
     
     respond_to do |format|
-      format.js {logger.error { "JS" }
+      format.js {
         render(:update) {|page| 
           page[name_field].value = item.name
           page[email_field].value = item.mail