Refactor admin cl interface and handle product access with groups

This commit is contained in:
Almira Krdzic
2018-10-16 16:57:48 +02:00
parent 554dc37a2d
commit ddf7d4452c
12 changed files with 320 additions and 262 deletions

View File

@@ -78,72 +78,7 @@ if ( ! defined( 'ABSPATH' ) ) {
</style>
<script>
jQuery(document).ready(function ($) {
$( "#tabs" ).tabs({
disabled: <?php echo $has_default_cl_extras ? '[ ]' : '[ 1 ]' ; ?>
});
$('#wiaas_add_cl_customer_extras').click(function(e) {
e.preventDefault();
var customer_id = $('#wiaas_cl_customers').val();
if (!customer_id || customer_id === '0') {
return;
}
$.post(window.ajaxurl, {
action: 'wiaas_create_cl_customer_extras',
_ajax_nonce: '<?php echo wp_create_nonce('wiaas_create_cl_customer_extras') ?>',
customer_id: customer_id,
package_id: <?php echo esc_attr($package->get_id()) ?>
}).done( function (result) {
$('#tabs-2').append(result);
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', true );
});
$('#wiaas_cl_customers').val('0');
});
$('#wiaas_package_extras').delegate('.wiaas_remove_cl_extras', 'click', function(e) {
e.preventDefault();
var customer_id = $( this ).data('customer_id');
$('#extras_customer_' + customer_id).remove();
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', false );
$('#wiaas_cl_customers').val('0');
});
$('#wiaas_package_extras').delegate('.wiaas-cl-extra-input', 'change', function(e) {
e.preventDefault();
var val = parseFloat($( this ).val());
var target = '#' + $( this).data('target');
if (isNaN(val)) {
$(target).val('Invalid!');
return;
}
var type = $( this).data('type');
if (type === 'fixed') {
$(target).text( $(target).data('base') + val);
}
if (type === 'recurrent' || type === 'services') {
$(target).data(type, val);
$(target).text( $(target).data('base') + $(target).data('recurrent') + $(target).data('services'));
}
});
});
</script>
<div class="wrap">
@@ -233,15 +168,15 @@ if ( ! defined( 'ABSPATH' ) ) {
</div>
</div>
<div id="tabs">
<div id="tabs" data-disabled="<?php echo $has_default_cl_extras ? '' : '1' ; ?>">
<ul id="tabs-navigation">
<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
</ul>
<form id="wiaas_package_extras" action="" method="post">
<input type="hidden" name="page" value="wiaas-cl-product"/>
<input type="hidden" name="id" value="<?php echo esc_attr($package->get_id()) ?>"/>
<input type="hidden" name="page" value="wiaas-cl-package"/>
<input type="hidden" id="wiaas_cl_package_id" name="cl_package_id" value="<?php echo esc_attr($package->get_id()) ?>"/>
<div id="tabs-1">
@@ -273,6 +208,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
</select>
<?php wp_nonce_field( 'wiaas_create_cl_customer_extras', 'wiaas_create_cl_customer_extras_nonce' ); ?>
<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
</div>