News:

Support the VirtueMart project and become a member

Main Menu

Bulk Actions for Custom Fields: Inheritance Blocking and Mass Deletion

Started by hazael, August 20, 2024, 15:34:08 PM

Previous topic - Next topic

hazael

I've implemented a new feature in the Virtuemart admin template that streamlines custom field management. You can now quickly select or deselect all custom fields to easily block inheritance or overwrite all fields for child or parent products. Additionally, a convenient button allows you to remove all or recently added custom fields.

Group checking or unchecking of checkboxes: [noninheritable], [disabler], [override]

 This enhancement can significantly improve efficiency when working with a large number of custom fields.

In this file:
/administrator/templates/vmadmin/html/com_virtuemart/product/product_edit_custom_customs.php

on line 35 before
<div class="uk-card-body">
paste this code
        <!-- start - additional buttons for custom fields   -->
<script>
function nOn() {
  const checkboxes = document.querySelectorAll('input[id*="noninheritable"]');
  checkboxes.forEach(checkbox => {
    checkbox.checked = true;
  });
}
function nOff() {
  const checkboxes = document.querySelectorAll('input[id*="noninheritable"]');
  checkboxes.forEach(checkbox => {
    checkbox.checked = false;
  });
}
function dOn() {
  const checkboxes = document.querySelectorAll('input[id*="disabler"]');
  checkboxes.forEach(checkbox => {
    checkbox.checked = true;
  });
}
function dOff() {
  const checkboxes = document.querySelectorAll('input[id*="disabler"]');
  checkboxes.forEach(checkbox => {
    checkbox.checked = false;
  });
}
function oOn() {
  const checkboxes = document.querySelectorAll('input[id*="override"]');
  checkboxes.forEach(checkbox => {
    checkbox.checked = true;
  });
}
function oOff() {
  const checkboxes = document.querySelectorAll('input[id*="override"]');
  checkboxes.forEach(checkbox => {
    checkbox.checked = false;
  });
}
function rLast() {
    const container = document.getElementById('vmuikit-js-customcf-container');
    const listy = Array.from(container.querySelectorAll('ul'));
    listy.pop().remove();
}
function rAll() {
const container = document.getElementById('vmuikit-js-customcf-container');
  const listy = container.querySelectorAll('ul');
  for (let i = 0; i < listy.length; i++) {
    listy[i].remove();
  }
}
</script>
    <div class="uk-padding">
    <div class="uk-child-width-expand uk-text-center" uk-grid>

<?php if($this->product->product_parent_id >0){ ?>

    <div>
        <div class="uk-card uk-card-default uk-padding-small uk-border-rounded" uk-tooltip="<?php echo vmText::('COM_VIRTUEMART_CUSTOMFLD_DIS_INH_TIP'); ?>">
            <h3 class="uk-card-title"><?php echo vmText::('DISABLE_ALL'); ?></h3>
            <input type="button" onclick='dOn()' value="<?php echo vmText::('COM_VIRTUEMART_ENABLE_ITEM'); ?>" class="btn btn-small button-apply btn-success"/>
            <input type="button" onclick='dOff()' value="<?php echo vmText::('COM_VIRTUEMART_DISABLE_ITEM'); ?>" class="btn btn-small button-cancel btn-danger"/>
        </div>
    </div>

    <div>
        <div class="uk-card uk-card-default uk-padding-small uk-border-rounded" uk-tooltip="<?php echo vmText::('COM_VIRTUEMART_DIS_DER_CUSTOMFLD_OVERR_DER_TIP'); ?>">
            <h3 class="uk-card-title"><?php echo vmText::('OVERRIDE_ALL'); ?></h3>
            <input type="button" onclick='oOn()' value="<?php echo vmText::('COM_VIRTUEMART_ENABLE_ITEM'); ?>" class="btn btn-small button-apply btn-success"/>
            <input type="button" onclick='oOff()' value="<?php echo vmText::('COM_VIRTUEMART_DISABLE_ITEM'); ?>" class="btn btn-small button-cancel btn-danger"/> 
        </div>
    </div>

<?php } else { ?>

    <div>
        <div class="uk-card uk-card-default uk-padding-small uk-border-rounded" uk-tooltip="<?php echo vmText::('COM_VIRTUEMART_CUSTOMFLD_DIS_DER_TIP'); ?>">
            <h3 class="uk-card-title"><?php echo vmText::('NOT_INHERITED'); ?></h3>
            <input type="button" onclick='nOn()' value="<?php echo vmText::('COM_VIRTUEMART_ENABLE_ITEM'); ?>" class="btn btn-small button-apply btn-success"/>
            <input type="button" onclick='nOff()' value="<?php echo vmText::('COM_VIRTUEMART_DISABLE_ITEM'); ?>" class="btn btn-small button-cancel btn-danger"/>
        </div>
    </div>

<?php ?>
    <div>
        <div class="uk-card uk-card-default uk-padding-small uk-border-rounded" uk-tooltip="Remove all or recently added custom field. The changes will be visible after saving.">
            <h3 class="uk-card-title"><?php echo vmText::('CLEAR_FIELDS'); ?></h3>
            <input type="button" onclick='rLast()' value="Last add" class="btn btn-small button-apply btn-success"/>
            <input type="button" onclick='rAll()' value="<?php echo vmText::('COM_VIRTUEMART_ALL'); ?>" class="btn btn-small button-apply btn-danger"/>         
        </div>
    </div>

    </div>
    </div>
        <!-- end - additional buttons for custom fields   -->