Advertisement
tareq1988

Untitled

May 16th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){
  2.  
  3.     var weDevs_CPM = {
  4.         init: function() {
  5.             $('.cpm-form-tasks').on('click', '.cpm-add-task-item', this.Task.fieldAdd);
  6.             $('.cpm-form-tasks').on('click', '.cpm-remove-task-item', this.Task.fieldRemove);
  7.             $('.cpm-task').on('click', '.cpm-mark-task-complete', this.Task.markComplete);
  8.             $('.cpm-task').on('click', '.cpm-mark-task-open', this.Task.markOpen);
  9.             $('.cpm-task').on('click', '.cpm-mark-task-delete', this.Task.markDelete);
  10.             $('.cpm-task-list').on('click', '.cpm-hide-tasks', this.Task.toggleTasks);
  11.         },
  12.         Task: {
  13.             fieldAdd: function() {
  14.                 var row = $('#cpm-form-tasks-new').html();
  15.  
  16.                 $(row).insertAfter($(this).parent().parent());
  17.                 $( ".datepicker" ).datepicker();
  18.  
  19.                 return false;
  20.             },
  21.             fieldRemove: function() {
  22.                 $(this).parent().parent().remove();
  23.  
  24.                 return false;
  25.             },
  26.             markComplete: function(e) {
  27.                 e.preventDefault();
  28.  
  29.                 var that = $(this),
  30.                 data = {
  31.                     task_id: that.data('id'),
  32.                     action: 'cpm_task_complete',
  33.                     '_wpnonce': cpm_task_nonce
  34.                 };
  35.  
  36.                 that.addClass('cpm-loading');
  37.                 $.post(ajaxurl, data, function(response) {
  38.                     location.reload();
  39.                 });
  40.             //that.removeClass('cpm-loading');
  41.             },
  42.             markOpen: function(e) {
  43.                 e.preventDefault();
  44.  
  45.                 var that = $(this),
  46.                 data = {
  47.                     task_id: that.data('id'),
  48.                     action: 'cpm_task_open',
  49.                     '_wpnonce': cpm_task_nonce
  50.                 };
  51.  
  52.                 that.addClass('cpm-loading');
  53.                 $.post(ajaxurl, data, function(response) {
  54.                     location.reload();
  55.                 });
  56.             //that.removeClass('cpm-loading');
  57.             },
  58.             markDelete: function(e) {
  59.                 e.preventDefault();
  60.  
  61.                 if(confirm('Are you sure?')) {
  62.                     var that = $(this),
  63.                     data = {
  64.                         task_id: that.data('id'),
  65.                         action: 'cpm_task_delete',
  66.                         '_wpnonce': cpm_task_nonce
  67.                     };
  68.  
  69.                     that.addClass('cpm-loading');
  70.                     $.post(ajaxurl, data, function(response) {
  71.                         location.reload();
  72.                     });
  73.                 }
  74.             },
  75.             toggleTasks: function(e) {
  76.                 e.preventDefault();
  77.  
  78.                 $(this).parent().next('.cpm-tasks').slideToggle();
  79.             }
  80.         }
  81.     };
  82.  
  83.     weDevs_CPM.init();
  84.  
  85. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement