Skip to content

Commit

Permalink
Fix a case where the wymeditor fields were not getting updated proper…
Browse files Browse the repository at this point in the history
…ly 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.
  • Loading branch information
parndt committed Nov 24, 2009
1 parent 538c46a commit 63975fa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 51 deletions.
51 changes: 48 additions & 3 deletions public/javascripts/refinery/admin.js
Expand Up @@ -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)
{
Expand All @@ -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();
});
});
@@ -1,51 +1,4 @@
<% unless f.object.new_record? -%>
<%= hidden_field_tag :continue_editing, false %>
<%= f.submit 'Save &amp; Continue Editing', :id => "submit_continue_button", :class => "wymupdate" %>
<% content_for :head do -%>
<script type='text/javascript'>
FastInit.addOnLoad(function() {
if ($('submit_continue_button') != null) {
$('submit_continue_button').observe("click", function(e) {
$('continue_editing').value = true;

if ((flash=$('flash')) != null) {
flash.hide();
}

new Ajax.Request(this.form.action, {
method: this.form.method
, parameters: this.form.serialize()
, onComplete: function(e) {
if ((flash_container = $('flash_container')) != null) {

flash_container.update(e.transport.responseText);

if ((flash = $('flash')) != null) {
flash.style.width = 'auto';
flash.appear();
}

$$('#errorExplanation').each(function(errorExplanation) {
if (errorExplanation.parentNode.id != 'flash_container') {
errorExplanation.remove();
}
});

$$('.fieldWithErrors').each(function(field) {
field.removeClassName('fieldWithErrors').addClassName('field');
});

flash_container.scrollTo();
$('continue_editing').value = false;
}
}
, evalScripts: true
});

e.preventDefault();
});
}
});
</script>
<% end -%>
<% end -%>
<% end -%>

0 comments on commit 63975fa

Please sign in to comment.