From 63975fa82f2558f7843354fe7c26963cb08bcc0d Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Tue, 24 Nov 2009 14:36:32 +1300 Subject: [PATCH] Fix a case where the wymeditor fields were not getting updated properly when using save and continue. Moved continue_editing javascript to admin.js and we are using jQuery for many of the functions inside admin.js now. --- public/javascripts/refinery/admin.js | 51 +++++++++++++++++-- .../shared/admin/_continue_editing.html.erb | 49 +----------------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/public/javascripts/refinery/admin.js b/public/javascripts/refinery/admin.js index c104b30227..b8d343d70a 100644 --- a/public/javascripts/refinery/admin.js +++ b/public/javascripts/refinery/admin.js @@ -10,9 +10,9 @@ FastInit.addOnLoad(function() { init_tooltips(); // focus first field in an admin form. - try{$(document.forms[0]).getInputs('text').first().focus();}catch(err){} + jQuery('form input[type=text]:first').focus(); - $$('a([href*="dialog=true"])').each(function(anchor) + jQuery('a[href*="dialog=true"]').each(function(i, anchor) { ['modal=true', 'width=928', 'height=473', 'titlebar=true', 'draggable=true'].each(function(feature) { @@ -21,7 +21,52 @@ FastInit.addOnLoad(function() anchor.href += "&" + feature; } }); - + tb_init(anchor); }); + + jQuery('#submit_continue_button').bind('click', function(e) { + // ensure wymeditors are up to date. + if (jQuery(this).hasClass('wymupdate')) { + WYMeditor.INSTANCES.each(function(wym) + { + wym.update(); + }); + } + + jQuery('#continue_editing').val(true); + + if ((flash=$('flash')) != null) { + flash.hide(); + } + + jQuery.post(this.form.action, this.form.serialize(), function(data) { + if ((flash_container = $('flash_container')) != null) { + flash_container.update(data); + + if ((flash = $('flash')) != null) { + flash.style.width = 'auto'; + flash.appear(); + } + + jQuery('.errorExplanation').each(function(i, node) { + if (node.parentNode.id != 'flash_container') { + node.remove(); + } + }); + + jQuery('.fieldWithErrors').each(function(i, field) { + field.removeClassName('fieldWithErrors').addClassName('field'); + }); + + $('flash_container').scrollTo(); + + jQuery('#continue_editing').val(false); + + jQuery('.fieldWithErrors:first :input:first').focus(); + } + }); + + e.preventDefault(); + }); }); \ No newline at end of file diff --git a/vendor/plugins/refinery/app/views/shared/admin/_continue_editing.html.erb b/vendor/plugins/refinery/app/views/shared/admin/_continue_editing.html.erb index 29d24d5a0a..b5e206b39a 100644 --- a/vendor/plugins/refinery/app/views/shared/admin/_continue_editing.html.erb +++ b/vendor/plugins/refinery/app/views/shared/admin/_continue_editing.html.erb @@ -1,51 +1,4 @@ <% unless f.object.new_record? -%> <%= hidden_field_tag :continue_editing, false %> <%= f.submit 'Save & Continue Editing', :id => "submit_continue_button", :class => "wymupdate" %> - <% content_for :head do -%> - - <% end -%> -<% end -%> +<% end -%> \ No newline at end of file