changeset 687:cdddec376920 live

Merge from branch "feature_36"
author Chris Cannam
date Fri, 16 Sep 2011 15:48:27 +0100
parents 65abc6b39292 (current diff) b1debf464389 (diff)
children 1f488f375d64 a8e402f48723 76be9c574f4f
files
diffstat 9 files changed, 55 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Sep 16 15:48:27 2011 +0100
@@ -63,37 +63,18 @@
   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' ]
+    fields = BibtexEntryType.fields(params[:value])
+    all_fields = BibtexEntryType.all_fields
 
-    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()
+          all_fields.each_with_index do |field, idx|            
+            unless fields.include? field
+              page["publication_bibtex_entry_attributes_#{field}"].up('p').hide()
+            else
+              page["publication_bibtex_entry_attributes_#{field}"].up('p').show()
             end            
           end
         }
@@ -115,11 +96,12 @@
     find_project_by_project_id unless params[:project_id].nil?
     
     @edit_view = true;
-    
     @publication = Publication.find(params[:id])
     @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
 
     @author_options = []  
+    
+    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)    
   end
 
   def update    
@@ -144,7 +126,7 @@
 
   def show
     find_project_by_project_id unless params[:project_id].nil?
-    
+        
     if @publication.nil?
       @publications = Publication.all
       render "index", :alert => 'The publication was not found!'
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Fri Sep 16 15:48:27 2011 +0100
@@ -6,6 +6,8 @@
   
   accepts_nested_attributes_for :author
   accepts_nested_attributes_for :publication
+
+  validates_presence_of :name_on_paper
   
   attr_accessor :is_user, :author_user_id, :search_name, :identify_author, :search_results
   before_save :associate_author_user
--- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb	Fri Sep 16 15:48:27 2011 +0100
@@ -12,6 +12,5 @@
   def entry_type_label
     entry_type = self.entry_type
     BibtexEntryType.find(entry_type).label
-  end
-  
+  end  
 end
--- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb	Fri Sep 16 15:48:27 2011 +0100
@@ -1,8 +1,35 @@
 class BibtexEntryType < ActiveRecord::Base
+
+  @@all_fields = [ "editor", "publisher", "chapter", "pages", "volume", "series", "address", "edition", "month", "year", "type", "note", "number", "journal", "howpublished", "key", "school" ]
+
+  @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], 
+                  'book' , [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ],
+                  'booklet' , [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ],
+                  'conference', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ],
+                  'inbook', [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ],
+                  'incollection', [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ],
+                  'inproceedings', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ],
+                  'manual', [ 'organization', 'address', 'edition', 'month', 'year', 'note' ],
+                  'masterthesis', [ 'school', 'year', 'address', 'month', 'note' ],
+                  'misc', [ 'howpublished', 'month', 'year', 'note' ],
+                  'phdthesis', [ 'school', 'year', 'address', 'month', 'note' ],
+                  'proceedings', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ],
+                  'techreport', [ 'year', 'type', 'number', 'address', 'month', 'note' ],
+                  'unpublished', [ 'note', 'month', 'year' ]]
+
   def redundant?
     name == 'conference'  # conference is a duplicate of inproceedings
   end
+
   def label
     l("field_bibtex_#{name}")
   end
+
+  def self.fields (type)
+    @@fields[ self.find(type).name ]    
+  end
+
+  def self.all_fields
+    @@all_fields
+  end
 end
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Fri Sep 16 15:48:27 2011 +0100
@@ -9,6 +9,7 @@
   has_one :bibtex_entry, :dependent => :destroy
 
   validates_presence_of :title
+  validates_length_of :authorships, :minimum => 1, :message => l("error_no_authors")
 
   accepts_nested_attributes_for :authorships
   accepts_nested_attributes_for :authors, :allow_destroy => true
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb	Fri Sep 16 15:48:27 2011 +0100
@@ -12,6 +12,9 @@
   <%= f.text_field :year, :size => 4, :class => 'bibtex' %> 
 </p>
 <p> 
+  <%= f.text_field :month, :size => 4, :class => 'bibtex' %> 
+</p>
+<p> 
   <%= f.text_field :chapter, :size => 15, :class => 'bibtex' %>  
 </p>  
 <p>   
--- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Fri Sep 16 15:48:27 2011 +0100
@@ -1,7 +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);' %>
+    <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>  
+    <%= javascript_tag 'Event.observe(window, "load", function(e){show_all_required_bibtex_fields(' + @bibtype_fields.to_json + ')});' %>
 <% end %>
 
 <h2><%=l(:label_publication_show)%></h2>
--- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Fri Sep 16 15:48:27 2011 +0100
@@ -57,18 +57,16 @@
     toggle_div("publication_authorships_attributes_" + form_object_id +"_search_author");
 }
 
-function edit_author(form_object_id){
-	
-	
-}
+function edit_author(form_object_id){}
 
 function hide_all_bibtex_required_fields() {
 	$$('input.bibtex').each(function(s){
 	    s.up('p').hide();
 		})}
 		
-function hide_all_empty_bibtex_fields() {
+function show_all_required_bibtex_fields(entrytype_fields) {
 	$$('input.bibtex').each(function(s){
-	    if(s.value==""){s.up('p').hide()};
-})}
+    if(entrytype_fields.indexOf(s.id.split('_').last()) == -1){s.up('p').hide()};
+	})
+}
 		
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/config/locales/en.yml	Wed Sep 14 14:26:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml	Fri Sep 16 15:48:27 2011 +0100
@@ -1,5 +1,7 @@
 # English strings go here for Rails i18n
 en:
+  project_module_redmine_bibliography: Bibliography
+
   title: "Title"
   authors: "Authors"
   author: "Author"
@@ -14,6 +16,8 @@
   identify_author_correct: "Yes, but I need to correct some details below"
   identify_author_no: "No, the author was not found in the search"
 
+  error_no_authors: "Please add at least one author to this publication."
+
   label_all_publications: All Publications
   label_all_publications_for_project: Publications associated with %{project}
   label_authors_show: "Authorships by this author"