changeset 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 97815d819fd3 6bbcfcb85e50
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb vendor/plugins/redmine_bibliography/assets/javascripts/authors.js
diffstat 5 files changed, 134 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Sep 13 17:17:27 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Sep 13 17:18:00 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
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb	Tue Sep 13 17:17:27 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb	Tue Sep 13 17:18:00 2011 +0100
@@ -1,21 +1,77 @@
+<p>
+  <label for="bibtex_entry_type"><%=l("field_entry_type")%> <span class="required">*</span></label>
+	<%= f.collection_select :entry_type, 
+	        BibtexEntryType.find(:all).reject { |x| x.redundant? }, 
+	        :id, 
+	        :label,  
+	        { :selected => @selected_bibtex_entry_type_id, :prompt => true },	           
+	        :onChange => remote_function( :url => { :controller => :publications, :action => :get_bibtex_required_fields}, :with => "'value=' + value" )	              
+	%>
+</p>
+<p> 
+  <%= f.text_field :year, :size => 4, :class => 'bibtex' %> 
+</p>
+<p> 
+  <%= f.text_field :chapter, :size => 15, :class => 'bibtex' %>  
+</p>  
+<p>   
+  <%= f.text_field :editor, :size => 33, :class => 'bibtex'  %>  
+</p>  
+<p>   
+  <%= f.text_field :booktitle, :size => 33, :class => 'bibtex'  %>  
+</p>  
+<p>   
+  <%= f.text_field :publisher,:size => 33, :class => 'bibtex'  %>  
+</p>  
+<p>   
+  <%= f.text_field :pages, :size => 12, :class => 'bibtex'  %>  
+</p>
+<p>
+ <%= f.text_field :address, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :annote, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :crossref, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :edition, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :eprint, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :howpublished, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :journal, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :key, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :note, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :number, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :organization, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :school, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :series, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :type, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :url, :class => 'bibtex' %>
+</p>
+<p>
+ <%= f.text_field :volume, :class => 'bibtex' %>
+</p>
 
-<p><label for="bibtex_entry_type"><%=l("field_entry_type")%> <span class="required">*</span></label>
-	<%= f.collection_select(:entry_type, BibtexEntryType.find(:all).reject { |x| x.redundant? }, :id, :label,  {:selected => @selected_bibtex_entry_type_id, :prompt => true})  %>
-    </p>
-    <p> 
-      <%= f.text_field :year, :size => 4 %> 
-    </p><p> 
-      <%= f.text_field :chapter, :size => 15 %>  
-    </p>  
-    <p>   
-      <%= f.text_field :editor, :size => 33  %>  
-    </p>  
-    <p>   
-      <%= f.text_field :booktitle,:size => 33  %>  
-    </p>  
-    <p>   
-      <%= f.text_field :publisher,:size => 33  %>  
-    </p>  
-    <p>   
-      <%= f.text_field :pages, :size => 12  %>  
-    </p>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Tue Sep 13 17:17:27 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Tue Sep 13 17:18:00 2011 +0100
@@ -1,6 +1,7 @@
 <% content_for :header_tags do %>
     <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %>
     <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
+    <%= javascript_tag 'Event.observe(window, "load", hide_all_empty_bibtex_fields);' %>
 <% end %>
 
 <h2><%=l(:label_publication_show)%></h2>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Tue Sep 13 17:17:27 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Tue Sep 13 17:18:00 2011 +0100
@@ -1,6 +1,7 @@
 <% content_for :header_tags do %>
     <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %>
     <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
+    <%= javascript_tag 'Event.observe(window, "load", hide_all_bibtex_required_fields);' %>
 <% end %>
 
 <h2><%=l(:label_publication_new)%></h2>
--- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Tue Sep 13 17:17:27 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Tue Sep 13 17:18:00 2011 +0100
@@ -29,11 +29,11 @@
 
 function toggle_input_field(field){	
     if (field.classNames().inspect().include("readonly") == false){
-	field.readOnly = true;	
-	field.addClassName('readonly');
+			field.readOnly = true;	
+			field.addClassName('readonly');
     } else {
-	field.readOnly = false;
-	field.removeClassName('readonly');
+			field.readOnly = false;
+			field.removeClassName('readonly');
     };	
 }
 
@@ -62,3 +62,13 @@
 	
 }
 
+function hide_all_bibtex_required_fields() {
+	$$('input.bibtex').each(function(s){
+	    s.up('p').hide();
+		})}
+		
+function hide_all_empty_bibtex_fields() {
+	$$('input.bibtex').each(function(s){
+	    if(s.value==""){s.up('p').hide()};
+})}
+		
\ No newline at end of file