| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpdb; |
| 7 |
if (!($current_user->ID && $current_user->has_cap('manage_options'))) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
$priorities = get_terms([ |
| 12 |
'taxonomy' => 'wpsc_priorities', |
| 13 |
'hide_empty' => false, |
| 14 |
'orderby' => 'meta_value_num', |
| 15 |
'order' => 'ASC', |
| 16 |
'meta_query' => array('order_clause' => array('key' => 'wpsc_priority_load_order')), |
| 17 |
]); |
| 18 |
|
| 19 |
?> |
| 20 |
<h4> |
| 21 |
<?php _e('Ticket Priorities','supportcandy');?> |
| 22 |
<button style="margin-left:10px;" class="btn btn-success btn-sm" onclick="wpsc_get_add_priority();"><?php _e('+Add New','supportcandy');?></button> |
| 23 |
</h4> |
| 24 |
|
| 25 |
<div class="wpsc_padding_space"></div> |
| 26 |
|
| 27 |
<ul class="wpsc-sortable"> |
| 28 |
<?php foreach ( $priorities as $priority ) : |
| 29 |
$color = get_term_meta( $priority->term_id, 'wpsc_priority_color', true); |
| 30 |
$backgound_color = get_term_meta( $priority->term_id, 'wpsc_priority_background_color', true); |
| 31 |
?> |
| 32 |
<li class="ui-state-default" data-id="<?php echo esc_attr($priority->term_id)?>"> |
| 33 |
<div class="wpsc-flex-container" style="background-color:<?php echo esc_attr($backgound_color)?>;color:<?php echo esc_attr($color)?>;"> |
| 34 |
<div class="wpsc-sortable-handle"><i class="fa fa-bars"></i></div> |
| 35 |
<div class="wpsc-sortable-label"><?php echo esc_attr($priority->name)?></div> |
| 36 |
<div class="wpsc-sortable-edit" onclick="wpsc_get_edit_priority(<?php echo esc_attr($priority->term_id)?>);"><i class="fa fa-edit"></i></div> |
| 37 |
<div class="wpsc-sortable-delete" onclick="wpsc_delete_priority(<?php echo esc_attr($priority->term_id)?>);"><i class="fa fa-trash"></i></div> |
| 38 |
</div> |
| 39 |
</li> |
| 40 |
<?php endforeach;?> |
| 41 |
</ul> |
| 42 |
|
| 43 |
<script> |
| 44 |
|
| 45 |
jQuery(function(){ |
| 46 |
jQuery( ".wpsc-sortable" ).sortable({ handle: '.wpsc-sortable-handle' }); |
| 47 |
jQuery( ".wpsc-sortable" ).on("sortupdate",function(event,ui){ |
| 48 |
var ids = jQuery(this).sortable( "toArray", {attribute: 'data-id'} ); |
| 49 |
var data = { |
| 50 |
action: 'wpsc_settings', |
| 51 |
setting_action : 'set_priority_order', |
| 52 |
priority_ids : ids, |
| 53 |
_ajax_nonce: '<?php echo wp_create_nonce('set_priority_order')?>' |
| 54 |
}; |
| 55 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 56 |
var response = JSON.parse(response_str); |
| 57 |
if (response.sucess_status=='1') { |
| 58 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 59 |
} |
| 60 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 61 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 62 |
}); |
| 63 |
}); |
| 64 |
}); |
| 65 |
|
| 66 |
function wpsc_get_add_priority(){ |
| 67 |
wpsc_modal_open(wpsc_admin.add_new_priority); |
| 68 |
var data = { |
| 69 |
action: 'wpsc_settings', |
| 70 |
setting_action : 'get_add_priority' |
| 71 |
}; |
| 72 |
jQuery.post(wpsc_admin.ajax_url, data, function(response) { |
| 73 |
jQuery('#wpsc_popup_body').html(response.body); |
| 74 |
jQuery('#wpsc_popup_footer').html(response.footer); |
| 75 |
jQuery('#wpsc_cat_name').focus(); |
| 76 |
}); |
| 77 |
} |
| 78 |
|
| 79 |
function wpsc_set_add_priority(){ |
| 80 |
var status_name = jQuery('#wpsc_priority_name').val().trim(); |
| 81 |
if (status_name.length == 0) { |
| 82 |
jQuery('#wpsc_priority_name').val('').focus(); |
| 83 |
return; |
| 84 |
} |
| 85 |
var status_color = jQuery('#wpsc_priority_color').val().trim(); |
| 86 |
if (status_color.length == 0) { |
| 87 |
status_color = '#ffffff'; |
| 88 |
} |
| 89 |
var status_bg_color = jQuery('#wpsc_priority_bg_color').val().trim(); |
| 90 |
if (status_bg_color.length == 0) { |
| 91 |
status_bg_color = '#1E90FF'; |
| 92 |
} |
| 93 |
jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>'); |
| 94 |
jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled"); |
| 95 |
var data = { |
| 96 |
action: 'wpsc_settings', |
| 97 |
setting_action : 'set_add_priority', |
| 98 |
priority_name : status_name, |
| 99 |
priority_color: status_color, |
| 100 |
priority_bg_color: status_bg_color, |
| 101 |
_ajax_nonce: '<?php echo wp_create_nonce('set_add_priority')?>' |
| 102 |
}; |
| 103 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 104 |
wpsc_modal_close(); |
| 105 |
var response = JSON.parse(response_str); |
| 106 |
if (response.sucess_status=='1') { |
| 107 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 108 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 109 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 110 |
wpsc_get_priority_settings(); |
| 111 |
} else { |
| 112 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 113 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 114 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 115 |
} |
| 116 |
}); |
| 117 |
} |
| 118 |
|
| 119 |
function wpsc_get_edit_priority(priority_id){ |
| 120 |
wpsc_modal_open(wpsc_admin.edit_priority); |
| 121 |
var data = { |
| 122 |
action: 'wpsc_settings', |
| 123 |
setting_action : 'get_edit_priority', |
| 124 |
priority_id : priority_id |
| 125 |
}; |
| 126 |
jQuery.post(wpsc_admin.ajax_url, data, function(response) { |
| 127 |
jQuery('#wpsc_popup_body').html(response.body); |
| 128 |
jQuery('#wpsc_popup_footer').html(response.footer); |
| 129 |
jQuery('#wpsc_priority_name').focus(); |
| 130 |
}); |
| 131 |
} |
| 132 |
|
| 133 |
function wpsc_set_edit_priority(priority_id){ |
| 134 |
var priority_name = jQuery('#wpsc_priority_name').val().trim(); |
| 135 |
if (priority_name.length == 0) { |
| 136 |
jQuery('#wpsc_priority_name').val('').focus(); |
| 137 |
return; |
| 138 |
} |
| 139 |
var priority_color = jQuery('#wpsc_priority_color').val().trim(); |
| 140 |
if (priority_color.length == 0) { |
| 141 |
priority_color = '#ffffff'; |
| 142 |
} |
| 143 |
var priority_bg_color = jQuery('#wpsc_priority_bg_color').val().trim(); |
| 144 |
if (priority_bg_color.length == 0) { |
| 145 |
priority_bg_color = '#1E90FF'; |
| 146 |
} |
| 147 |
jQuery('.wpsc_popup_action').text('<?php _e('Please wait ...','supportcandy')?>'); |
| 148 |
jQuery('.wpsc_popup_action, #wpsc_popup_body input').attr("disabled", "disabled"); |
| 149 |
var data = { |
| 150 |
action: 'wpsc_settings', |
| 151 |
setting_action : 'set_edit_priority', |
| 152 |
priority_id : priority_id, |
| 153 |
priority_name : priority_name, |
| 154 |
priority_color: priority_color, |
| 155 |
priority_bg_color: priority_bg_color, |
| 156 |
_ajax_nonce: '<?php echo wp_create_nonce('set_edit_priority')?>' |
| 157 |
}; |
| 158 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 159 |
wpsc_modal_close(); |
| 160 |
var response = JSON.parse(response_str); |
| 161 |
if (response.sucess_status=='1') { |
| 162 |
wpsc_get_priority_settings(); |
| 163 |
} else { |
| 164 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 165 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 166 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 167 |
} |
| 168 |
}); |
| 169 |
} |
| 170 |
|
| 171 |
function wpsc_delete_priority(priority_id){ |
| 172 |
var flag = confirm(wpsc_admin.are_you_sure); |
| 173 |
if (flag) { |
| 174 |
var data = { |
| 175 |
action: 'wpsc_settings', |
| 176 |
setting_action : 'delete_priority', |
| 177 |
priority_id : priority_id, |
| 178 |
_ajax_nonce: '<?php echo wp_create_nonce('delete_priority')?>' |
| 179 |
}; |
| 180 |
jQuery.post(wpsc_admin.ajax_url, data, function(response_str) { |
| 181 |
var response = JSON.parse(response_str); |
| 182 |
if (response.sucess_status=='1') { |
| 183 |
jQuery('#wpsc_alert_success .wpsc_alert_text').text(response.messege); |
| 184 |
jQuery('#wpsc_alert_success').slideDown('fast',function(){}); |
| 185 |
setTimeout(function(){ jQuery('#wpsc_alert_success').slideUp('fast',function(){}); }, 3000); |
| 186 |
wpsc_get_priority_settings(); |
| 187 |
} else { |
| 188 |
jQuery('#wpsc_alert_error .wpsc_alert_text').text(response.messege); |
| 189 |
jQuery('#wpsc_alert_error').slideDown('fast',function(){}); |
| 190 |
setTimeout(function(){ jQuery('#wpsc_alert_error').slideUp('fast',function(){}); }, 3000); |
| 191 |
} |
| 192 |
}); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
</script> |
| 197 |
|