# taskbuilder/6.0.5/asset/js/admin.js

Taskbuilder – Project Management &amp; Task Management Tool With Kanban Board, version 6.0.5. 2,874 lines.

- Page: https://pluginprobe.com/plugins/taskbuilder/6.0.5/code/asset/js/admin.js
- Raw: https://pluginprobe.com/plugins/taskbuilder/6.0.5/raw/asset/js/admin.js
- Modified: 2026-08-26T12:27:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/taskbuilder/6.0.5/code/asset/js/admin.js#L10-L20`.

```javascript
function getMentionDropdown(editor) {
    let body = jQuery(editor.getBody());
    let dropdown = body.find('#wppm_mention_list');

    if (!dropdown.length) {
        dropdown = jQuery('<div id="wppm_mention_list"></div>');
        body.append(dropdown);
    }
      if (!editor.mentionDropdown) {
        return editor.mentionDropdown;
      }else{
        return dropdown;
      }
}

function updateActiveItem(items,mentionIndex) {
  items.removeClass('active').css({
      background: '#fff',
      color: '#333'
  });
  items.eq(mentionIndex)
    .addClass('active')
    .css({
        background: '#0073aa',
        color: '#fff'
    });
}

function wppm_add_new_project(){
  jQuery('#wppm_project_container').show();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_add_new_project'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  });  
}

function wppm_projects(){
  jQuery('#wppm_project_container').hide();
  jQuery('#wppm_project_list').show(); 
}

function wppm_get_users(proj_id){
  wppm_modal_open('Add Users'); 
  var data = {
    action: 'wppm_get_users',
    proj_id: proj_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_get_general_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_general').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_general_setings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_get_page_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_page').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_page_setings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_set_page_settings(){
  jQuery('.wppm_submit_wait').show();
    var dataform = new FormData(jQuery('#wppm-frm-ps')[0]);
    jQuery.ajax({
      url: wppm_admin.ajax_url,
      type: 'POST',
      data: dataform,
      processData: false,
      contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    jQuery('.wppm_submit_wait').hide();
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
  });
}

 /*
 * Category Settings
 */
function wppm_get_category_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_category').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_category_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

/**
 * Delete category
 */
function wppm_delete_category(cat_id) {

  const flag = confirm(wppm_admin.confirm);
  if (!flag) return;

  var data = { action: 'wppm_delete_category', 
    cat_id,
    _ajax_nonce:jQuery('#wppm_delete_cat_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function (res) {
    wppm_get_category_settings();
  });
}

function wppm_get_proj_status_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_proj_status').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_proj_status_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_get_add_proj_status(){
  wppm_modal_open(wppm_admin.add_new_status); 
  var data = {
    action: 'wppm_get_add_proj_status'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
    jQuery('#wppm_proj_status_name').focus();
  });
}

function wppm_delete_proj_status(status_id){
  const flag = confirm(wppm_admin.confirm);
  if (!flag) return;

  var data = { action: 'wppm_delete_status', status_id,
    _ajax_nonce:jQuery('#wppm_delete_pstatus_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function (res) {
    wppm_get_proj_status_settings();
  });
}

function wppm_set_project_users(){
  var dataform = new FormData(jQuery('#frm_get_project_users')[0]);
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var proj_id = jQuery('#wppm_proj_id').val();
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function () {
    wppm_modal_close(); 
    wppm_open_project(proj_id);
  });
}

function wppm_set_task_users(proj_id,project_id){
  var dataform = new FormData(jQuery('#frm_get_task_users')[0]);
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var task_id = jQuery('#wppm_task_id').val();
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function () {
    if((proj_id!=0)||(proj_id!="")){
      wppm_task_modal_close(); 
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_task_modal_close(); 
      wppm_open_task(task_id,project_id);
    }
  });
}

function wppm_get_project_list(page_no){
  jQuery('#wppm_project_container').show();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var dataform=new FormData(jQuery('#wppm_project_list_frm')[0]);
	dataform.append("page_no", page_no);
  dataform.append("action", 'wppm_get_project_list');
  dataform.append("page", wppm_admin.page);
  dataform.append("wppm_project_filter", wppm_project_filter);
  jQuery.ajax( {
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  }) 
  .done(function( response ) {
    jQuery('#wppm_project_container').html(response);
  });
}

function wppm_add_new_task(proj_id,project_id){
  jQuery('#wppm_task_container').show();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_add_new_task',
    proj_id:proj_id,
    project_id:project_id
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  }); 
}

function wppm_get_task_list(page_no,id){
  jQuery('#wppm_task_container').show();
  // window.history.replaceState( {}, null, 'admin.php?page=wppm-tasks&section=task-list' );
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_task_list',
    page_no:page_no,
    page:wppm_admin.page,
    project_id:id,
    wppm_task_filter:wppm_task_filter
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  }); 
}

function wppm_get_task_prioriy_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_task_priorities').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_priority_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_add_task_priority(){
  wppm_modal_open(wppm_admin.add_new_priority); 
  var data = {
    action: 'wppm_add_task_priority'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
    jQuery('#wppm_cat_name').focus();
  });
}

function wppm_delete_task_priority(priority_id){
  const flag = confirm(wppm_admin.confirm);
  if (!flag) return;

  var data = { action: 'wppm_delete_task_priority', priority_id,
    _ajax_nonce:jQuery('#wppm_delete_tprio_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function (res) {
    wppm_get_task_prioriy_settings();
  });
}

function wppm_get_task_status_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_task_status').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_task_status_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_get_add_task_status(){
  wppm_modal_open(wppm_admin.add_new_status); 
  var data = {
    action: 'wppm_get_add_task_status'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
    jQuery('#wppm_cat_name').focus();
  });
}

function wppm_delete_task_status(status_id){
  const flag = confirm(wppm_admin.confirm);
  if (!flag) return;

  var data = { action: 'wppm_delete_task_status', status_id,
    _ajax_nonce: jQuery('#wppm_delete_tstatus_ajax_nonce').val()};
  jQuery.post(wppm_admin.ajax_url, data, function (res) {
    wppm_get_task_status_settings();
  });
}

function wppm_task_search_filter(page){
  var task_search = jQuery("#wppm_task_search_filter").val();
  jQuery('#wppm_task_container').show();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
      action: 'wppm_get_task_list',
      task_search:task_search,
      page:page
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  });
}

function wppm_view_task_search_filter(page_no,page,proj_id){
  var task_search = jQuery("#wppm_view_task_search_filter").val() || '';
  jQuery('#wppm_task_container').show();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);

  var data = {
    action: 'wppm_get_task_list_card_view',
    task_search:task_search,
    page_no:page_no,
    page:page,
    project_id:proj_id
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  });
}

function wppm_open_task(id,proj_id){
  jQuery('#wppm_task_container').show();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_open_task',
    id:id,
    auth_code: wppm_admin.auth_code,
    page:wppm_admin.page,
    project_id:proj_id
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  });
}

function wppm_open_dashboard_task(id){
     window.location.href = 'admin.php?page=wppm-tasks&task_id=' + id;
}

function wppm_open_project_tasks(id,proj_id){
  wppm_modal_open('Open Tasks');
  jQuery('#wppm_task_container').show();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_open_task',
    id: id,
    proj_id:proj_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    jQuery('#wppm_popup_body').html(response_str);
    //jQuery('#wppm_task_container').html(response_str);
  });
}

function wppm_add_new_checklist(task_id,proj_id){
  if(jQuery('#wppm_checklist_label').val()==''){
    jQuery('#wppm_checklist_label').focus();
    return  false;
  }
  var data = {
    action: 'wppm_add_new_checklist',
    task_id: task_id,
    proj_id: proj_id,
    checklist_name: jQuery('#wppm_checklist_label').val(),
    _ajax_nonce:jQuery('#wppm_checklist_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    if((proj_id!=0)||(proj_id!="")){
      //wppm_modal_close(); 
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      //wppm_modal_close(); 
      wppm_open_task(task_id);
    }
  });
}

function wppm_add_new_checklist_item(checklist_id,task_id,proj_id){
  if(jQuery('#wppm_checklist_item_label_'+checklist_id).val()==''){
    jQuery('#wppm_checklist_item_label_'+checklist_id).focus();
    return  false;
  }
  var data = {
    action: 'wppm_add_new_checklist_item',
    checklist_id: checklist_id,
    proj_id:proj_id,
    label: jQuery('#wppm_checklist_item_label_'+checklist_id).val(),
    _ajax_nonce:jQuery('#wppm_checklist_item_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    if((proj_id!=0)||(proj_id!="")){
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_open_task(task_id);
    }
  });
}

function wppm_delete_checklist(checklist_id,task_id,proj_id){
  const flag = confirm(wppm_admin.confirm);
  if (!flag) return;
  var data = {
    action: 'wppm_delete_checklist',
    checklist_id: checklist_id,
    task_id:task_id,
    proj_id:proj_id,
    _ajax_nonce:jQuery('#wppm_delete_checklist_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    if((proj_id!=0)||(proj_id!="")){
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_open_task(task_id);
    }
  });
}

function wppm_delete_checklist_item(item_id,checklist_id,proj_id,task_id){
  const flag = confirm(wppm_admin.confirm);
  if (!flag) return;
  var data = {
    action: 'wppm_remove_checklist_item',
    item_id:item_id,
    checklist_id: checklist_id,
    proj_id:proj_id,
    task_id:task_id,
    _ajax_nonce:jQuery('#wppm_delete_checklist_item_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    if((proj_id!=0)||(proj_id!="")){
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_open_task(task_id);
    }
  });
}

function wppm_checklist_progress(checklist_id,item_id,task_id){
  var $checkboxes = jQuery('.wppm_checklist_item_'+checklist_id);
  var $progress = jQuery('#CheckProgress_'+checklist_id);
  var total = $checkboxes.length;
  var checked = jQuery('.wppm_checklist_item_'+checklist_id).filter(':checked').length;
  var progressWidth = (checked / total) * 100;
  var checked_item;
  jQuery('#CheckProgress_'+checklist_id).css('background','#5ba4cf');
  jQuery('#CheckProgress_'+checklist_id).css('width', progressWidth + '%');
  if (jQuery("#wppm_checklist_item_"+item_id).prop("checked")==true) { 
    checked_item=1;
  }else{
    checked_item=0;
  }
  var data = {
    action: 'wppm_set_checklist_progress',
    checklist_id: checklist_id,
    item_id:item_id,
    checked_item: checked_item,
    _ajax_nonce:jQuery('#wppm_checklist_progress_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    wppm_open_task(task_id);
  });
}

function wppm_open_individual_task(id){
  jQuery('#wppm_project_container').show();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_open_task',
    id:id
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  });
}


function wppm_display_grid_view(page,id){
  var task_search = jQuery("#wppm_view_task_search_filter").val() || '';
  jQuery('#wppm_task_container').show();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
        action: 'wppm_get_task_list_card_view',
        task_search: task_search,
        wppm_task_filter: wppm_task_filter,
        page:page,  
        id:id
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  });
}

function wppm_remove_filter(id){
  jQuery('#wppm_user_display_container_'+id).remove();
}

function wppm_remove_user_from_project(id){
  jQuery('#wppm_user_container_'+id).remove();
}

function wppm_remove_task_user_filter(id){
  jQuery('#wppm_task_user_display_container_'+id).remove();
}

function wppm_attachment_cancel( obj ){
  jQuery(obj).parent().remove();
}

function wppm_get_en_general_setting(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_en_setting_general').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  
  var data = {
    action: 'wppm_get_en_general_setting',
  };

  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_set_en_general_settings(){
  jQuery('.wppm_submit_wait').show();
  var dataform = new FormData(jQuery('#wppm_en_frm_general_settings')[0]);
  
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    jQuery('.wppm_submit_wait').hide();
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
  });
}

function wppm_get_en_task_notifications(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_en_ticket_notifications').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  
  var data = {
    action: 'wppm_get_en_task_notifications'
  };

  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_edit_task_status(id,proj_id,project_id){
  if(proj_id==0){
    wppm_task_modal_open('Edit'); 
  }else{
    wppm_modal_open('Edit'); 
  }
  var data = {
    action: 'wppm_edit_task_status',
    task_id: id,
    proj_id:proj_id,
    project_id:project_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_edit_task_users(task_id,proj_id,project_id){
  if(proj_id==0){
    wppm_task_modal_open('Add Users'); 
  }else{
    wppm_modal_open('Add Users'); 
  } 
  var data = {
    action: 'wppm_get_task_users',
    task_id: task_id,
    proj_id:proj_id,
    project_id:project_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_edit_task_details(id,proj_id,project_id){
  if(proj_id==0){
    wppm_task_modal_open('Edit Task Details'); 
  }else{
    wppm_modal_open('Edit Task Details'); 
  }
  var data = {
    action: 'wppm_edit_task_details',
    task_id: id,
    proj_id:proj_id,
    project_id:project_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_set_change_task_status(task_id,proj_id,project_id){
  var dataform = new FormData(jQuery('#frm_get_task_change_status')[0]);
  if(proj_id == 0){
    wppm_task_modal_close();
  }else{
    wppm_modal_close();
  }
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    if((proj_id!=0)||(proj_id!="")){
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_open_task(task_id,project_id);
    }
    
  }); 
}

function wppm_edit_task_creator(task_id,proj_id,project_id){
  if(proj_id==0){
    wppm_task_modal_open('Edit Task Creator'); 
  }else{
    wppm_modal_open('Edit Task Creator'); 
  }
  var data = {
    action: 'wppm_edit_task_creator',
    task_id: task_id,
    proj_id: proj_id,
    project_id: project_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_set_change_raised_by(task_id,proj_id,project_id){
  var dataform = new FormData(jQuery('#frm_get_task_creator')[0]);
  if(proj_id==0){
    wppm_task_modal_close(); 
  }else{
    wppm_modal_close(); 
  }
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    if((proj_id!=0)||(proj_id!="")){
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_open_task(task_id,project_id);
    }
  }); 
}

function wppm_set_change_task_details(task_id, proj_id, project_id) {
    var dataform = new FormData(jQuery('#frm_get_edit_task_deatils')[0]);
    var editor = tinyMCE.get('wppm_edit_task_description');
    var description = '';
    if (editor) {
        description = editor.getContent().trim();
    } else {
        description = jQuery('#wppm_edit_task_description').val().trim();
    }
    dataform.append('wppm_edit_task_description', description);
    if (proj_id == 0) {
        wppm_task_modal_close();
    } else {
        wppm_modal_close();
    }
    jQuery('#wppm_task_container').html(wppm_admin.loading_html);
    jQuery.ajax({
        url: wppm_admin.ajax_url,
        type: 'POST',
        data: dataform,
        processData: false,
        contentType: false
    }).done(function(response_str) {
        if (proj_id != 0 && proj_id != "") {
            wppm_open_project_tasks(task_id, proj_id);
        } else {
            wppm_open_task(task_id, project_id);
        }
    });
}

function wppm_edit_thread(comment_id,task_id,proj_id){
  if(proj_id==0){
    wppm_task_modal_open('Edit Thread'); 
  }else{
    wppm_modal_open('Edit Thread'); 
  }
  var data = {
    action: 'wppm_edit_task_thread',
    comment_id:comment_id,
    task_id: task_id,
    proj_id: proj_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_edit_proj_thread(comment_id,proj_id){
  wppm_modal_open('Edit Thread'); 
  var data = {
    action: 'wppm_edit_proj_thread',
    comment_id:comment_id,
    proj_id: proj_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_set_edit_task_thread(task_id,proj_id){
  var dataform = new FormData(jQuery('#frm_edit_task_thread')[0]);
  if(wppm_admin.rich_text_editor == 1){
    var comment_body = tinyMCE.get('wppm_edit_task_thread_editor').getContent().trim();
  }else{
    var comment_body = jQuery('#wppm_edit_task_thread_editor').val().trim();
  }
  dataform.append('wppm_edit_task_thread', comment_body);
  if(proj_id==0){
    wppm_task_modal_close(); 
  }else{
    wppm_modal_close(); 
  }
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    if((proj_id!=0)||(proj_id!="")){
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_open_task(task_id);
    }
  }); 
}

function wppm_set_edit_proj_thread(proj_id){
  var dataform = new FormData(jQuery('#frm_edit_proj_thread')[0]);
  if(wppm_admin.rich_text_editor == 1){
    var comment_body = tinyMCE.get('wppm_edit_proj_thread_editor').getContent().trim();
  }else{
    var comment_body = jQuery('#wppm_edit_proj_thread_editor').val().trim();
  }
  dataform.append('wppm_edit_proj_thread', comment_body);
  wppm_modal_close();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
      wppm_open_project(proj_id);
  }); 
}

function wppm_delete_thread(comment_id,task_id,proj_id){
  if(proj_id==0){
    wppm_task_modal_open('Delete Thread'); 
  }else{
    wppm_modal_open('Delete Thread'); 
  }
  var data = {
    action: 'wppm_delete_task_thread',
    comment_id:comment_id,
    task_id: task_id,
    proj_id:proj_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_delete_proj_thread(comment_id,proj_id){
  wppm_modal_open('Delete Thread'); 
  var data = {
    action: 'wppm_delete_proj_thread',
    comment_id:comment_id,
    proj_id:proj_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_set_delete_thread(task_id,proj_id){
  var dataform = new FormData(jQuery('#frm_delete_task_thread')[0]);
  if(proj_id==0){
    wppm_task_modal_close(); 
  }else{
    wppm_modal_close(); 
  }
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    if((proj_id!=0)||(proj_id!="")){
      wppm_open_project_tasks(task_id,proj_id);
    }else if((proj_id==0)||(proj_id=="")){
      wppm_open_task(task_id);
    }
  }); 
}

function wppm_set_delete_proj_thread(proj_id){
  var dataform = new FormData(jQuery('#frm_delete_proj_thread')[0]);
  wppm_modal_close();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_open_project(proj_id);
  }); 
}

function wppm_edit_proj_details(id){
  wppm_modal_open('Edit Project Details'); 
  var data = {
    action: 'wppm_edit_project_details',
    id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_set_change_project_details(id){
  var dataform = new FormData(jQuery('#frm_get_edit_project_deatils')[0]);
  var description = tinyMCE.get('wppm_edit_project_description').getContent().trim();
  dataform.append('wppm_edit_project_description', description);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_open_project(id);
  });
}

function wppm_edit_project_status(id){
  wppm_modal_open('Edit Project Status'); 
  var data = {
    action: 'wppm_edit_project_status',
    id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_set_change_project_status(id){
  var dataform = new FormData(jQuery('#frm_get_project_change_status')[0]);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_open_project(id);
  });
}

function wppm_edit_project_creator(id){
  wppm_modal_open('Edit Project Creator'); 
  var data = {
    action: 'wppm_edit_project_creator',
    id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_set_change_project_raised_by(id){
  var dataform = new FormData(jQuery('#frm_get_project_creator')[0]);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_open_project(id);
  });
}

function wppm_edit_project_users(id){
  wppm_modal_open('Add Users'); 
  var data = {
    action: 'wppm_get_project_users',
    id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_delete_project(id){
  wppm_modal_open('Delete Project'); 
  var data = {
    action: 'wppm_get_delete_project',
    id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_set_delete_project(){
  var dataform = new FormData(jQuery('#frm_delete_project')[0]);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_project_list();
  });
}

function wppm_get_delete_task(id,proj_id,project_id){
  if(proj_id==0){
    wppm_task_modal_open('Delete Task'); 
  }else{
    wppm_modal_open('Delete Task'); 
  } 
  var data = {
    action: 'wppm_get_delete_task',
    id: id,
    proj_id:proj_id,
    project_id:project_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_set_delete_task(proj_id,project_id){
  var dataform = new FormData(jQuery('#frm_delete_task')[0]);
  if(proj_id==0){
    wppm_task_modal_close();
  }else{
    wppm_modal_close(); 
  }
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    if(project_id!=0){
      wppm_get_project_tasks_kanban_view(project_id);
    }else{
      if(proj_id==0){
        wppm_get_task_list();
      }else{
        wppm_get_project_tasks(proj_id);
      }
    }
  });
}

function wppm_get_edit_email_notification(id){
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_edit_email_notification',
    id : id
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_get_tinymce(selector,body_id){ 
  jQuery('#visual').addClass('btn btn-primary');
  jQuery('#text').removeClass('btn btn-primary');
  jQuery('#text').addClass('btn btn-default');
  tinymce.init({ 
	  selector:'#'+selector,
	  body_id: body_id,
	  menubar: false,
		statusbar: false,
	  height : '200',
	  plugins: [
	      'lists link image directionality'
	  ],
	  image_advtab: true,
	  toolbar: 'bold italic underline blockquote | alignleft aligncenter alignright | bullist numlist | rtl | link image',
	  branding: false,
	  autoresize_bottom_margin: 20,
	  browser_spellcheck : true,
	  relative_urls : false,
	  remove_script_host : false,
	  convert_urls : true,
		setup: function (editor) {
	  }
	});
}

function wppm_get_textarea(){
  jQuery('#visual').removeClass('btn btn-primary');
  jQuery('#visual').addClass('btn btn-default');
  jQuery('#text').addClass('btn btn-primary');
  tinymce.remove();
}

function wppm_get_templates(){
  wppm_modal_open(wppm_admin.templates);
  var data = {
    action: 'wppm_get_templates'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_set_edit_email_notification(){
  var dataform = new FormData(jQuery('#wppm_edit_email_notification_settings')[0]);
  wppm_modal_close();
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
    wppm_get_en_task_notifications();
  });
}

function wppm_set_general_settings(){
  jQuery('.wppm_submit_wait').show();
  var dataform = new FormData(jQuery('#wppm_frm_general_settings')[0]);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    jQuery('.wppm_submit_wait').hide();
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
  });
}

function wppm_get_project_tasks(id){
  wppm_modal_open('Tasks'); 
  var data = {
    action: 'wppm_get_project_tasks',
    id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_create_project_task(id){
  wppm_task_modal_open('Tasks'); 
  var data = {
    action: 'wppm_add_new_task',
    proj_id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    jQuery('#wppm_popup_body').html(response_str);
  });
}

function wppm_load_prev_page(prev_page_no, page_no, sort_by, order, is_archieved) {
    if (prev_page_no != 0) {
        page_no = prev_page_no - 1;
        if (parseInt(is_archieved) === 1) {
            wppm_get_archieve_project_list(
                page_no,
                sort_by,
                order,
                1
            );
        } else {
            wppm_get_project_list(
                page_no,
                sort_by,
                order
            );
        }
    }
    return false;
}

function wppm_load_next_page(next_page_no, page_no, sort_by, order, is_archieved) {
    if (next_page_no != page_no) {
        page_no = next_page_no;
        if (parseInt(is_archieved) === 1) {
            wppm_get_archieve_project_list(
                page_no,
                sort_by,
                order,
                1
            );
        } else {
            wppm_get_project_list(
                page_no,
                sort_by,
                order
            );
        }
    }

    return false;
}

function wppm_load_prev_task_page(prev_page_no,page_no, sort_by, order){
  if(prev_page_no!=0){
    page_no=prev_page_no-1;
		wppm_get_task_list(page_no,sort_by,order);
	}
}

function wppm_load_next_task_page(next_page_no,page_no,sort_by,order){
	if(next_page_no!=page_no){
    page_no = next_page_no;
	  wppm_get_task_list(page_no,sort_by,order);
	}
}

function wppm_load_prev_task_page_card_view(prev_page_no,page_no){
  if(prev_page_no!=0){
    page_no=prev_page_no-1;
		wppm_view_task_search_filter(page_no);
	}
}

function wppm_load_next_task_page_card_view(next_page_no,page_no){
	if(next_page_no!=page_no){
    page_no = next_page_no;
	  wppm_view_task_search_filter(page_no);
	}
}

function wppm_thread_attachment_remove(obj,attachment,comment_id,task_id,proj_id){
  if( confirm(wppm_admin.confirm) ){
   var data = {
     action: 'wppm_remove_thread_attachment',
     attachment : attachment,
     comment_id : comment_id,
     task_id:task_id,
     _ajax_nonce : jQuery('#wppm_ajax_nonce').val()
   };
   jQuery.post(wppm_admin.ajax_url, data, function(response) {
      jQuery(obj).parent('td').parent('tr').remove();
      if((proj_id!=0)||(proj_id!="")){
        wppm_open_project_tasks(task_id,proj_id);
      }else if((proj_id==0)||(proj_id=="")){
        wppm_open_task(task_id);
      }
    });
  }
}

function wppm_proj_thread_attachment_remove(obj,attachment,comment_id,id){
  if( confirm(wppm_admin.confirm) ){
   var data = {
     action: 'wppm_remove_proj_thread_attachment',
     attachment : attachment,
     comment_id : comment_id,
     proj_id:id,
     _ajax_nonce:jQuery('#wppm_proj_thread_attachment_remove').val()
   };
   jQuery.post(wppm_admin.ajax_url, data, function(response) {
      jQuery(obj).parent('td').parent('tr').remove();
      wppm_open_project(id);
    });
  }
}

function wppm_open_project(id){
  jQuery('#wppm_project_list').hide();
  jQuery('#wppm_project_container').show();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_open_project',
    id:id,
    auth_code: wppm_admin.auth_code
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  });
}

function wppm_project_search_filter(is_archieved){
  var project_search = jQuery("#wppm_project_search_filter").val();
  jQuery('#wppm_project_container').show();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
      action: 'wppm_get_project_list',
      project_search:project_search,
      page: wppm_admin.page,
      is_archieved:is_archieved
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  });
}

function wppm_clone_task(id,proj_id,project_id){
  if(proj_id==0){
    wppm_task_modal_open('Clone Task'); 
  }else{
    wppm_modal_open('Clone Task'); 
  }
  var data = {
    action: 'wppm_clone_task',
    id: id,
    proj_id: proj_id,
    project_id: project_id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_set_clone_task(proj_id,project_id){
  var dataform = new FormData(jQuery('#frm_edit_clone_task_name')[0]);
  if(proj_id==0){
    wppm_task_modal_close();
  }else{
    wppm_modal_close(); 
  }
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    if(project_id!=0){
      wppm_get_project_tasks_kanban_view(project_id);
    }else{
      if(proj_id==0){
        wppm_get_task_list();
      }else{
        wppm_get_project_tasks(proj_id);
      }
    }
  });
}

function wppm_sort_up_task_list(sort_by,order,page){
  jQuery('#wppm_task_container').show();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_task_list',
    sort_by:sort_by,
    order:order,
    page:page
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  }); 
}

function wppm_sort_up_project_list(sort_by,order){
  jQuery('#wppm_project_container').show();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_project_list',
    sort_by:sort_by,
    order:order,
    page: wppm_admin.page
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  }); 
}

function wppm_get_miscellaneous_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_miscellaneous').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_advanced_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_get_appearance_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_appearance').addClass('active');
  var data = {
    action: 'wppm_get_appearance_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_get_coworker_permission_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_coworker').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_coworker_permission_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_set_coworkers_permission_settings(){
  jQuery('.wppm_submit_wait').show();
  var dataform = new FormData(jQuery('#wppm_frm_coworkers_permission_settings')[0]);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    jQuery('.wppm_submit_wait').hide();
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
  });
}

function wppm_get_rich_text_editor_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_rich_text_editor').addClass('active');
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_rich_text_editor_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_set_rich_text_editor_settings(){
  jQuery('.wppm_submit_wait').show();
  var dataform = new FormData(jQuery('#wppm_frm_rich_text_editor_settings')[0]);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    jQuery('.wppm_submit_wait').hide();
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
  });
}

function wppm_get_ap_proj_list(current_tab_class) {
	jQuery( '.wppm-setting-tab-container button' ).removeClass( 'active' );
	jQuery( '.wppm-setting-tab-container button.' + current_tab_class ).addClass( 'active' );
	jQuery('.wppm-setting-section-body').html(wppm_admin.loading_html);
  var data = { action: 'wppm_get_ap_proj_list' ,
      current_tab:current_tab_class
  };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function (response) {
			jQuery( '.wppm-setting-section-body' ).html( response );
		}
	);
}

function wppm_get_ap_modal_popup(current_tab_class){
  jQuery( '.wppm-setting-tab-container button' ).removeClass( 'active' );
	jQuery( '.wppm-setting-tab-container button.' + current_tab_class ).addClass( 'active' );
	jQuery('.wppm-setting-section-body').html(wppm_admin.loading_html);
  var data = { action: 'wppm_get_ap_modal_popup' ,
      current_tab:current_tab_class };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function (response) {
			jQuery( '.wppm-setting-section-body' ).html( response );
		}
	);
}

function wppm_get_ap_task_list(current_tab_class){
  jQuery( '.wppm-setting-tab-container button' ).removeClass( 'active' );
	jQuery( '.wppm-setting-tab-container button.' + current_tab_class ).addClass( 'active' );
	jQuery( '.wppm-setting-section-body').html(wppm_admin.loading_html);
	var data = { action: 'wppm_get_ap_task_list' ,
      current_tab:current_tab_class
  };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function (response) {
			jQuery( '.wppm-setting-section-body' ).html( response );
		}
	);
}

function wppm_get_ap_individual_proj(current_tab_class){
  jQuery( '.wppm-setting-tab-container button' ).removeClass( 'active' );
	jQuery( '.wppm-setting-tab-container button.' + current_tab_class ).addClass( 'active' );
	jQuery( '.wppm-setting-section-body').html(wppm_admin.loading_html);
	var data = { action: 'wppm_get_ap_individual_proj' ,
      current_tab:current_tab_class
  };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function (response) {
			jQuery( '.wppm-setting-section-body' ).html( response );
		}
	);
}

function wppm_get_ap_individual_task(current_tab_class){
  jQuery( '.wppm-setting-tab-container button' ).removeClass( 'active' );
	jQuery( '.wppm-setting-tab-container button.' + current_tab_class ).addClass( 'active' );
	jQuery( '.wppm-setting-section-body').html(wppm_admin.loading_html);
	var data = { action: 'wppm_get_ap_individual_task' ,
      current_tab:current_tab_class
  };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function (response) {
			jQuery( '.wppm-setting-section-body' ).html( response );
		}
	);
}

function wppm_get_ap_grid_view(current_tab_class){
  jQuery( '.wppm-setting-tab-container button' ).removeClass( 'active' );
	jQuery( '.wppm-setting-tab-container button.' + current_tab_class ).addClass( 'active' );
	jQuery( '.wppm-setting-section-body').html(wppm_admin.loading_html);
	var data = { action: 'wppm_get_ap_grid_view' ,
      current_tab:current_tab_class
  };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function (response) {
			jQuery( '.wppm-setting-section-body' ).html( response );
		}
	);
}

function wppm_get_ap_settings(current_tab_class){
  jQuery( '.wppm-setting-tab-container button' ).removeClass( 'active' );
	jQuery( '.wppm-setting-tab-container button.' + current_tab_class ).addClass( 'active' );
	jQuery( '.wppm-setting-section-body').html(wppm_admin.loading_html);
	var data = { action: 'wppm_get_ap_settings' ,
      current_tab:current_tab_class
  };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function (response) {
			jQuery( '.wppm-setting-section-body' ).html( response );
		}
	);
}

function wppm_set_ap_settings(){
  var form     = jQuery( '.wppm-frm-ap-settings' )[0];
	var dataform = new FormData( form );
	jQuery('.wppm_submit_wait').show();
	jQuery.ajax(
		{
			url: wppm_admin.ajax_url,
			type: 'POST',
			data: dataform,
			processData: false,
			contentType: false
		}
	).done(
		function (response_str) {
      var response = JSON.parse(response_str);
      jQuery('.wppm_submit_wait').hide();
      if (response.sucess_status=='1') {
        jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
      }
      jQuery('#wppm_alert_success').slideDown('fast',function(){});
      setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);  
		}
	);
}

function wppm_set_ap_proj_list() {
	var form     = jQuery( '.wppm-frm-ap-pl' )[0];
	var dataform = new FormData( form );
	jQuery('.wppm_submit_wait').show();
	jQuery.ajax(
		{
			url: wppm_admin.ajax_url,
			type: 'POST',
			data: dataform,
			processData: false,
			contentType: false
		}
	).done(
		function (response_str) {
      var response = JSON.parse(response_str);
      jQuery('.wppm_submit_wait').hide();
      if (response.sucess_status=='1') {
        jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
      }
      jQuery('#wppm_alert_success').slideDown('fast',function(){});
      setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);  
		}
	);
}

function wppm_set_ap_task_list(){
  var form     = jQuery( '.wppm-frm-ap-tl' )[0];
	var dataform = new FormData( form );
	jQuery('.wppm_submit_wait').show();
	jQuery.ajax(
		{
			url: wppm_admin.ajax_url,
			type: 'POST',
			data: dataform,
			processData: false,
			contentType: false
		}
	).done(
		function (response_str) {
      var response = JSON.parse(response_str);
      jQuery('.wppm_submit_wait').hide();
      if (response.sucess_status=='1') {
        jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
      }
      jQuery('#wppm_alert_success').slideDown('fast',function(){});
      setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);  
		}
	);
}

function wppm_set_ap_individual_proj(){
  var form     = jQuery( '.wppm-frm-ap-individual_pl' )[0];
	var dataform = new FormData( form );
	jQuery('.wppm_submit_wait').show();
	jQuery.ajax(
		{
			url: wppm_admin.ajax_url,
			type: 'POST',
			data: dataform,
			processData: false,
			contentType: false
		}
	).done(
		function (response_str) {
      var response = JSON.parse(response_str);
      jQuery('.wppm_submit_wait').hide();
      if (response.sucess_status=='1') {
        jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
      }
      jQuery('#wppm_alert_success').slideDown('fast',function(){});
      setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);  
		}
	);
}

function wppm_set_ap_individual_task(){
  var form     = jQuery( '.wppm-frm-ap-individual_tl' )[0];
	var dataform = new FormData( form );
	jQuery('.wppm_submit_wait').show();
	jQuery.ajax(
		{
			url: wppm_admin.ajax_url,
			type: 'POST',
			data: dataform,
			processData: false,
			contentType: false
		}
	).done(
		function (response_str) {
      var response = JSON.parse(response_str);
      jQuery('.wppm_submit_wait').hide();
      if (response.sucess_status=='1') {
        jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
      }
      jQuery('#wppm_alert_success').slideDown('fast',function(){});
      setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);  
		}
	);
}

function wppm_set_ap_modal_popup(){
  var form     = jQuery( '.wppm-frm-ap-modal_popup' )[0];
	var dataform = new FormData( form );
	jQuery('.wppm_submit_wait').show();
	jQuery.ajax(
		{
			url: wppm_admin.ajax_url,
			type: 'POST',
			data: dataform,
			processData: false,
			contentType: false
		}
	).done(
		function (response_str) {
      var response = JSON.parse(response_str);
      jQuery('.wppm_submit_wait').hide();
      if (response.sucess_status=='1') {
        jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
      }
      jQuery('#wppm_alert_success').slideDown('fast',function(){});
      setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);  
		}
	);
}

function wppm_set_ap_grid_view(){
  var form     = jQuery( '.wppm-frm-ap-grid_view' )[0];
	var dataform = new FormData( form );
	jQuery('.wppm_submit_wait').show();
	jQuery.ajax(
		{
			url: wppm_admin.ajax_url,
			type: 'POST',
			data: dataform,
			processData: false,
			contentType: false
		}
	).done(
		function (response_str) {
      var response = JSON.parse(response_str);
      jQuery('.wppm_submit_wait').hide();
      if (response.sucess_status=='1') {
        jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
      }
      jQuery('#wppm_alert_success').slideDown('fast',function(){});
      setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);  
		}
	);
}

function wppm_set_advanced_settings(){
  jQuery('.wppm_submit_wait').show();
  var dataform = new FormData(jQuery('#wppm_frm_advanced_settings')[0]);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    jQuery('.wppm_submit_wait').hide();
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
  });
}

function wppm_get_project_visibility(id){
  wppm_modal_open('Change Visibility'); 
  var data = {
    action: 'wppm_get_project_visibility',
    id: id
  }
  jQuery.post(wppm_admin.ajax_url, data, function(response_str) { 
    var response = JSON.parse(response_str);
    jQuery('#wppm_popup_body').html(response.body);
    jQuery('#wppm_popup_footer').html(response.footer);
  });
}

function wppm_select_project_visibility(proj_id){
  if(jQuery('input[name="wppm_project_visibility_option"]').is(':checked')){
    var project_visibility = jQuery('input[name="wppm_project_visibility_option"]:checked').val();
  }else{
    var project_visibility = 0;
  }
  var data = {
    action: 'wppm_change_project_visibility',
    project_id:proj_id,
    project_visibility:project_visibility,
    _ajax_nonce:jQuery('#wppm_proj_visibility_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function() {
  });
}

function wppm_apply_project_filter(is_archieved){
  wppm_project_filter = jQuery('#wppm_project_filter').find(":selected").val();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_project_list',
    wppm_project_filter:wppm_project_filter,
    page:wppm_admin.page,
    is_archieved:is_archieved
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  }); 
}

function getWppmCookie(name) {
  const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
  if (match) return decodeURIComponent(match[2]);
  return null;
}

function wppm_apply_task_filter(page = 1, listFilters = null) {
  // 🔥 use passed filters OR read from UI
  if (!listFilters) {
    listFilters = {
      created_by: jQuery("#tb-created-by").val() || [],
      assigned: jQuery("#tb-assigned").val() || [],
      priority: jQuery("#tb-priority").val() || [],
      start_date: jQuery("#tb-start-date").val() || "",
      end_date: jQuery("#tb-end-date").val() || ""
    };
  }
  // 🔥 get main filter
  let wppm_task_filter = jQuery('#wppm_task_filter').val();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.post(wppm_admin.ajax_url, {
    action: 'wppm_get_task_list',
    wppm_task_filter: wppm_task_filter,
    page: page,
    listFilters: JSON.stringify(listFilters) // ✅ ALWAYS stringify
  }, function (response) {
    jQuery('#wppm_task_container').html(response);
    // 🔥 save cookie
    setListFilterCookie(listFilters);
    // 🔥 sync UI
    setTimeout(function () {
      syncUIWithFilters(listFilters);
      renderActiveFilters(listFilters);
    }, 100);

  });
}

function wppm_tl_reset_filter(page){
  var url = new URL(window.location.href);
  if (url.searchParams.has('wppm_task_filter')) {
      url.searchParams.delete('wppm_task_filter');
      window.location.href = url.toString();
      return false;
  }
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_task_list',
    wppm_task_filter:'all',
    task_search:"",
    sort_by:"task_name",
    order:"ASC",
    wppm_proj_filter:0,
    page:page
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  }); 
   // ✅ close popup
  jQuery("#tb-advanced-panel").removeClass("tb-open");
  jQuery("#tb-backdrop").removeClass("active");

  // ✅ clear inputs
  jQuery('#tb-advanced-panel input').val('');
  jQuery('#tb-advanced-panel select').val([]);

  // ✅ clear chips
  jQuery("#tb-active-filters").html('');
   resetFilters('list');
}

function wppm_apply_task_filter_grid_view(page,id,filters){
  wppm_task_filter = jQuery('#wppm_task_filter').find(":selected").val();
  if (!filters) {
    filters = {
      created_by: jQuery("#tb-created-by").val() || [],
      assigned: jQuery("#tb-assigned").val() || [],
      priority: jQuery("#tb-priority").val() || [],
      start_date: jQuery("#tb-start-date").val() || "",
      end_date: jQuery("#tb-end-date").val() || ""
    };
  }
  jQuery('#wppm_task_container').html(wppm_admin.loading_html); 
  var data = {
    action: 'wppm_view_project_tasks',
    wppm_task_filter:wppm_task_filter,
    page:page,
    id:id,
    filters: JSON.stringify(filters)
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response); 
      // 🔥 save cookie
    setFilterCookie(filters);

    // 🔥 sync UI
    setTimeout(function () {
      syncUIWithFilters(filters);
      renderActiveFilters(filters);
    }, 100);
  }); 
}

function wppm_tl_reset_grid_view_filter(page,id){
  var url = new URL(window.location.href);
  if (url.searchParams.has('wppm_task_filter')) {
      url.searchParams.delete('wppm_task_filter');
      window.location.href = url.toString();
      return false;
  }
  jQuery('#wppm_task_container').html(wppm_admin.loading_html); 
  var data = {
    action: 'wppm_view_project_tasks',
    wppm_task_filter:'all',
    task_search:"",
    sort_by:"task_name",
    order:"ASC",
    wppm_proj_filter:"0",
    page:page,
    id:id
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response); 
  });
   // ✅ close popup
  jQuery("#tb-advanced-panel").removeClass("tb-open");
  jQuery("#tb-backdrop").removeClass("active");

  // ✅ clear inputs
  jQuery('#tb-advanced-panel input').val('');
  jQuery('#tb-advanced-panel select').val([]);

  // ✅ clear chips
  jQuery("#tb-active-filters").html('');
   window.localStorage.removeItem('wppm_task_filter');
  if(id!=0){
    resetFilters('kanban');
  }else{
    resetFilters('grid');
  } 
}
function wppm_pl_reset_filter(is_archieved) {
    var url = new URL(window.location.href);
    if (url.searchParams.has('wppm_project_filter')) {
        url.searchParams.delete('wppm_project_filter');
        window.location.href = url.toString();
        return false;
    }
    jQuery('#wppm_project_container').html(wppm_admin.loading_html);
    var data = {
        action: 'wppm_get_project_list',
        wppm_project_filter: 'all',
        project_search: '',
        sort_by: 'project_name',
        order: 'ASC',
        page: wppm_admin.page,
        is_archieved: is_archieved
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response) {
        jQuery('#wppm_project_container').html(response);
    });
}

function wppm_tasks_by_select_project(page){
  wppm_proj_filter = jQuery('#wppm_task_list_proj_filter').find(":selected").val();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_task_list',
    wppm_proj_filter:wppm_proj_filter,
    page:page
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  });  
}

function wppm_tasks_by_select_project_grid_view(page){
  wppm_proj_filter = jQuery('#wppm_task_list_proj_filter').find(":selected").val();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_view_project_tasks',
    wppm_proj_filter:wppm_proj_filter,
    page:page
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_task_container').html(response);
  });  
}

function wppm_reset_ap_proj_list(){
  jQuery( "#wppm_reset_ap_proj_list_btn" ).text( wppm_admin.please_wait );
  var _ajax_nonce = jQuery("#wppm_reset_ap_proj_list_nonce").val();
	var data = { action: 'wppm_reset_ap_proj_list',_ajax_nonce };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function () {
			wppm_get_ap_proj_list('project-list');
		}
	);
}

function wppm_reset_ap_task_list(){
  jQuery( "#wppm_reset_ap_task_list_btn" ).text( wppm_admin.please_wait );
  var _ajax_nonce = jQuery("#wppm_reset_ap_task_list_ajax_nonce").val();
	var data = { action: 'wppm_reset_ap_task_list',_ajax_nonce };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function () {
			wppm_get_ap_task_list('task-list');
		}
	);
}

function wppm_reset_ap_individual_proj(){
  jQuery( "#wppm_reset_ap_individual_proj_btn" ).text( wppm_admin.please_wait );
  var _ajax_nonce =  jQuery( "#wppm_reset_ap_individual_proj_ajax_nonce").val();
	var data = { action: 'wppm_reset_ap_individual_proj',
          _ajax_nonce, };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function () {
			wppm_get_ap_individual_proj('individual-project');
		}
	);
}

function wppm_reset_ap_individual_task(){
  jQuery( "#wppm_reset_ap_individual_task_btn" ).text( wppm_admin.please_wait );
  var _ajax_nonce = jQuery( "#wppm_reset_ap_individual_task_ajax_nonce" ).val();
	var data = { action: 'wppm_reset_ap_individual_task',_ajax_nonce };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function () {
			wppm_get_ap_individual_task('individual-task');
		}
	);
}

function wppm_reset_ap_modal_popup(){
  jQuery( "#wppm_reset_ap_modal_popup_btn" ).text( wppm_admin.please_wait );
  var _ajax_nonce = jQuery( "#wppm_reset_ap_modal_popup_nonce" ).val();
	var data = { action: 'wppm_reset_ap_modal_popup',_ajax_nonce };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function () {
			wppm_get_ap_modal_popup('modal-popup');
		}
	);
}

function wppm_reset_ap_grid_view(){
  jQuery( "#wppm_reset_ap_grid_view_btn" ).text( wppm_admin.please_wait );
  var wppm_reset_grid_ajax_nonce = jQuery( "#wppm_reset_ap_grid_view_ajax_nonce" ).val();
  var data = {
    action: 'wppm_reset_ap_grid_view',
    wppm_reset_grid_ajax_nonce:wppm_reset_grid_ajax_nonce
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    wppm_get_ap_grid_view('grid-view');
  }); 
}

function wppm_reset_ap_settings(){
  jQuery( "#wppm_reset_ap_settings_btn" ).text( wppm_admin.please_wait );
  var _ajax_nonce = jQuery("#wppm_reset_ap_settings_nonce").val();
	var data = { action: 'wppm_reset_ap_settings',_ajax_nonce };
	jQuery.post(
		wppm_admin.ajax_url,
		data,
		function () {
			wppm_get_ap_settings('settings');
		}
	);
}
/**
 * Bulk selector change
 */
function wppm_bulk_select_change() {
  jQuery("#wppm-bulk-actions-btn").show();
  var checked = jQuery(".wppm-bulk-selector").is(":checked");
  jQuery(".wppm-bulk-select").prop("checked", checked);
  if(!checked){
    jQuery("#wppm-bulk-actions-btn").hide();
  }
}

function wppm_task_bulk_select_change() {
  jQuery("#wppm-task-bulk-actions-btn").show();
  var checked = jQuery(".wppm-bulk-selector").is(":checked");
  jQuery(".wppm-task-bulk-select").prop("checked", checked);
  if(!checked){
    jQuery("#wppm-bulk-actions-btn").hide();
  }
}

function wppm_bulk_change_status(nonce){
  var items = jQuery(".wppm-bulk-select:checked");
  var checked = items.length === 0 ? false : true;
  jQuery(".wppm-bulk-selector").prop("checked", checked);
  if (items.length != 0) {
    var proj_ids = jQuery(".wppm-bulk-select:checked")
      .map(function () {
        return this.value;
      })
      .get();
      wppm_modal_open('Change Status'); 
    var data = {
      action: "wppm_get_bulk_change_proj_status",
      proj_ids,
      _ajax_nonce: nonce,
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
      var response = JSON.parse(response_str);
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    });
  }
}

function wppm_set_bulk_change_project_status(){
  var dataform = new FormData(jQuery('#frm_get_bulk_project_change_status')[0]);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_project_list();
  });
}

function wppm_bulk_change_category(nonce){
  var items = jQuery(".wppm-bulk-select:checked");
  var checked = items.length === 0 ? false : true;
  jQuery(".wppm-bulk-selector").prop("checked", checked);
  if (items.length != 0) {
    var proj_ids = jQuery(".wppm-bulk-select:checked")
      .map(function () {
        return this.value;
      })
      .get();
      wppm_modal_open('Change Category'); 
    var data = {
      action: "wppm_get_bulk_change_proj_cat",
      proj_ids,
      _ajax_nonce: nonce,
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
      var response = JSON.parse(response_str);
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    });
  }
}

function wppm_set_bulk_change_project_category(){
  var dataform = new FormData(jQuery('#frm_get_bulk_project_change_category')[0]);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_project_list();
  });
}

function wppm_bulk_assign_users(nonce){
  var items = jQuery(".wppm-bulk-select:checked");
  var checked = items.length === 0 ? false : true;
  jQuery(".wppm-bulk-selector").prop("checked", checked);
  if (items.length != 0) {
    var proj_ids = jQuery(".wppm-bulk-select:checked")
      .map(function () {
        return this.value;
      })
      .get();
      wppm_modal_open('Assign Co-workers'); 
    var data = {
      action: "wppm_get_bulk_assign_users",
      proj_ids,
      _ajax_nonce: nonce,
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
      var response = JSON.parse(response_str);
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    });
  }
}

function wppm_set_bulk_project_users(){
  var dataform = new FormData(jQuery('#frm_get_bulk_project_users')[0]);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_project_list();
  });
}

function wppm_bulk_delete_project(nonce){
  var items = jQuery(".wppm-bulk-select:checked");
  var checked = items.length === 0 ? false : true;
  jQuery(".wppm-bulk-selector").prop("checked", checked);
  if (items.length != 0) {
    var proj_ids = jQuery(".wppm-bulk-select:checked")
      .map(function () {
        return this.value;
      })
      .get();
      wppm_modal_open('Delete Project'); 
    var data = {
      action: "wppm_get_bulk_delete_project",
      proj_ids,
      _ajax_nonce: nonce,
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
      var response = JSON.parse(response_str);
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    });
  }
}

function wppm_set_delete_bulk_projects(){
  var dataform = new FormData(jQuery('#frm_delete_bulk_project')[0]);
  wppm_modal_close();
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_project_list();
  });
}

function wppm_bulk_change_task_status(nonce){
  var items = jQuery(".wppm-task-bulk-select:checked");
  var checked = items.length === 0 ? false : true;
  jQuery(".wppm-bulk-selector").prop("checked", checked);
  if (items.length != 0) {
    var task_ids = jQuery(".wppm-task-bulk-select:checked")
      .map(function () {
        return this.value;
      })
      .get();
      wppm_task_modal_open('Change Task Status'); 
    var data = {
      action: "wppm_get_bulk_change_task_status",
      task_ids,
      _ajax_nonce: nonce,
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
      var response = JSON.parse(response_str);
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    });
  }
}

function wppm_set_bulk_change_task_priority(){
  var dataform = new FormData(jQuery('#frm_get_bulk_task_change_priority')[0]);
  wppm_task_modal_close();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_task_list();
  });
}

function wppm_set_bulk_change_task_status(){
  var dataform = new FormData(jQuery('#frm_get_bulk_task_change_status')[0]);
  wppm_task_modal_close();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_task_list();
  });
}

function wppm_bulk_change_task_priority(nonce){
  var items = jQuery(".wppm-task-bulk-select:checked");
  var checked = items.length === 0 ? false : true;
  jQuery(".wppm-bulk-selector").prop("checked", checked);
  if (items.length != 0) {
    var task_ids = jQuery(".wppm-task-bulk-select:checked")
      .map(function () {
        return this.value;
      })
      .get();
      wppm_task_modal_open('Change Task Priority'); 
    var data = {
      action: "wppm_get_bulk_change_task_priority",
      task_ids,
      _ajax_nonce: nonce
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
      var response = JSON.parse(response_str);
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    });
  }
}

function wppm_bulk_delete_task(nonce){
  var items = jQuery(".wppm-task-bulk-select:checked");
  var checked = items.length === 0 ? false : true;
  jQuery(".wppm-bulk-selector").prop("checked", checked);
  if (items.length != 0) {
    var task_ids = jQuery(".wppm-task-bulk-select:checked")
      .map(function () {
        return this.value;
      })
      .get();
      wppm_task_modal_open('Delete Task'); 
    var data = {
      action: "wppm_get_bulk_delete_task",
      task_ids,
      _ajax_nonce: nonce,
    };
    jQuery.post(wppm_admin.ajax_url, data, function(response_str) {
      var response = JSON.parse(response_str);
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    });
  }
}

function wppm_set_delete_bulk_tasks(){
  var dataform = new FormData(jQuery('#frm_delete_bulk_tasks')[0]);
  wppm_task_modal_close();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_get_task_list();
  });
}

function wppm_print_task(id){
  jQuery('#wppmprint_menu').css('display', 'flex');
}

function wppm_open_pdf(id){
  window.open(wppm_admin.ajax_url + "?action=wppm_get_task_pdf&id=" + id, "_blank");
}

function wppm_download_pdf(id){
  window.open(wppm_admin.ajax_url + "?action=wppm_download_pdf&id=" + id, "_blank");
}

function wppm_archive_task(id,is_archived,project_id){
  if (!confirm(wppm_admin.confirm)) {
      return;
  } else {
    var data = {
      action: 'wppm_archive_task',
      id: id,
      is_archived: is_archived,
      project_id: project_id,
    };
    jQuery.post(wppm_admin.ajax_url, data, function() { 
      wppm_open_task(id,project_id);
    });
  }
}

function wppm_archive_project(project_id,is_archived){
  if (!confirm(wppm_admin.confirm)) {
      return;
  } else {
    var data = {
      action: 'wppm_archive_project',
      project_id: project_id,
      is_archived: is_archived,
    };
    jQuery.post(wppm_admin.ajax_url, data, function() { 
      wppm_open_project(project_id);
    });
  }
}

function wppm_get_print_task_settings(){
  jQuery('.wppm_setting_pills li').removeClass('active');
  jQuery('#wppm_settings_print_task').addClass('active'); 
  jQuery('.wppm_setting_col2').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_print_task_settings'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('.wppm_setting_col2').html(response);
  });
}

function wppm_set_print_task_settings(){
  jQuery('.wppm_submit_wait').show();
  var dataform = new FormData(jQuery('#wppm_print_task_settings')[0]);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    var response = JSON.parse(response_str);
    jQuery('.wppm_submit_wait').hide();
    if (response.sucess_status=='1') {
      jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege);
    }
    jQuery('#wppm_alert_success').slideDown('fast',function(){});
    setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000);
  });
}

function wppm_edit_checklist_item(item_id,checklist_id,proj_id,task_id){
  wppm_task_modal_open('Edit Checklist Item') ;
  var data = {
    action: 'wppm_edit_checklist_item',
    item_id:item_id,
    checklist_id: checklist_id,
    task_id: task_id,
    proj_id: proj_id,
    _ajax_nonce:jQuery('#wppm_edit_checklist_item_ajax_nonce').val()
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    var response = JSON.parse(response);
    if(proj_id==0){
      jQuery('#wppm_task_popup_body').html(response.body);
      jQuery('#wppm_task_popup_footer').html(response.footer);
    }else{
      jQuery('#wppm_popup_body').html(response.body);
      jQuery('#wppm_popup_footer').html(response.footer);
    }
  });
}

function wppm_set_checklist_item_name(item_id,checklist_id,task_id){
  var dataform = new FormData(jQuery('#frm_get_edit_checklist_item')[0]);
  wppm_task_modal_close();
  jQuery('#wppm_task_container').html(wppm_admin.loading_html);
  jQuery.ajax({
    url: wppm_admin.ajax_url,
    type: 'POST',
    data: dataform,
    processData: false,
    contentType: false
  })
  .done(function (response_str) {
    wppm_open_task(task_id);
  });
}

function wppm_get_project_tasks_kanban_view(proj_id, KanbanFilters = {}) {
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_project_tasks_kanban_view',
    id: proj_id,
    filters: JSON.stringify(KanbanFilters)
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  });
}

function renderActiveFilters(filters) {
    let box = document.getElementById("tb-active-filters");
    if (!box) {
        return;
    }
    // CLEAR OLD CHIPS
    box.innerHTML = "";
    if (!filters || typeof filters !== "object") {
        return;
    }
    // CREATED BY
    if (Array.isArray(filters.created_by)) {
        filters.created_by.forEach(function(id) {
            let text = jQuery('#tb-created-by option[value="' + id + '"]').text();
            if (text) {
                createChip(text, "created_by", id);
            }
        });
    }
    // ASSIGNED
    if (Array.isArray(filters.assigned)) {
        filters.assigned.forEach(function(id) {
            let text = jQuery('#tb-assigned option[value="' + id + '"]').text();
            if (text) {
              createChip(text, "assigned", id);
            }
        });
    }

    // PRIORITY
    if (Array.isArray(filters.priority)) {
        filters.priority.forEach(function(id) {
            let text = jQuery('#tb-priority option[value="' + id + '"]').text();
            if (text) {
              createChip(text, "priority", id);
            }
        });
    }

    // DATE CHIP
    if (filters.start_date || filters.end_date) {
        let dateText =
            (filters.start_date || "") +
            " → " +
            (filters.end_date || "");
        createChip(dateText, "date", "");
    }
}

function renderMulti(filters, key, selector, label) {
  if (!filters || !filters[key]) {
    return;
  }
  let values = filters[key] || [];
  if (!Array.isArray(values) || values.length === 0) {
    return;
  }
  jQuery(selector + " option").each(function () {
    let val = String(jQuery(this).val());
    let text = jQuery(this).text();
    if (values.map(String).includes(val)) {
      createChip(`${label}: ${text}`, key, val);
    }
  });
}

function createChip(text, key, value) {
    let container = document.getElementById("tb-active-filters");
    if (!container) {
        return;
    }
    let chip = document.createElement("span");
    chip.className = "tb-chip";
    chip.innerHTML = `
        ${key.charAt(0).toUpperCase() + key.slice(1)}: ${text}
        <span
            class="tb-remove"
            data-key="${key}"
            data-value="${value || ''}"
        >
            ✕
        </span>
    `;
    container.appendChild(chip);
}

function syncUIWithFilters(filters) {
    jQuery("#tb-created-by")
        .val(filters.created_by || [])
        .trigger("change");

    jQuery("#tb-assigned")
        .val(filters.assigned || [])
        .trigger("change");

    jQuery("#tb-priority")
        .val(filters.priority || [])
        .trigger("change");

    jQuery("#tb-start-date")
        .val(filters.start_date || "");

    jQuery("#tb-end-date")
        .val(filters.end_date || "");
}

function resetFilters(view_type) {
  let emptyFilters = {
    created_by: [],
    assigned: [],
    priority: [],
    start_date: "",
    end_date: "",
    id: jQuery('#wppm_proj_id').val() || 0
  };
  // Reset UI fields
  jQuery("#tb-created-by").val(null).trigger("change");
  jQuery("#tb-assigned").val(null).trigger("change");
  jQuery("#tb-priority").val(null).trigger("change");
  jQuery("#tb-start-date").val("");
  jQuery("#tb-end-date").val("");
  if (view_type === 'grid') {
    window.filters = { ...emptyFilters };
    // Delete cookie
    document.cookie =
      "tb_filters=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
    // Apply fresh filters
    wppm_apply_task_filter_grid_view('0',emptyFilters.id,window.filters);
  }
  if (view_type === 'list') {
    window.listFilters = { ...emptyFilters };
    // Delete cookie
    document.cookie =
      "tb_list_filters=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
    // Apply fresh filters
    wppm_apply_task_filter(1, window.listFilters);
  }
  if (view_type === 'kanban') {
    window.KanbanFilters = { ...emptyFilters };
    // Delete cookie
    document.cookie =
      "tb_kanban_filters=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
    // Apply fresh filters
    wppm_get_project_tasks_kanban_view(
      window.KanbanFilters.id,
      window.KanbanFilters
    );
  }
}

function getFilterCookie() {
  let name = "tb_filters=";
  let arr = document.cookie.split(';');
  for (let i = 0; i < arr.length; i++) {
    let c = arr[i].trim();
    if (c.indexOf(name) === 0) {
      try {
        return JSON.parse(decodeURIComponent(c.substring(name.length)));
      } catch (e) {
        return null;
      }
    }
  }
  return null;
}

function getListFilterCookie() {
  let name = "tb_list_filters=";
  let arr = document.cookie.split(';');
  for (let i = 0; i < arr.length; i++) {
    let c = arr[i].trim();
    if (c.indexOf(name) === 0) {
      try {
        return JSON.parse(decodeURIComponent(c.substring(name.length)));
      } catch (e) {
        return null;
      }
    }
  }
  return null;
}

function getKanbanFilterCookie() {
  let name = "tb_kanban_filters=";
  let arr = document.cookie.split(';');
  for (let i = 0; i < arr.length; i++) {
    let c = arr[i].trim();
    if (c.indexOf(name) === 0) {
      try {
        return JSON.parse(decodeURIComponent(c.substring(name.length)));
      } catch (e) {
        return null;
      }
    }
  }
  return null;
}

function setFilterCookie(filters) {
  document.cookie =
    "tb_filters=" + encodeURIComponent(JSON.stringify(filters)) +
    ";path=/;max-age=" + (60 * 60 * 24);
}

function setListFilterCookie(listFilters) {
  document.cookie =
    "tb_list_filters=" + encodeURIComponent(JSON.stringify(listFilters)) +
    ";path=/;max-age=" + (60 * 60 * 24);
}

function setKanbanFilterCookie(KanbanFilters) {
  document.cookie =
    "tb_kanban_filters=" + encodeURIComponent(JSON.stringify(KanbanFilters)) +
    ";path=/;max-age=" + (60 * 60 * 24);
}

let filterTimeout;
function triggerFilter(page = 1, filters = {}, view_type = 'list', proj_id = 0) {
    clearTimeout(filterTimeout);
    filterTimeout = setTimeout(function () {
        if (view_type === 'grid') {
            wppm_apply_task_filter_grid_view(
                page,
                proj_id,
                filters
            );
        }
        if (view_type === 'list') {
            wppm_apply_task_filter(
                page,
                filters
            );
        }
        if (view_type === 'kanban') {
            wppm_get_project_tasks_kanban_view(
                proj_id,
                filters
            );
        }
    }, 300);
}

function wppm_archieve_project_list(){
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_archieve_project_list'
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  });
}

function wppm_get_archieve_project_list(page_no){
  jQuery('#wppm_project_container').html(wppm_admin.loading_html);
  var data = {
    action: 'wppm_get_project_list',
    page_no:page_no,
    is_archieved:1
  };
  jQuery.post(wppm_admin.ajax_url, data, function(response) {
    jQuery('#wppm_project_container').html(response);
  });
}

```
