| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
?> |
| 6 |
<?php |
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly |
| 9 |
} |
| 10 |
|
| 11 |
global $current_user, $wpdb, $wppmfunction; |
| 12 |
if (!($current_user->ID && $current_user->has_cap('manage_options'))) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
$statuses = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wppm_task_statuses ORDER BY load_order ASC" ); |
| 16 |
$status_arr = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}wppm_task_statuses" ); |
| 17 |
$status_ids=array(); |
| 18 |
if(!empty($status_arr)){ |
| 19 |
foreach($status_arr as $key=>$val){ |
| 20 |
$statuses_array= json_decode(json_encode($val)); |
| 21 |
$status_ids[] = $statuses_array->id; |
| 22 |
} |
| 23 |
$status_ids = $wppmfunction->sanitize_array($status_ids); |
| 24 |
} |
| 25 |
?> |
| 26 |
<div id="wppm_task_statuses_container"> |
| 27 |
<span class="wppm-title"> |
| 28 |
<?php echo esc_html_e('Task Statuses','taskbuilder');?> |
| 29 |
<span style="margin-left:10px;" class="wppm_btn btn-primary wppm-add-new-btn" onclick="wppm_get_add_task_status();"><?php echo esc_html_e('+Add New','taskbuilder');?></span> |
| 30 |
</span> |
| 31 |
<div class="wppm_padding_space"></div> |
| 32 |
<ul class="wppm-sortable"> |
| 33 |
<?php |
| 34 |
if(!empty($statuses)){ |
| 35 |
foreach ($statuses as $status){ |
| 36 |
$color=$status->color; |
| 37 |
$background_color=$status->bg_color; |
| 38 |
?> |
| 39 |
<li class="ui-state-default" data-id="<?php echo esc_attr($status->id)?>"> |
| 40 |
<div class="wppm-flex-container"style="background-color:<?php echo esc_attr($background_color)?>;color:<?php echo esc_attr($color)?>;"> |
| 41 |
<div class="wppm-sortable-handle"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/filter.svg'); ?>" alt="filter"></div> |
| 42 |
<div class="wppm-sortable-label"><?php echo esc_html_e($status->name,'taskbuilder')?></div> |
| 43 |
<div class="wppm-sortable-edit" onclick="wppm_get_edit_task_status(<?php echo esc_attr($status->id)?>);"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/edit1.svg'); ?>" alt="edit"></div> |
| 44 |
<div class="wppm-sortable-delete" onclick="wppm_delete_task_status(<?php echo esc_attr($status->id)?>);"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/trash.svg'); ?>" alt="delete"></div> |
| 45 |
</div> |
| 46 |
</li> |
| 47 |
|
| 48 |
<?php } |
| 49 |
} |
| 50 |
?> |
| 51 |
</ul> |
| 52 |
<div> |
| 53 |
<script> |
| 54 |
jQuery(function(){ |
| 55 |
jQuery( ".wppm-sortable" ).sortable({ handle: '.wppm-sortable-handle' }); |
| 56 |
jQuery( ".wppm-sortable" ).on("sortupdate",function(event,ui){ |
| 57 |
var keys = jQuery(this).sortable( "toArray", {attribute: 'data-id'} ); |
| 58 |
var status_order = <?php echo json_encode($status_ids); ?>; |
| 59 |
var result = {}; |
| 60 |
for (var i = 0; i < keys.length; i++){ |
| 61 |
result[keys[i]] = status_order[i]; |
| 62 |
} |
| 63 |
var data = { |
| 64 |
action: 'wppm_set_task_status_order', |
| 65 |
load_orders : result |
| 66 |
}; |
| 67 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 68 |
var response = JSON.parse(response_str); |
| 69 |
if (response.sucess_status==1) { |
| 70 |
jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege); |
| 71 |
} |
| 72 |
jQuery('#wppm_alert_success').slideDown('fast',function(){}); |
| 73 |
setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000); |
| 74 |
}); |
| 75 |
}); |
| 76 |
}); |
| 77 |
|
| 78 |
function wppm_set_add_task_status(){ |
| 79 |
var status_name = jQuery('#wppm_task_status_name').val().trim(); |
| 80 |
if (status_name.length == 0) { |
| 81 |
jQuery('#wppm_task_status_name').val('').focus(); |
| 82 |
return; |
| 83 |
} |
| 84 |
var status_color = jQuery('#wppm_task_status_color').val().trim(); |
| 85 |
if (status_color.length == 0) { |
| 86 |
status_color = '#ffffff'; |
| 87 |
} |
| 88 |
var status_bg_color = jQuery('#wppm_task_status_bg_color').val().trim(); |
| 89 |
if (status_bg_color.length == 0) { |
| 90 |
status_bg_color = '#1E90FF'; |
| 91 |
} |
| 92 |
jQuery('.wppm_popup_action').text('<?php _e('Please wait ...','taskbuilder')?>'); |
| 93 |
jQuery('.wppm_popup_action, #wppm_popup_body input').attr("disabled", "disabled"); |
| 94 |
var data = { |
| 95 |
action: 'wppm_set_add_task_status', |
| 96 |
status_name : status_name, |
| 97 |
status_color: status_color, |
| 98 |
status_bg_color: status_bg_color |
| 99 |
}; |
| 100 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 101 |
wppm_modal_close(); |
| 102 |
var response = JSON.parse(response_str); |
| 103 |
wppm_get_task_status_settings(); |
| 104 |
if (response.sucess_status=='1') { |
| 105 |
jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege); |
| 106 |
jQuery('#wppm_alert_success').slideDown('fast',function(){}); |
| 107 |
setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000); |
| 108 |
wppm_get_task_status_settings(); |
| 109 |
} else { |
| 110 |
jQuery('#wppm_alert_error .wppm_alert_text').text(response.messege); |
| 111 |
jQuery('#wppm_alert_error').slideDown('fast',function(){}); |
| 112 |
setTimeout(function(){ jQuery('#wppm_alert_error').slideUp('fast',function(){}); }, 3000); |
| 113 |
} |
| 114 |
}) |
| 115 |
} |
| 116 |
|
| 117 |
function wppm_get_edit_task_status(status_id){ |
| 118 |
wppm_modal_open(wppm_admin.edit_status); |
| 119 |
var data = { |
| 120 |
action : 'wppm_get_edit_task_status', |
| 121 |
status_id:status_id |
| 122 |
}; |
| 123 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 124 |
var response = JSON.parse(response_str); |
| 125 |
jQuery('#wppm_popup_body').html(response.body); |
| 126 |
jQuery('#wppm_popup_footer').html(response.footer); |
| 127 |
jQuery('#wppm_proj_status_name').focus(); |
| 128 |
}) |
| 129 |
} |
| 130 |
|
| 131 |
function wppm_set_edit_task_status(status_id){ |
| 132 |
var status_name = jQuery('#wppm_edit_task_status_name').val().trim(); |
| 133 |
if (status_name.length == 0) { |
| 134 |
jQuery('#wppm_edit_task_status_name').val('').focus(); |
| 135 |
return; |
| 136 |
} |
| 137 |
var status_color = jQuery('#wppm_edit_task_status_color').val().trim(); |
| 138 |
if (status_color.length == 0) { |
| 139 |
status_color = '#ffffff'; |
| 140 |
} |
| 141 |
var status_bg_color = jQuery('#wppm_edit_task_status_bg_color').val().trim(); |
| 142 |
if (status_bg_color.length == 0) { |
| 143 |
status_bg_color = '#1E90FF'; |
| 144 |
} |
| 145 |
jQuery('.wppm_popup_action').text('<?php _e('Please wait ...','taskbuilder')?>'); |
| 146 |
jQuery('.wppm_popup_action, #wppm_popup_body input').attr("disabled", "disabled"); |
| 147 |
var data = { |
| 148 |
action : 'wppm_set_edit_task_status', |
| 149 |
status_id:status_id, |
| 150 |
status_name:status_name, |
| 151 |
status_color: status_color, |
| 152 |
status_bg_color: status_bg_color |
| 153 |
}; |
| 154 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 155 |
wppm_modal_close(); |
| 156 |
var response = JSON.parse(response_str); |
| 157 |
wppm_get_task_status_settings(); |
| 158 |
if (response.sucess_status=='1') { |
| 159 |
jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege); |
| 160 |
jQuery('#wppm_alert_success').slideDown('fast',function(){}); |
| 161 |
setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000); |
| 162 |
wppm_get_task_status_settings(); |
| 163 |
} else { |
| 164 |
jQuery('#wppm_alert_error .wppm_alert_text').text(response.messege); |
| 165 |
jQuery('#wppm_alert_error').slideDown('fast',function(){}); |
| 166 |
setTimeout(function(){ jQuery('#wppm_alert_error').slideUp('fast',function(){}); }, 3000); |
| 167 |
} |
| 168 |
}); |
| 169 |
} |
| 170 |
</script> |
| 171 |
|