Skip to content

Commit

Permalink
fix conditions on new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Oct 1, 2024
1 parent e1f7b1a commit cac5b41
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
43 changes: 25 additions & 18 deletions classes/fields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,41 +937,48 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
// is
$pro_enabled = ppom_pro_is_installed() && 'valid' === apply_filters( 'product_ppom_license_status', '' );

$html_input .= '<div class="col-md-2 col-sm-2">';
$html_input .= '<select data-metatype="operators" class="ppom-conditional-keys form-control">';
$html_input .= '<div class="col-md-3 col-sm-3">';
$html_input .= '<select name="ppom[' . esc_attr( $field_index ) . '][conditions][rules][0][operators]" class="form-control ppom-conditional-keys" data-metatype="operators">';

$html_input .= '<optgroup label="' . __( 'Value Comparison', 'woocommerce-product-addon' ) . '">';
$html_input .= '<option value="is">' . __( 'is', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="not">' . __( 'is not', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="empty">' . __( 'is empty', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="any">' . __( 'has any value', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="empty">' . __( 'is empty', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="is">' . __( 'is', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="not">' . __( 'is not', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '</optgroup>';

$html_input .= '<optgroup label="' . __( 'Text Matching', 'woocommerce-product-addon' ) . '">';
$html_input .= '<option value="' . ( $pro_enabled ? 'contains' : '' ) . '"' . disabled( false, $pro_enabled, false ) . '>' . __( 'contains', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="' . ( $pro_enabled ? 'not-contains' : '' ) . '"' . disabled( false, $pro_enabled, false ) . '>' . __( 'does not contain', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="' . ( $pro_enabled ? 'regex' : '' ) . '"' . disabled( false, $pro_enabled, false ) . '>' . __( 'matches RegEx', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="contains" ' . disabled( false, $pro_enabled, false ) . '>' . __( 'contains', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="not-contains" ' . disabled( false, $pro_enabled, false ) . '>' . __( 'does not contain', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="regex" ' . disabled( false, $pro_enabled, false ) . '>' . __( 'matches RegEx', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '</optgroup>';

$html_input .= '<optgroup label="' . __( 'Numeric Comparison', 'woocommerce-product-addon' ) . '">';
$html_input .= '<option value="greater than">' . __( 'greater than', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="less than">' . __( 'less than', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="' . ( $pro_enabled ? 'even-number' : '' ) . '"' . disabled( false, $pro_enabled, false ) . '>' . __( 'is even', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="' . ( $pro_enabled ? 'odd-number' : '' ) . '"' . disabled( false, $pro_enabled, false ) . '>' . __( 'is odd', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="' . ( $pro_enabled ? 'between' : '' ) . '"' . disabled( false, $pro_enabled, false ) . '>' . __( 'is between', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="' . ( $pro_enabled ? 'number-multiplier' : '' ) . '"' . disabled( false, $pro_enabled, false ) . '>' . __( 'is multiple of', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="greater than">' . __( 'greater than', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="less than">' . __( 'less than', 'woocommerce-product-addon' ) . '</option>';
$html_input .= '<option value="between" ' . disabled( false, $pro_enabled, false ) . '>' . __( 'is between', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="number-multiplier" ' . disabled( false, $pro_enabled, false ) . '>' . __( 'is multiple of', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="even-number" ' . disabled( false, $pro_enabled, false ) . '>' . __( 'is even', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '<option value="odd-number" ' . disabled( false, $pro_enabled, false ) . '>' . __( 'is odd', 'woocommerce-product-addon' ) . ( ! $pro_enabled ? ' (PRO)' : '' ) . '</option>';
$html_input .= '</optgroup>';

$html_input .= '</select> ';

$html_input .= '</div>';

// conditional elements values
$html_input .= '<div class="col-md-4 col-sm-4">';
$html_input .= '<div class="col-md-3 col-sm-3">';
$html_input .= '<input name="ppom[' . esc_attr( $field_index ) . '][conditions][rules][0][element_constant]" class="form-control ppom-conditional-keys ppom-hide-element" data-metatype="element_constant" >';

$html_input .= '<div class="ppom-between-input-container ppom-hide-element"> ';
$html_input .= '<input type="number" name="ppom[' . esc_attr( $field_index ) . '][conditions][rules][0][cond-between-interval][from]" class="form-control ppom-conditional-keys" data-metatype="between-input-from" pattern="^\\d+(\\.\\d{1,4})?$">';
$html_input .= '<span>' . __( 'and', 'woocommerce-product-addon' ) . '</span>';
$html_input .= '<input type="number" name="ppom[' . esc_attr( $field_index ) . '][conditions][rules][0][cond-between-interval][to]" class="form-control ppom-conditional-keys" data-metatype="between-input-to" pattern="^\\d+(\\.\\d{1,4})?$">';
$html_input .= '</div>';

$html_input .= '<select data-metatype="element_values" class="ppom-conditional-keys form-control"></select>';
// Upsell
$html_input .= '<a class="ppom-upsell-condition ppom-hide-element" target="_blank" href="' . esc_url( tsdk_utmify( tsdk_translate_link( PPOM_UPGRADE_URL ), 'input-field-edit', 'condition' ) ) . '"><span class="dashicons dashicons-external"></span> ' . __('Upgrade to Unlock', 'woocommerce-product-addon') . '</a>';


// $html_input .= '<input type="text" class="form-control ppom-conditional-keys" placeholder="Enter Option" data-metatype="element_values">';
$html_input .= '</div>';

// Add and remove btn
Expand Down
7 changes: 7 additions & 0 deletions css/ppom-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1855,3 +1855,10 @@ header.ppom-modal-header {
.ppom-wrapper select.form-control{
line-height: unset;
}
.ppom-wrapper select.form-control{
line-height: unset;
}

.ppom-wrapper a.ppom-upsell-condition:hover{
text-decoration: none;
}
6 changes: 3 additions & 3 deletions js/admin/ppom-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,7 @@ jQuery(function($) {
* @type {HTMLSelectElement|null}
*/
const conditionTargetSelectInput = container.querySelector( '[data-metatype="elements"]' );

if ( !conditionConstantInput || !conditionTargetSelectOptionsInput || !conditionTargetSelectInput ) {
if ( !conditionConstantInput || !conditionTargetSelectInput ) {
return;
}

Expand Down Expand Up @@ -1390,6 +1389,7 @@ jQuery(function($) {
*/
const targetFieldTypeInput = conditionTargetSelectInput.querySelector(`option[value="${conditionTargetSelectInput.value}"]`);
if (
conditionTargetSelectOptionsInput &&
COMPARISON_VALUE_CAN_USE_SELECT.includes( selectedOperator ) &&
targetFieldTypeInput?.dataset?.fieldtype &&
OPERATOR_COMPARISON_VALUE_FIELD_TYPE['select'].includes( targetFieldTypeInput.dataset.fieldtype )
Expand All @@ -1402,7 +1402,7 @@ jQuery(function($) {
if ( shouldHideSelectInput && shouldHideTextInput && shouldHideBetweenInputs && shouldHideUpsell ) {
conditionConstantInput.parentNode?.classList.add('ppom-invisible-element'); // NOTE: Make the entire container visible to preserve the space.
} else {
conditionTargetSelectOptionsInput.classList.toggle("ppom-hide-element", shouldHideSelectInput );
conditionTargetSelectOptionsInput?.classList.toggle("ppom-hide-element", shouldHideSelectInput );
conditionConstantInput.classList.toggle("ppom-hide-element", shouldHideTextInput );
betweenInputs?.classList.toggle("ppom-hide-element", shouldHideBetweenInputs );
container.querySelector('.ppom-upsell-condition')?.classList.toggle("ppom-hide-element", shouldHideUpsell);
Expand Down
1 change: 0 additions & 1 deletion js/ppom-conditions-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ function ppom_check_conditions(data_name, callback) {
}

function ppom_get_input_dom_type(data_name) {
console.log(data_name)
// const field_obj = jQuery(`input[name="ppom[fields][${data_name}]"], input[name="ppom[fields][${data_name}[]]"], select[name="ppom[fields][${data_name}]"]`);
const field_obj = jQuery(`.ppom-input[data-data_name="${data_name}"]`);
return field_obj.closest('.ppom-field-wrapper').data('type');
Expand Down

0 comments on commit cac5b41

Please sign in to comment.