← All changes
|
includes/admin/settings/class-wpsc-ticket-statuses.php
+77
-2
3.5.2
→
3.5.4
View file →
| @@ -25,8 +25,11 @@ | ||
| 25 | 25 | |
| 26 | 26 | // Delete. |
| 27 | 27 | add_action( 'wp_ajax_wpsc_get_delete_status', array( __CLASS__, 'get_delete_status' ) ); |
| 28 | 28 | add_action( 'wp_ajax_wpsc_set_delete_status', array( __CLASS__, 'set_delete_status' ) ); |
| 29 | + | |
| 30 | + // Sorting. | |
| 31 | + add_action( 'wp_ajax_wpsc_set_status_load_order', array( __CLASS__, 'set_status_load_order' ) ); | |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | 34 | /** |
| 32 | 35 | * Get status settings |
| @@ -60,8 +63,9 @@ | ||
| 60 | 63 | </div> |
| 61 | 64 | <table class="wpsc-ticket-statuses wpsc-setting-tbl"> |
| 62 | 65 | <thead> |
| 63 | 66 | <tr> |
| 67 | + <th style="width: 30px;"><?php esc_attr_e( 'Sort', 'supportcandy' ); ?></th> | |
| 64 | 68 | <th><?php esc_attr_e( 'Name', 'supportcandy' ); ?></th> |
| 65 | 69 | <th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th> |
| 66 | 70 | </tr> |
| 67 | 71 | </thead> |
| @@ -68,9 +72,10 @@ | ||
| 68 | 72 | <tbody> |
| 69 | 73 | <?php |
| 70 | 74 | foreach ( $statuses as $status ) { |
| 71 | 75 | ?> |
| 72 | - <tr> | |
| 76 | + <tr data-id="<?php echo esc_attr( $status->id ); ?>"> | |
| 77 | + <td class="sort-handle"><?php WPSC_Icons::get( 'sort' ); ?></td> | |
| 73 | 78 | <td><span class="wpsc-tag" style="color: <?php echo esc_attr( $status->color ); ?>; background-color: <?php echo esc_attr( $status->bg_color ); ?>;" ><?php echo esc_attr( $status->name ); ?></span></td> |
| 74 | 79 | <td> |
| 75 | 80 | <div class="actions"> |
| 76 | 81 | <span class="wpsc-link" onclick="wpsc_get_edit_status(<?php echo esc_attr( $status->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_status' ) ); ?>');" ><?php echo esc_attr__( 'Edit', 'supportcandy' ); ?></span> |
| @@ -90,11 +95,13 @@ | ||
| 90 | 95 | </div> |
| 91 | 96 | <script> |
| 92 | 97 | jQuery('table.wpsc-ticket-statuses').DataTable({ |
| 93 | 98 | ordering: false, |
| 99 | + autoWidth: false, | |
| 94 | 100 | pageLength: 20, |
| 95 | 101 | bLengthChange: false, |
| 96 | - columnDefs: [ | |
| 102 | + columnDefs: [ | |
| 103 | + { targets: 0, width: '30px', searchable: false }, | |
| 97 | 104 | { targets: -1, searchable: false }, |
| 98 | 105 | { targets: '_all', className: 'dt-left' } |
| 99 | 106 | ], |
| 100 | 107 | layout: { |
| @@ -125,8 +132,37 @@ | ||
| 125 | 132 | }, |
| 126 | 133 | }, |
| 127 | 134 | language: supportcandy.translations.datatables |
| 128 | 135 | }); |
| 136 | + | |
| 137 | + jQuery(function() { | |
| 138 | + // Enable sorting with jQuery UI. | |
| 139 | + jQuery('table.wpsc-ticket-statuses tbody').sortable({ | |
| 140 | + handle: '.sort-handle', | |
| 141 | + helper: function(e, tr) { | |
| 142 | + var $originals = tr.children(); | |
| 143 | + var $helper = tr.clone(); | |
| 144 | + $helper.children().each(function(index) { | |
| 145 | + jQuery(this).width($originals.eq(index).width()); | |
| 146 | + }); | |
| 147 | + return $helper; | |
| 148 | + }, | |
| 149 | + update: function(event, ui) { | |
| 150 | + var ids = jQuery(this).sortable('toArray', { attribute: 'data-id' }); | |
| 151 | + jQuery.post( | |
| 152 | + supportcandy.ajax_url, | |
| 153 | + { | |
| 154 | + action: 'wpsc_set_status_load_order', | |
| 155 | + _ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_set_status_load_order' ) ); ?>', | |
| 156 | + ids: ids | |
| 157 | + }, | |
| 158 | + function(response) { | |
| 159 | + | |
| 160 | + } | |
| 161 | + ); | |
| 162 | + } | |
| 163 | + }); | |
| 164 | + }); | |
| 129 | 165 | </script> |
| 130 | 166 | <?php |
| 131 | 167 | wp_die(); |
| 132 | 168 | } |
| @@ -232,13 +268,15 @@ | ||
| 232 | 268 | wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 233 | 269 | } |
| 234 | 270 | |
| 235 | 271 | $color = isset( $_POST['color'] ) ? sanitize_text_field( wp_unslash( $_POST['color'] ) ) : ''; |
| 272 | + $color = ( 'transparent' === $color ) ? $color : sanitize_hex_color( $color ); | |
| 236 | 273 | if ( ! $color ) { |
| 237 | 274 | wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 238 | 275 | } |
| 239 | 276 | |
| 240 | 277 | $bgcolor = isset( $_POST['bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['bg-color'] ) ) : ''; |
| 278 | + $bgcolor = ( 'transparent' === $bgcolor ) ? $bgcolor : sanitize_hex_color( $bgcolor ); | |
| 241 | 279 | if ( ! $bgcolor ) { |
| 242 | 280 | wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 243 | 281 | } |
| 244 | 282 | |
| @@ -411,13 +449,15 @@ | ||
| 411 | 449 | wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 412 | 450 | } |
| 413 | 451 | |
| 414 | 452 | $color = isset( $_POST['color'] ) ? sanitize_text_field( wp_unslash( $_POST['color'] ) ) : ''; |
| 453 | + $color = ( 'transparent' === $color ) ? $color : sanitize_hex_color( $color ); | |
| 415 | 454 | if ( ! $color ) { |
| 416 | 455 | wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 417 | 456 | } |
| 418 | 457 | |
| 419 | 458 | $bgcolor = isset( $_POST['bg-color'] ) ? sanitize_text_field( wp_unslash( $_POST['bg-color'] ) ) : ''; |
| 459 | + $bgcolor = ( 'transparent' === $bgcolor ) ? $bgcolor : sanitize_hex_color( $bgcolor ); | |
| 420 | 460 | if ( ! $bgcolor ) { |
| 421 | 461 | wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 422 | 462 | } |
| 423 | 463 | |
| @@ -618,8 +658,43 @@ | ||
| 618 | 658 | } |
| 619 | 659 | |
| 620 | 660 | $status->destroy( $status ); |
| 621 | 661 | wp_die(); |
| 662 | + } | |
| 663 | + | |
| 664 | + /** | |
| 665 | + * Set load order for ticket statuses | |
| 666 | + * | |
| 667 | + * @return void | |
| 668 | + */ | |
| 669 | + public static function set_status_load_order() { | |
| 670 | + | |
| 671 | + if ( check_ajax_referer( 'wpsc_set_status_load_order', '_ajax_nonce', false ) != 1 ) { | |
| 672 | + wp_send_json_error( 'Unauthorized request!', 400 ); | |
| 673 | + } | |
| 674 | + | |
| 675 | + if ( ! WPSC_Functions::is_site_admin() ) { | |
| 676 | + wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); | |
| 677 | + } | |
| 678 | + | |
| 679 | + $ids = isset( $_POST['ids'] ) ? array_map( 'intval', wp_unslash( $_POST['ids'] ) ) : array(); | |
| 680 | + if ( ! $ids ) { | |
| 681 | + wp_send_json_error( 'Bad Request', 400 ); | |
| 682 | + } | |
| 683 | + | |
| 684 | + $count = 1; | |
| 685 | + foreach ( $ids as $id ) { | |
| 686 | + | |
| 687 | + $status = new WPSC_Status( $id ); | |
| 688 | + if ( ! $status->id ) { | |
| 689 | + continue; | |
| 690 | + } | |
| 691 | + | |
| 692 | + $status->load_order = $count++; | |
| 693 | + $status->save(); | |
| 694 | + } | |
| 695 | + | |
| 696 | + wp_send_json( array( 'success' => true ), 200 ); | |
| 622 | 697 | } |
| 623 | 698 | } |
| 624 | 699 | endif; |
| 625 | 700 | |