changeset 445:77f88379115a feature_36

Merged my forks. More work in the controllers and views of the publications model.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 08 Jun 2011 11:35:04 +0100
parents b461f84ed41a (current diff) 948400933de8 (diff)
children 995d4c99843d
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/author.rb vendor/plugins/redmine_bibliography/app/models/publication.rb vendor/plugins/redmine_bibliography/app/views/publications/_edit.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/app/views/publications/show.html.erb
diffstat 7 files changed, 81 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Sat Jun 04 18:08:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Jun 08 11:35:04 2011 +0100
@@ -6,7 +6,10 @@
 
   def new
     @publication = Publication.new      
-
+    
+    # we'll always want a new publication to have its bibtex entry
+    @publication.build_bibtex_entry
+    
     # the step we're at in the form
     @publication.current_step = session[:publication_step]
 
@@ -16,6 +19,20 @@
 
   def create
     @publication = Publication.new(params[:publication])
+
+    if @publication.save
+      flash[:notice] = "Successfully created publication."
+      redirect_to @publication
+    else
+      render :action => 'new'
+    end
+  end
+
+  def index
+    @publications = Publication.find(:all)
+  end
+
+  def new_from_bibfile
     @publication.current_step = session[:publication_step]
     
     # contents of the paste text area
@@ -36,37 +53,28 @@
     end
 
     session[:publication_step] = @publication.current_step
-
-    if @publication.new_record?
-      render "new"
-    else
-      session[:publication_step] = session[:publication_params] = nil
-      flash[:notice] = "New publication saved!"
-      redirect_to @publication
-    end
-  end
-
-  def index
-    @publications = Publication.find(:all)
-  end
-
-  def edit
-    
-    @publication = Publication.find(params[:id])
     
   end
 
-  def update
+
+  def edit    
     @publication = Publication.find(params[:id])
+  end
+
+  def update    
+    @publication = Publication.find(params[:id])
+        
     if @publication.update_attributes(params[:publication])
       flash[:notice] = "Successfully updated Publication."
-      redirect_to @publication
     else
-      render :action => 'edit'
+      flash[:notice] = "Could not Update Publication."
     end
+    
   end
 
   def show
+    logger.error "-------> No Show"
+    
     @publication = Publication.find(params[:id])
 
     if @publication.nil?
--- a/vendor/plugins/redmine_bibliography/app/models/author.rb	Sat Jun 04 18:08:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/author.rb	Wed Jun 08 11:35:04 2011 +0100
@@ -2,6 +2,6 @@
   has_many :authorships
   has_many :publications, :through => :authorships
 
-  belongs_to :user
+  # belongs_to :user
   
 end
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Sat Jun 04 18:08:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Wed Jun 08 11:35:04 2011 +0100
@@ -2,15 +2,18 @@
 
 class Publication < ActiveRecord::Base
   unloadable
-
-
+  
   has_many :authorships
   has_many :authors, :through => :authorships
-  has_one :bibtex_entry
+  has_one :bibtex_entry, :dependent => :destroy
 
   validates_presence_of :title
+
+  accepts_nested_attributes_for :authorships
+  accepts_nested_attributes_for :authors, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
+#  accepts_nested_attributes_for :bibtex_entry, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true 
   
-  accepts_nested_attributes_for :authors, :bibtex_entry
+  
   
   attr_writer :current_step
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -0,0 +1,38 @@
+<% form_for @publication do |f| -%>
+  <%= f.error_messages %>
+  <p>
+    <%= f.label :title, l(:title) %>  <%= f.text_field :title %>  
+  </p>
+  
+  <h3><%= l(:authors) %></h3>
+  
+  <%- f.fields_for :authors do |author| -%>
+    <p>
+      <%= author.label :name, l("name") %> <%= author.text_field :name %>            
+    </p>
+  <%- end -%>
+  
+  <% f.fields_for :bibtex_entry do |bib| -%>
+    <p> 
+      <%= bib.label :year, l(:year) %>  <%= bib.text_field :year %>  
+    </p>
+    <p> 
+      <%= bib.label :chapter, l(:chapter) %>  <%= bib.text_field :chapter %>  
+    </p>
+    <p>  
+      <%= bib.label :editor, l(:editor) %>  <%= bib.text_field :editor %>  
+    </p>
+    <p> 
+      <%= bib.label :booktitle, l(:booktitle) %>  <%= bib.text_field :booktitle %>  
+    </p>
+    <p> 
+      <%= bib.label :publisher, l(:publisher) %>  <%= bib.text_field :publisher %>  
+    </p>
+    <p> 
+      <%= bib.label :pages, l(:pages) %>  <%= bib.text_field :pages %>  
+    </p>
+  <% end -%>
+
+  <%= f.submit %>
+
+<% end -%>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Sat Jun 04 18:08:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -2,7 +2,6 @@
 
 <%= render :partial => 'edit' %>
 
-
 <p>
   <%= link_to :show %></p>
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Sat Jun 04 18:08:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -1,4 +1,3 @@
 <h1>New Publication</h1>
 
 <%= render :partial => 'edit' %>
-
--- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Sat Jun 04 18:08:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -1,20 +1,21 @@
 <h2>Publication Details</h2>
 <h4>Title</h4>
-<%= @publication.title %>
+<%= h @publication.title %>
 
 <h4>Authors</h4>
 <% @publication.authors.each do |author| %>
-<%= author.name  %> <br />
+<%= h author.name  %> <br />
 <% end %>
 <br />
 
+<%- if @publication.bibtex_entry != nil -%>
 <% @publication.bibtex_entry.attributes.each do |field| %>
   <% if field[1] != nil %>
     <h4><%= field[0] %></h4>
     <%= @publication.bibtex_entry.attributes[field[0]] unless field[1] == nil %>
     <br />
-  <% end %>
-<% end %>
+  <%- end -%>
+<%- end -%>
+<%- end -%>
 
 
-