app/assets/javascripts/admin/blog/posts.js in tb_blog-1.2.1 vs app/assets/javascripts/admin/blog/posts.js in tb_blog-1.3.0.beta1
- old
+ new
@@ -1,66 +1,59 @@
-spud.admin.posts = new function(){
+(function(){
- var self = this;
+spud.admin.posts = {
+ edit: function(){
+ $('body').on('click', '.spud-post-add-category', clickedPostAddCategory);
+ $('body').on('submit', '.spud-post-category-form', submittedPostCategoryForm);
+ }
+};
- this.edit = function(){
- spud.admin.date_picker.init();
+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
+ });
+ }
+ });
+};
- $('body').on('click', '.spud_post_add_category', self.clickedPostAddCategory);
- $('body').on('click', '.save_post_category_button', self.submittedPostCategoryForm);
- $('body').on('submit', '.spud_post_category_form', self.submittedPostCategoryForm);
- };
+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
+ });
+};
- this.clickedPostAddCategory = function(e){
- e.preventDefault();
- $.ajax({
- url: $(this).attr('href'),
- dataType: 'html',
- success: function(html, textStatus, jqXHR){
- displayModalDialogWithOptions({
- title: 'Add Category',
- html: html
- });
- }
- });
- };
+var savedPostCategorySuccess = function(data, textStatus, jqXHR){
+ var checkbox = '';
+ checkbox += '<li class="spud_post_form_category" data-id="'+data.id+'">';
+ checkbox += '<input id="spud_post_category_'+data.id+'" name="spud_post[category_ids][]" type="checkbox" value="'+data.id+'" checked>' + "\n";
+ checkbox += '<label for="spud_post_category_'+data.id+'">'+data.name+'</label>';
+ checkbox += '<ul></ul></li>';
+ $('.spud-post-categories-list').append(checkbox).scrollTop(99999);
+ spud.admin.modal.hide();
+};
- this.submittedPostCategoryForm = function(e){
- e.preventDefault();
- var form = $('.spud_post_category_form');
- $.ajax({
- url: form.attr('action'),
- data: form.serialize(),
- type: 'post',
- dataType: 'json',
- success: self.savedPostCategorySuccess,
- error: self.savePostCategoryError
- });
- };
-
- this.savedPostCategorySuccess = function(data, textStatus, jqXHR){
- var checkbox = '';
- checkbox += '<li class="spud_post_form_category" data-id="'+data.id+'">';
- checkbox += '<input id="spud_post_category_'+data.id+'" name="spud_post[category_ids][]" type="checkbox" value="'+data.id+'" checked>' + "\n";
- checkbox += '<label for="spud_post_category_'+data.id+'">'+data.name+'</label>';
- checkbox += '<ul></ul></li>';
- if(data.parent_id > 0){
- $('.spud_post_form_category[data-id="'+data.parent_id+'"]>ul').append(checkbox);
- }
- else{
- $('.spud_post_categories_form').append(checkbox);
- }
- hideModalDialog();
- };
-
- this.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);
- }
- }
- };
+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);
+ }
+ }
};
+
+})();