changeset 469:ae87ae455cfb feature_36

correctly saving authors.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 24 Jun 2011 11:23:23 +0100
parents 0bb9c7baed07
children 30b36ab6f15a
files vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb vendor/plugins/redmine_bibliography/app/views/publications/_author_fields.rhtml vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb vendor/plugins/redmine_bibliography/assets/javascripts/authors.js
diffstat 4 files changed, 29 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Thu Jun 23 18:52:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Fri Jun 24 11:23:23 2011 +0100
@@ -1,7 +1,6 @@
 require 'bibtex'
 
 module PublicationsHelper
-
   def projects_check_box_tags(name, projects)
     s = ''
     projects.sort.each do |project|
@@ -10,6 +9,10 @@
     s 
   end
   
+  def link_to_remove_fields(name, f)
+    f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
+  end
+  
   def link_to_add_fields(name, f, association)
     new_object = f.object.class.reflect_on_association(association).klass.new
     fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_author_fields.rhtml	Thu Jun 23 18:52:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_author_fields.rhtml	Fri Jun 24 11:23:23 2011 +0100
@@ -1,8 +1,8 @@
-<div class="author_fields">
-  <% fields_for :authors do |author_form| -%>
-    <%= author_form.label :name, l("name") %> <%= author_form.text_field :name %>            
-    <%= author_form.hidden_field :_destroy %>
-    
-    <%= link_to_function "Remove", "remove_author(this)" %>  
-  <% end -%>
-</div>  
+<div class="fields">
+  <p>  
+    <%= f.label :name, l("name") %>
+    <%= f.text_field :name %>            
+    <%= f.hidden_field :_destroy %>
+    <%= link_to_function "Remove", "remove_author(this)" %>
+  </p>
+</div>
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Thu Jun 23 18:52:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Fri Jun 24 11:23:23 2011 +0100
@@ -4,19 +4,19 @@
 
 
 <% form_for @publication, :url => { :project_id  => @project_id, :action => :create } do |f| -%>
-  <%= f.error_messages %>
-  
-  <p><%= f.label :title, l(:title) %>  <%= f.text_field :title %></p>
+  <%= f.error_messages %>  
+  <p>
+    <%= f.label :title, l(:title) %><br />
+    <%= f.text_field :title %>
+  </p>
 
   <h3><%= l(:authors) %></h3>    
     <%= link_to_remote l(:add_me_as_author), {:url => { :controller => 'publications', :action => 'add_author', :user_id => @current_user}, :update => 'users_div' }, { :id => 'add_me_as_an_author', :class => 'icon icon-add' } %>  
 
-
-  <div id='authors'>    
-    <%= link_to_add_fields l(:add_another_author), f, :authors %>
-
-    <%= render :partial => 'author_fields', :collection => @publication.authors %>    
-  </div>  
+  <% f.fields_for :authors do |builder| %>
+    <%= render "author_fields", :f => builder %>
+  <% end %>
+  <p><%= link_to_add_fields l(:add_another_author), f, :authors %></p>
     
   <h3>Other Details</h3>
 
--- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Thu Jun 23 18:52:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Fri Jun 24 11:23:23 2011 +0100
@@ -3,8 +3,15 @@
 	$(link).up('.author_fields').remove();
 }
 
+function remove_fields(link) {
+  $(link).previous("input[type=hidden]").value = "1";
+  $(link).up(".fields").hide();
+}
+
 function add_fields(link, association, content) {
   var new_id = new Date().getTime();
   var regexp = new RegExp("new_" + association, "g")
-  $(link).parent().before(content.replace(regexp, new_id));
+  $(link).up().insert({
+    before: content.replace(regexp, new_id)
+  });
 }
\ No newline at end of file