Skip to content

Instantly share code, notes, and snippets.

@stympy
Created February 28, 2011 23:12
Show Gist options
  • Save stympy/848242 to your computer and use it in GitHub Desktop.
Save stympy/848242 to your computer and use it in GitHub Desktop.
function displaySuccess(message) {
$('body').scrollTo();
$('#success_message').remove();
$('#content').prepend(banner = $('<div class="ui-widget flash hidden" id="success_message"><div class="ui-state-corner-all ui-state-highlight"><p><span class="ui-icon ui-icon-info"></span>' + message + '</p></div></div>'));
banner.slideDown('normal', function() {
setTimeout(function() { banner.slideUp('slow'); }, 10000);
});
}
function formSubmit(data, status, xhr, form) {
if (data.errors) {
displayErrors(form, data.errors);
} else if(data.error) {
alert(data.error);
} else {
saveNeeded = false;
if (data.location == 'back' || data.location == window.location.href) {
// If the model being edited has nested attributes, the page needs to be reloaded to make sure new ones get ids associated with them
if ($('input[name*=attributes]').length) {
window.location.reload();
} else {
submitCleanup();
if (data.image && !data.image.match('missing-original.gif')) {
$('#image_holder').html('<img src="' + data.image + '">');
}
displaySuccess(data.flash.notice);
Cookie.erase("flash");
}
} else {
window.location = data.location;
}
}
}
function submitCleanup() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment