changeset 705:b6f9f005c0b6 feature_36

Fixes Bug #298 - on the New View now toggles the new authorship fields.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 19 Sep 2011 17:28:32 +0100
parents 4903d6131c08
children 0a34c4cb73d5
files vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb vendor/plugins/redmine_bibliography/assets/javascripts/authors.js
diffstat 4 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Mon Sep 19 16:59:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Mon Sep 19 17:28:32 2011 +0100
@@ -42,12 +42,12 @@
     f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
   end
     
-  def link_to_add_fields(name, f, association)
+  def link_to_add_author_fields(name, f, association, action)
     new_object = f.object.class.reflect_on_association(association).klass.new
     fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
       render(association.to_s.singularize + "_fields", :f => builder)
     end    
-    link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" })
+    link_to_function(name, h("add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')"), { :class => 'icon icon-add', :id => "add_another_author" })
   end  
 
   def sanitized_object_name(object_name)
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Mon Sep 19 16:59:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Mon Sep 19 17:28:32 2011 +0100
@@ -45,12 +45,11 @@
 
   <p>
 
-  <% if params[:action] == 'new' %>
-   <%= button_to_function l(:label_save_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %>
-  <% else %>
-<%= button_to_function l(:label_edit_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %>
-
- <% end %>
+  <%- if params[:action] == 'new' -%>
+    <%= button_to_function l(:label_save_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %>
+  <%- else -%>
+    <%= button_to_function l(:label_edit_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %>
+  <%- end -%>
 
 
   <%= link_to_remove_fields l("remove_author"), f %>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb	Mon Sep 19 16:59:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb	Mon Sep 19 17:28:32 2011 +0100
@@ -24,7 +24,7 @@
     <% f.fields_for :authorships do |builder| -%>
       <%= render "authorship_fields", :f => builder %>
     <%- end -%>
-    <%= link_to_add_fields l(:label_add_an_author), f, :authorships %>
+    <%= link_to_add_author_fields l(:label_add_an_author), f, :authorships, params[:action] %>
   </div>
 </div>
 
--- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Mon Sep 19 16:59:22 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Mon Sep 19 17:28:32 2011 +0100
@@ -3,12 +3,15 @@
     $(link).up(".fields").hide();
 }
 
-function add_fields(link, association, content) {
-    var new_id = new Date().getTime();
-    var regexp = new RegExp("new_" + association, "g")
-    $(link).insert({
-	before: content.replace(regexp, new_id)
-    });
+function add_author_fields(link, association, content, action) {
+	var new_id = new Date().getTime();
+  var regexp = new RegExp("new_" + association, "g");
+  $(link).insert({
+		before: content.replace(regexp, new_id)
+  });
+	if(action != "new"){
+		toggle_save_author(new_id, $(link));
+	};
 }
 
 function identify_author_status(status, object_id) {