Merge pull request 'WP PLUGIN ソート対象拡張' (#5) from 機能追加_カスタムフィールドソートチェック関連のjQuery into master

Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/POST_ORDER_BY_ARCHIVE/pulls/5
This commit was merged in pull request #5.
This commit is contained in:
nobu
2021-05-11 20:49:30 +09:00
8 changed files with 109 additions and 96 deletions
+10
View File
@@ -22,6 +22,16 @@ License: GPLv2
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/**
* todo:カスタムフィールド追加処理
* 指定したキーが無ければ、投稿の管理画面表示時にメタボックスを追加する。
* メタキーは下記のオプションテーブルから取得する
* _apop_normal_order_param
* _apop_search_order_param
* _apop_tax_order_param
* ラベルは「APO+カスタムフィールド:XXXX」とする
*/
define( 'APOP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'APOP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'APOP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); define( 'APOP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
+1 -2
View File
@@ -23,8 +23,7 @@ if ( ! class_exists( 'APOP' ) ) {
'level_8', 'level_8',
'apop_post_sort', 'apop_post_sort',
array( $this, 'display_setting_page' ), array( $this, 'display_setting_page' ),
'', ''
50
); );
add_submenu_page( add_submenu_page(
'apop_post_sort', // parent_slug 'apop_post_sort', // parent_slug
+26 -16
View File
@@ -288,52 +288,62 @@ value="' . $sort_num . '">
); );
$list = array(); $list = array();
foreach ( $target_keys as $target_key ) { foreach ( $target_keys as $target_key ) {
$cnv_order_params = self::set_order_list_param( $order_param, $target_key ); $cnv_order_params = self::set_order_list_param( $order_param, $target_key );
$use = $cnv_order_params['use']; $use = $cnv_order_params['use'];
$sort = $cnv_order_params['sort']; $sort = $cnv_order_params['sort'];
$alert = $cnv_order_params['alert']; $alert = $cnv_order_params['alert'];
$no_order_class = $cnv_order_params['no_order_class']; $no_order_class = $cnv_order_params['no_order_class'];
$field_metakey_input = '';
if ( $target_key == 'custom_field' ) { if ( $target_key == 'custom_field' ) {
$meta_key = $cnv_order_params['custom_field']['meta_key']; $meta_key = $cnv_order_params['custom_field']['meta_key'];
$value_type = $cnv_order_params['custom_field']['value_type']; $value_type = $cnv_order_params['custom_field']['value_type'];
$field_metakey_input = self::create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type ); $field_metakey_input = self::create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type );
$target_key_check_class = 'custom_field_check';
} else {
$target_key_check_class = 'sort_' . $target_key . '_check';
} }
$list[] = '<li class="product-list' . $no_order_class . '"> $list[] = '<li class="product-list' . $no_order_class . '">
<div class="product-list-type-label"><b>' . $target_values[ $target_key ] . '</b></div> <div class="product-list-type-label"><b>' . $target_values[ $target_key ] . '</b></div>
<div class="product-list-sort-type"> <div class="product-list-sort-type">
<label> <label>
<input type="hidden" name="_' . $name_key . '[' . $target_key . '][use]" value="0"' . self::set_search_normal_checked( $use, 0 ) . '> <input type="hidden" name="_' . $name_key . '[' . $target_key . '][use]" value="0"' . self::set_search_normal_checked( $use, 0 ) . '>
有効:<input type="checkbox" name="_' . $name_key . '[' . $target_key . '][use]" value="1"' . self::set_search_normal_checked( $use, 1 ) . '> 有効:<input class="' . $target_key_check_class . '" type="checkbox" name="_' . $name_key . '[' . $target_key . '][use]" value="1"' . self::set_search_normal_checked( $use, 1 ) . '>
</label> </label>
<label> <label>
<input class="' . $name_key . '" type="radio" <input class="order_param" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]" name="_' . $name_key . '[' . $target_key . '][sort]"
value="1"' . self::set_search_normal_checked( $sort, 1 ) . '>昇順</label> value="1"' . self::set_search_normal_checked( $sort, 1 ) . '>昇順</label>
<label> <label>
<input class="' . $name_key . '" type="radio" <input class="order_param" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]" name="_' . $name_key . '[' . $target_key . '][sort]"
value="2"' . self::set_search_normal_checked( $sort, 2 ) . '>降順</label> value="2"' . self::set_search_normal_checked( $sort, 2 ) . '>降順</label>
' . $field_metakey_input . '
</div> </div>
</li>'; </li>';
} }
return array( return array(
implode( PHP_EOL, $list ), implode( PHP_EOL, $list ),
$alert, $alert
$field_metakey_input,
); );
} }
private static function create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type ): string { private static function create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type ): string {
return '<div class="sort_custom_field">カスタムフィールドキー: return '<div class="sort_custom_field">
<input type="text" name="_' . $name_key . '[' . $target_key . '][field][meta_key]" value="' . $meta_key . '"> <div class="sort_custom_field_inner"><div class="sort_custom_field_inner_label">カスタムフィールドキー:</div>
値タイプ: <input type="text" class="custom_field_key" name="_' . $name_key . '[' . $target_key . '][field][meta_key]" value="' . $meta_key . '">
</div>
<div class="sort_custom_field_inner">
<div class="sort_custom_field_inner_label">値タイプ:</div>
<label><input type="radio" <label><input type="radio"
class="custom_field_meta_value"
name="_' . $name_key . '[' . $target_key . '][field][value_type]" name="_' . $name_key . '[' . $target_key . '][field][value_type]"
value="meta_value"' . self::set_search_normal_checked( $value_type, 'meta_value' ) . '>テキスト</label> value="meta_value"' . self::set_search_normal_checked( $value_type, 'meta_value' ) . '>テキスト</label>
<label><input type="radio" <label><input type="radio"
class="custom_field_meta_value"
name="_' . $name_key . '[' . $target_key . '][field][value_type]" name="_' . $name_key . '[' . $target_key . '][field][value_type]"
value="meta_value_num"' . self::set_search_normal_checked( $value_type, 'meta_value_num' ) . '>数値</label> value="meta_value_num"' . self::set_search_normal_checked( $value_type, 'meta_value_num' ) . '>数値</label>
</div>
</div>'; </div>';
} }
+17 -1
View File
@@ -119,6 +119,7 @@ dl.apop_setting_list dd:first-of-type {
.search_normal_sort .product-list-sort-type { .search_normal_sort .product-list-sort-type {
width: 100%; width: 100%;
display: flex; display: flex;
flex-wrap: wrap;
} }
.search_normal_sort .product-list-sort-type label { .search_normal_sort .product-list-sort-type label {
@@ -161,8 +162,23 @@ dl.apop_setting_list dd:first-of-type {
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
} }
.sort_custom_field{ .sort_custom_field {
width: 100%; width: 100%;
margin-top: .5em;
padding-top: .5em;
border-top: 1px solid #ccc;
}
.sort_custom_field_inner {
display: flex;
}
.sort_custom_field_inner:first-child {
margin-bottom: .5em;
}
.sort_custom_field_inner_label {
width: 40%;
} }
@media only screen and (max-width: 1264px) { @media only screen and (max-width: 1264px) {
+50 -69
View File
@@ -7,8 +7,6 @@ jQuery(function ($) {
order_list(); order_list();
//order type //order type
// change_search_order();
// change_normal_order();
change_sort_box(); change_sort_box();
//Tax select //Tax select
@@ -18,6 +16,8 @@ jQuery(function ($) {
change_search_per_page(); change_search_per_page();
change_tax_per_page(); change_tax_per_page();
change_custom_field_sort();
change_normal_field_sort();
function change_tab_menu() { function change_tab_menu() {
let submit_type = $('.post-order-box-outer').data('submit_type'); let submit_type = $('.post-order-box-outer').data('submit_type');
@@ -60,80 +60,23 @@ jQuery(function ($) {
} }
} }
function change_normal_order() {
let s_radio = $('.apop_normal_order');
let s_box = $('.normal_sort_box');
let default_index = $('.apop_normal_order_target').data('normal_order_target') - 1;
s_box.hide().find('input').each(function () {
$(this).prop('disabled', true);
});
$('.normal_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false);
s_radio.on('click', function () {
let target_index = $(this).val() - 1;
s_box.hide().find('input').each(function () {
$(this).prop('disabled', true);
});
$('.normal_sort_box:eq(' + target_index + ')').show().find('input').prop('disabled', false);
})
}
function change_search_order() {
let s_radio = $('.apop_search_order');
let s_box = $('.search_sort_box');
let default_index = $('.apop_search_order_target').data('search_order_target') - 1;
s_box.hide().find('input').each(function () {
$(this).prop('disabled', true);
});
$('.search_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false);
s_radio.on('click', function () {
let target_index = $(this).val() - 1;
s_box.hide().find('input').each(function () {
$(this).prop('disabled', true);
});
$('.search_sort_box:eq(' + target_index + ')').show().find('input').prop('disabled', false);
})
}
function change_sort_box() { function change_sort_box() {
let parent_selector = $('.list-orders-inner');
let parent_selector_size = parent_selector.length;
let s_radio = $('.sort_menu'); let s_radio = $('.sort_menu');
let s_box = $('.sort_box'); let sort_menu_size = $('.sort_menu_list').length;
s_box.hide().find('input').each(function () { $('.sort_box').hide();
$(this).prop('disabled', true); for (let i = 0; i < sort_menu_size; i++) {
}); let type_index = $('.sort_menu_list:eq(' + i + ')').data('order_target') - 1;
$('.sort_menu_list:eq(' + i + ')').siblings('.sort_box:eq(' + type_index + ')').show();
for (let i = 0; i < parent_selector_size; i++) {
let my_target = $('.list-orders-inner:eq(' + i + ')');
let default_index = my_target.find('.sort_menu_list').data('order_target') - 1;
if (typeof default_index !== "undefined") {
my_target.find('.sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false);
} else if (isNaN(default_index)) {
my_target.find('.sort_box:eq(0)').show().find('input').prop('disabled', false);
}
} }
s_radio.on('click', function () { s_radio.on('click', function () {
let target_index = $(this).val() - 1; let target_index = $(this).val() - 1;
$(this).parents('.list-orders-inner') $(this).parents('.list-orders-inner').find('.sort_box').hide();
.find('.sort_box').hide() $(this).parents('.list-orders-inner').find('.sort_box:eq(' + target_index + ')').show();
.find('input').each(function () {
$(this).prop('disabled', true);
});
$(this).parents('.list-orders-inner')
.find('.sort_box:eq(' + target_index + ')').show()
.find('input').prop('disabled', false);
}) })
} }
function select_tax() { function select_tax() {
let select_cat_checkbox = $('.select_cat_checkbox'); let select_cat_checkbox = $('.select_cat_checkbox');
let input_chk_size = select_cat_checkbox.length; let input_chk_size = select_cat_checkbox.length;
@@ -182,9 +125,7 @@ jQuery(function ($) {
function change_tax_per_page() { function change_tax_per_page() {
let set_number = $('.set_number'); let set_number = $('.set_number');
let input_chk_size = set_number.length; let input_chk_size = set_number.length;
for (let i = 0; i < input_chk_size; i++) {
let i = 0;
for (i; i < input_chk_size; i++) {
let input_num_box = $('.set_number:eq(' + i + ')').siblings('.per_page_cat_input'); let input_num_box = $('.set_number:eq(' + i + ')').siblings('.per_page_cat_input');
if (input_num_box.val() == '') { if (input_num_box.val() == '') {
input_num_box.prop('disabled', true); input_num_box.prop('disabled', true);
@@ -202,4 +143,44 @@ jQuery(function ($) {
}); });
} }
function change_custom_field_sort() {
let s_box = $('.sort_box');
let custom_field_check = $('.custom_field_check');
s_box.find(custom_field_check).each(function () {
if ($(this).prop('checked') == false) {
$(this).parents('.product-list-sort-type').find('.custom_field_key').prop('disabled', true);
$(this).parents('.product-list-sort-type').find('.custom_field_meta_value').prop('disabled', true);
}
});
custom_field_check.on('click', function () {
if ($(this).prop('checked') == true) {
$(this).parents('.product-list-sort-type').find('.custom_field_key').prop('disabled', false);
$(this).parents('.product-list-sort-type').find('.custom_field_meta_value').prop('disabled', false);
} else {
$(this).parents('.product-list-sort-type').find('.custom_field_key').val('').prop('disabled', true);
$(this).parents('.product-list-sort-type').find('.custom_field_meta_value').prop('disabled', true);
}
})
}
function change_normal_field_sort() {
let s_box = $('.sort_box');
let targets = '.custom_field_check, .sort_date_check, .sort_title_check, .sort_ID_check, .sort_modified_check';
s_box.find(targets).each(function () {
if ($(this).prop('checked') == false) {
$(this).parents('.product-list-sort-type').find('.order_param').prop('disabled', true);
}
});
$(targets).on('click', function () {
if ($(this).prop('checked') == true) {
$(this).parents('.product-list-sort-type').find('.order_param').prop('disabled', false)
} else {
$(this).parents('.product-list-sort-type').find('.order_param').prop('disabled', true);
}
});
}
}); });
+2 -4
View File
@@ -26,12 +26,11 @@ $submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' );
<?php include APOP_PLUGIN_PATH . 'template/order_parts_menu.php'; ?> <?php include APOP_PLUGIN_PATH . 'template/order_parts_menu.php'; ?>
<hr> <hr>
<div class="sort_box"> <div class="sort_box">
<?php list( $list, $alert, $field_metakey_input ) = APOP_UI::create_search_normal_list( 'normal' ); ?> <?php list( $list, $alert ) = APOP_UI::create_search_normal_list( 'normal' ); ?>
<?php echo $alert; ?> <?php echo $alert; ?>
<ul class="post-order-list search_normal_sort"> <ul class="post-order-list search_normal_sort">
<?php echo $list; ?> <?php echo $list; ?>
</ul> </ul>
<?php echo $field_metakey_input; ?>
</div> </div>
<div class="sort_box"> <div class="sort_box">
<?php echo APOP_UI::none_registered_alert_msg(); ?> <?php echo APOP_UI::none_registered_alert_msg(); ?>
@@ -59,12 +58,11 @@ $submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' );
<?php include APOP_PLUGIN_PATH . 'template/order_parts_menu.php'; ?> <?php include APOP_PLUGIN_PATH . 'template/order_parts_menu.php'; ?>
<hr> <hr>
<div class="sort_box"> <div class="sort_box">
<?php list( $list, $alert, $field_metakey_input ) = APOP_UI::create_search_normal_list( 'search' ); ?> <?php list( $list, $alert ) = APOP_UI::create_search_normal_list( 'search' ); ?>
<?php echo $alert; ?> <?php echo $alert; ?>
<ul class="post-order-list search_normal_sort"> <ul class="post-order-list search_normal_sort">
<?php echo $list; ?> <?php echo $list; ?>
</ul> </ul>
<?php echo $field_metakey_input; ?>
</div> </div>
<div class="sort_box"> <div class="sort_box">
<?php echo APOP_UI::none_registered_alert_msg(); ?> <?php echo APOP_UI::none_registered_alert_msg(); ?>
+1 -2
View File
@@ -38,12 +38,11 @@
</ul> </ul>
</div> </div>
<div class="sort_box"> <div class="sort_box">
<?php list( $list, $alert, $field_metakey_input ) = APOP_UI::create_search_normal_list( 'tax', $tax_data->term_id ); ?> <?php list( $list, $alert) = APOP_UI::create_search_normal_list( 'tax', $tax_data->term_id ); ?>
<?php echo $alert; ?> <?php echo $alert; ?>
<ul class="post-order-list search_normal_sort"> <ul class="post-order-list search_normal_sort">
<?php echo $list; ?> <?php echo $list; ?>
</ul> </ul>
<?php echo $field_metakey_input; ?>
</div> </div>
<input type="hidden" name="submit_type" value="<?php echo $submit_type_number; ?>"> <input type="hidden" name="submit_type" value="<?php echo $submit_type_number; ?>">
<p class="submit post-order"><input type="submit" name="Submit" <p class="submit post-order"><input type="submit" name="Submit"
+1 -1
View File
@@ -13,7 +13,7 @@ $param_settings = array(
'_apop_tax_sort_type', '_apop_tax_sort_type',
'_apop_normal_order_param', '_apop_normal_order_param',
'_apop_search_order_param', '_apop_search_order_param',
'apop_tax_order_param', '_apop_tax_order_param',
); );
foreach ( $param_settings as $param_setting ) { foreach ( $param_settings as $param_setting ) {
delete_option( $param_setting ); delete_option( $param_setting );