# HG changeset patch # User luisf # Date 1307529304 -3600 # Node ID 77f88379115ac9fb9a52b1d011759e0b66183662 # Parent b461f84ed41a7905ffe52a4be619eaf76bd11c55# Parent 948400933de8d7b897695ef62f5a58fcfa88a1ad Merged my forks. More work in the controllers and views of the publications model. diff -r b461f84ed41a -r 77f88379115a vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- 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? diff -r b461f84ed41a -r 77f88379115a vendor/plugins/redmine_bibliography/app/models/author.rb --- 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 diff -r b461f84ed41a -r 77f88379115a vendor/plugins/redmine_bibliography/app/models/publication.rb --- 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 diff -r b461f84ed41a -r 77f88379115a vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb --- /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 %> +

+ <%= f.label :title, l(:title) %> <%= f.text_field :title %> +

+ +

<%= l(:authors) %>

+ + <%- f.fields_for :authors do |author| -%> +

+ <%= author.label :name, l("name") %> <%= author.text_field :name %> +

+ <%- end -%> + + <% f.fields_for :bibtex_entry do |bib| -%> +

+ <%= bib.label :year, l(:year) %> <%= bib.text_field :year %> +

+

+ <%= bib.label :chapter, l(:chapter) %> <%= bib.text_field :chapter %> +

+

+ <%= bib.label :editor, l(:editor) %> <%= bib.text_field :editor %> +

+

+ <%= bib.label :booktitle, l(:booktitle) %> <%= bib.text_field :booktitle %> +

+

+ <%= bib.label :publisher, l(:publisher) %> <%= bib.text_field :publisher %> +

+

+ <%= bib.label :pages, l(:pages) %> <%= bib.text_field :pages %> +

+ <% end -%> + + <%= f.submit %> + +<% end -%> diff -r b461f84ed41a -r 77f88379115a vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb --- 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' %> -

<%= link_to :show %>

diff -r b461f84ed41a -r 77f88379115a vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb --- 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 @@

New Publication

<%= render :partial => 'edit' %> - diff -r b461f84ed41a -r 77f88379115a vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb --- 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 @@

Publication Details

Title

-<%= @publication.title %> +<%= h @publication.title %>

Authors

<% @publication.authors.each do |author| %> -<%= author.name %>
+<%= h author.name %>
<% end %>
+<%- if @publication.bibtex_entry != nil -%> <% @publication.bibtex_entry.attributes.each do |field| %> <% if field[1] != nil %>

<%= field[0] %>

<%= @publication.bibtex_entry.attributes[field[0]] unless field[1] == nil %>
- <% end %> -<% end %> + <%- end -%> +<%- end -%> +<%- end -%> -