| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpdb, $wppmfunction; |
| 7 |
if (!($current_user->ID && $current_user->has_cap('manage_options'))) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
$priorities = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wppm_task_priorities ORDER BY load_order ASC" ); |
| 11 |
$priority_arr = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}wppm_task_priorities" ); |
| 12 |
$priority_ids = array(); |
| 13 |
if(!empty($priority_arr)){ |
| 14 |
foreach($priority_arr as $key=>$val){ |
| 15 |
$priorities_array= json_decode(json_encode($val)); |
| 16 |
$priority_ids[] = $priorities_array->id; |
| 17 |
} |
| 18 |
$priority_ids = $wppmfunction->sanitize_array($priority_ids); |
| 19 |
} |
| 20 |
$wppm_ap_settings = get_option("wppm-ap-settings"); |
| 21 |
?> |
| 22 |
<div id="wppm_task_priorities_container"> |
| 23 |
<div class="wppm-help-container"> |
| 24 |
<a href="https://taskbuilder.net/docs/task-priorities/" target="_blank"><?php echo esc_attr__( 'Click here', 'taskbuilder' )?></a> <?php echo esc_attr__( 'to see the documentation!', 'taskbuilder' )?> |
| 25 |
</div> |
| 26 |
<span class="wppm-title"> |
| 27 |
<?php echo esc_html_e('Task Priorities','taskbuilder');?> |
| 28 |
</span> |
| 29 |
<span style="margin-left:10px;background-color:<?php echo esc_attr($wppm_ap_settings['add-new-button-bg-color'])?>;color:<?php echo esc_attr($wppm_ap_settings['add-new-button-text-color'])?>;" class="wppm-add-new-btn wppm_btn btn-primary" onclick="wppm_add_task_priority();"><?php echo esc_html_e('+Add New','taskbuilder');?></span> |
| 30 |
<div class="wppm_padding_space"></div> |
| 31 |
<ul class="wppm-sortable"> |
| 32 |
<?php |
| 33 |
if(!empty($priorities)){ |
| 34 |
foreach ($priorities as $priority){ |
| 35 |
$color=$priority->color; |
| 36 |
$background_color=$priority->bg_color; |
| 37 |
?> |
| 38 |
<li class="ui-state-default" data-id="<?php echo esc_attr($priority->id)?>"> |
| 39 |
<div class="wppm-flex-container"style="background-color:<?php echo esc_attr($background_color)?>;color:<?php echo esc_attr($color)?>;"> |
| 40 |
<div class="wppm-sortable-handle"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/filter.svg'); ?>" alt="filter"></div> |
| 41 |
<div class="wppm-sortable-label"><?php echo esc_html_e($priority->name,'taskbuilder') ?></div> |
| 42 |
<div class="wppm-sortable-edit" data-toggle="tooltip" title="Edit" data-placement="top" onclick="wppm_get_edit_task_priority(<?php echo esc_attr($priority->id)?>);"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/edit1.svg'); ?>" alt="edit"></div> |
| 43 |
<div class="wppm-sortable-delete" data-toggle="tooltip" title="Delete" data-placement="top" onclick="wppm_delete_task_priority(<?php echo esc_attr($priority->id)?>);"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/trash.svg'); ?>" alt="delete"></div> |
| 44 |
</div> |
| 45 |
</li> |
| 46 |
|
| 47 |
<?php } |
| 48 |
} |
| 49 |
?> |
| 50 |
</ul> |
| 51 |
<input type="hidden" name="wppm_prio_order_ajax_nonce" id="wppm_prio_order_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wppm_set_priority_order' ) ); ?>"> |
| 52 |
<input type="hidden" name="wppm_delete_tprio_ajax_nonce" id="wppm_delete_tprio_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wppm_delete_task_priority' ) ); ?>"> |
| 53 |
<div> |
| 54 |
<style> |
| 55 |
#wppm_task_priorities_container .wppm-add-new-btn:hover{ |
| 56 |
background-color: <?php echo esc_attr($wppm_ap_settings['add-new-button-hover-color'])?>!important; |
| 57 |
} |
| 58 |
</style> |
| 59 |
<script> |
| 60 |
jQuery(function(){ |
| 61 |
jQuery( ".wppm-sortable" ).sortable({ handle: '.wppm-sortable-handle' }); |
| 62 |
jQuery( ".wppm-sortable" ).on("sortupdate",function(event,ui){ |
| 63 |
var keys = jQuery(this).sortable( "toArray", {attribute: 'data-id'} ); |
| 64 |
var priority_order = <?php echo json_encode($priority_ids); ?>; |
| 65 |
var result = {}; |
| 66 |
for (var i = 0; i < keys.length; i++){ |
| 67 |
result[keys[i]] = priority_order[i]; |
| 68 |
} |
| 69 |
var data = { |
| 70 |
action: 'wppm_set_priority_order', |
| 71 |
load_orders : result, |
| 72 |
_ajax_nonce : jQuery('#wppm_prio_order_ajax_nonce').val() |
| 73 |
}; |
| 74 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 75 |
var response = JSON.parse(response_str); |
| 76 |
if (response.sucess_status==1) { |
| 77 |
jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege); |
| 78 |
} |
| 79 |
jQuery('#wppm_alert_success').slideDown('fast',function(){}); |
| 80 |
setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000); |
| 81 |
}); |
| 82 |
}); |
| 83 |
}); |
| 84 |
|
| 85 |
function wppm_set_add_priority(){ |
| 86 |
var priority_name = jQuery('#wppm_priority_name').val().trim(); |
| 87 |
if (priority_name.length == 0) { |
| 88 |
jQuery('#wppm_priority_name').val('').focus(); |
| 89 |
return; |
| 90 |
} |
| 91 |
var priority_color = jQuery('#wppm_priority_color').val().trim(); |
| 92 |
if (priority_color.length == 0) { |
| 93 |
priority_color = '#ffffff'; |
| 94 |
} |
| 95 |
var priority_bg_color = jQuery('#wppm_priority_bg_color').val().trim(); |
| 96 |
if (priority_bg_color.length == 0) { |
| 97 |
priority_bg_color = '#1E90FF'; |
| 98 |
} |
| 99 |
jQuery('.wppm_popup_action').text('<?php _e('Please wait ...','taskbuilder')?>'); |
| 100 |
jQuery('.wppm_popup_action, #wppm_popup_body input').attr("disabled", "disabled"); |
| 101 |
var data = { |
| 102 |
action: 'wppm_set_add_priority', |
| 103 |
priority_name : priority_name, |
| 104 |
priority_color: priority_color, |
| 105 |
priority_bg_color: priority_bg_color, |
| 106 |
_ajax_nonce:jQuery('[name="_ajax_nonce"]').val() |
| 107 |
}; |
| 108 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 109 |
wppm_modal_close(); |
| 110 |
var response = JSON.parse(response_str); |
| 111 |
wppm_get_task_prioriy_settings(); |
| 112 |
if (response.sucess_status=='1') { |
| 113 |
jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege); |
| 114 |
jQuery('#wppm_alert_success').slideDown('fast',function(){}); |
| 115 |
setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000); |
| 116 |
wppm_get_task_prioriy_settings(); |
| 117 |
} else { |
| 118 |
jQuery('#wppm_alert_error .wppm_alert_text').text(response.messege); |
| 119 |
jQuery('#wppm_alert_error').slideDown('fast',function(){}); |
| 120 |
setTimeout(function(){ jQuery('#wppm_alert_error').slideUp('fast',function(){}); }, 3000); |
| 121 |
} |
| 122 |
}) |
| 123 |
} |
| 124 |
|
| 125 |
function wppm_get_edit_task_priority(priority_id){ |
| 126 |
wppm_modal_open(wppm_admin.edit_status); |
| 127 |
var data = { |
| 128 |
action : 'wppm_get_edit_priority', |
| 129 |
priority_id:priority_id |
| 130 |
}; |
| 131 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 132 |
var response = JSON.parse(response_str); |
| 133 |
jQuery('#wppm_popup_body').html(response.body); |
| 134 |
jQuery('#wppm_popup_footer').html(response.footer); |
| 135 |
jQuery('#wppm_proj_status_name').focus(); |
| 136 |
}) |
| 137 |
} |
| 138 |
|
| 139 |
function wppm_set_edit_priority(priority_id){ |
| 140 |
var priority_name = jQuery('#wppm_edit_priority_name').val().trim(); |
| 141 |
if (priority_name.length == 0) { |
| 142 |
jQuery('#wppm_edit_priority_name').val('').focus(); |
| 143 |
return; |
| 144 |
} |
| 145 |
var priority_color = jQuery('#wppm_edit_priority_color').val().trim(); |
| 146 |
if (priority_color.length == 0) { |
| 147 |
priority_color = '#ffffff'; |
| 148 |
} |
| 149 |
var priority_bg_color = jQuery('#wppm_edit_priority_bg_color').val().trim(); |
| 150 |
if (priority_bg_color.length == 0) { |
| 151 |
priority_bg_color = '#1E90FF'; |
| 152 |
} |
| 153 |
jQuery('.wppm_popup_action').text('<?php _e('Please wait ...','taskbuilder')?>'); |
| 154 |
jQuery('.wppm_popup_action, #wppm_popup_body input').attr("disabled", "disabled"); |
| 155 |
var data = { |
| 156 |
action : 'wppm_set_edit_priority', |
| 157 |
priority_id:priority_id, |
| 158 |
priority_name:priority_name, |
| 159 |
priority_color: priority_color, |
| 160 |
priority_bg_color: priority_bg_color, |
| 161 |
_ajax_nonce:jQuery('[name="_ajax_nonce"]').val() |
| 162 |
}; |
| 163 |
jQuery.post(wppm_admin.ajax_url, data, function(response_str) { |
| 164 |
wppm_modal_close(); |
| 165 |
var response = JSON.parse(response_str); |
| 166 |
wppm_get_task_prioriy_settings(); |
| 167 |
if (response.sucess_status=='1') { |
| 168 |
jQuery('#wppm_alert_success .wppm_alert_text').text(response.messege); |
| 169 |
jQuery('#wppm_alert_success').slideDown('fast',function(){}); |
| 170 |
setTimeout(function(){ jQuery('#wppm_alert_success').slideUp('fast',function(){}); }, 3000); |
| 171 |
wppm_get_task_prioriy_settings(); |
| 172 |
} else { |
| 173 |
jQuery('#wppm_alert_error .wppm_alert_text').text(response.messege); |
| 174 |
jQuery('#wppm_alert_error').slideDown('fast',function(){}); |
| 175 |
setTimeout(function(){ jQuery('#wppm_alert_error').slideUp('fast',function(){}); }, 3000); |
| 176 |
} |
| 177 |
}); |
| 178 |
} |
| 179 |
</script> |