(function(){ spud.admin.posts = { edit: function(){ $('body').on('click', '.spud-post-add-category', clickedPostAddCategory); $('body').on('submit', '.spud-post-category-form', submittedPostCategoryForm); } }; var clickedPostAddCategory = function(e){ e.preventDefault(); $.ajax({ url: $(this).attr('href'), dataType: 'html', success: function(html, textStatus, jqXHR){ spud.admin.modal.displayWithOptions({ title: 'Add Category', html: html }); } }); }; var submittedPostCategoryForm = function(e){ e.preventDefault(); var form = $('.spud-post-category-form'); $.ajax({ url: form.attr('action'), data: form.serialize(), type: 'post', dataType: 'json', success: savedPostCategorySuccess, error: savePostCategoryError }); }; var savedPostCategorySuccess = function(data, textStatus, jqXHR){ var checkbox = ''; checkbox += '
  • '; checkbox += '' + "\n"; checkbox += ''; checkbox += '
  • '; $('.spud-post-categories-list').append(checkbox).scrollTop(99999); spud.admin.modal.hide(); }; var savePostCategoryError = function(jqXHR, textStatus, errorThrown){ if(jqXHR.status == 422){ var html = jqXHR.responseText; $('.spud-post-category-form').replaceWith(html); } else{ if(window.console){ console.error('Oh Snap:', arguments); } } }; })();