News:

Support the VirtueMart project and become a member

Main Menu

How to check or uncheck all checkboxes of a customfields?

Started by hazael, February 10, 2022, 18:40:57 PM

Previous topic - Next topic

hazael

Is there any way (maybe javascript) to select or deselect group of boxes (disable / override) for custom fields with one button?
Marking each box individually is very tiresome when you have 50 entries for each child product

hazael

#1
In the file:
administrator/components/com_virtuemart/views/product/tmpl/product_edit_custom.php

This code:
$text .= '<span style="white-space: nowrap;" class="hasTooltip" title="'.htmlentities(vmText::_('COM_VIRTUEMART_DIS_DER_CUSTOMFLD_OVERR_DER_TIP')).'">o:'.VmHtml::checkbox('field['.$i.'][override]',$customfield->override,$checkValue).'</span>';
Change to:
$text .= '<span style="white-space: nowrap;" class="hasTooltip" title="'.htmlentities(vmText::_('COM_VIRTUEMART_DIS_DER_CUSTOMFLD_OVERR_DER_TIP')).'">o:'.VmHtml::checkbox('field['.$i.'][override]" class="override',$customfield->override,$checkValue).'</span>';
This code:
$text = '<span style="white-space: nowrap;" class="hasTooltip" title="'.htmlentities(vmText::_($tip)).'">d:'.VmHtml::checkbox('field[' . $i . '][disabler]',$customfield->disabler,$checkValue).'</span>';
Change to:
$text = '<span style="white-space: nowrap;" class="hasTooltip" title="'.htmlentities(vmText::_($tip)).'">d:'.VmHtml::checkbox('field[' . $i . '][disabler]" class="disabler',$customfield->disabler,$checkValue).'</span>';

After:
<legend><?php echo vmText::_('COM_VIRTUEMART_CUSTOM_FIELD_TYPE' );?></legend>

Paste:
 
<?php if($this->product->product_parent_id >0){ ?>
        <script type="text/javascript">
            function selectso(){ 
var ele = document.getElementsByClassName("override");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=true; 
                } 
            } 
            function deSelecto(){ 
var ele = document.getElementsByClassName("override");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=false; 
                     
                } 
            }   
            function selectsd(){ 
var ele = document.getElementsByClassName("disabler");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=true; 
                } 
            } 
            function deSelectd(){ 
var ele = document.getElementsByClassName("disabler");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=false; 
                     
                } 
            }   
function remove() {
  var ele = document.getElementById("custom_fields");
  ele.remove();
}

        </script>
<div style="text-align: center;margin-bottom:30px;background:#eee;padding:20px">
<div style="width:30%;float:left;max-width:200px">
<div>Disable all fields</div>
<input type="button" onclick='selectsd()' value="Select" class="btn btn-small button-apply btn-success"/>
<input type="button" onclick='deSelectd()' value="Deselect" class="btn btn-small button-apply"/>
</div>
<div style="width:30%;float:left;max-width:200px">
<div>Override all fields</div>
        <input type="button" onclick='selectso()' value="Select" class="btn btn-small button-apply btn-success"/> 
        <input type="button" onclick='deSelecto()' value="Deselect" class="btn btn-small button-apply"/> 
</div>
<div style="width:30%;float:left;max-width:200px">
<div>Remove all fields</div>
        <input type="button" onclick='remove()' value="Clear" class="btn btn-small button-apply btn-danger"/> 
</div>
<div style="clear:both"></div>
</div>
<?php }?>



And it works great :)



hazael

My mod for the new VM template (Shows only in child products)

templates/vmadmin/html/com_virtuemart/product/product_edit_custom_customs.php
<?php
/**
 *
 * Handle the Product Custom Fields
 *
 * @package    VirtueMart
 * @subpackage Product
 * @author RolandD, Patrick khol
 * @link https://virtuemart.net
 * @copyright Copyright (c) 2004 - Copyright (C) 2004 - 2022 Virtuemart Team. All rights reserved. VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: product_edit_custom_customs.php 10649 2022-05-05 14:29:44Z Milbo $
 *
 */


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
$customcfs $this->customcfs;


?>

<div class="uk-card uk-card-small uk-card-vm">
<div class="uk-card-header">
<div class="uk-card-title">
<span class="md-color-cyan-600 uk-margin-small-right"
uk-icon="icon: customfield; ratio: 1.2"></span>
<?php echo vmText::_('COM_VIRTUEMART_CUSTOM_FIELD_TYPE' ); ?>
</div>
</div>
<div class="uk-card uk-padding">
<div class="uk-card-title">
<?php if($this->product->product_parent_id >0){ ?>
        <script type="text/javascript">
            function selectso(){ 
var ele = document.getElementsByClassName("override");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=true; 
                } 
            } 
            function deSelecto(){ 
var ele = document.getElementsByClassName("override");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=false; 
                     
                } 
            }   
            function selectsd(){ 
var ele = document.getElementsByClassName("disabler");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=true; 
                } 
            } 
            function deSelectd(){ 
var ele = document.getElementsByClassName("disabler");
                for(var i=0; i<ele.length; i++){ 
                    if(ele[i].type=='checkbox') 
                        ele[i].checked=false; 
                     
                } 
            }   
function remove() {
  var ele = document.getElementById("vmuikit-js-customcf-container");
  ele.remove();
}

        </script>
<div class="uk-grid-small uk-child-width-expand"  uk-grid>
<div>
<div><?php echo vmText::('COM_VIRTUEMART_DISABLE_ALL_FIELDS'); ?></div>
<input type="button" onclick='selectsd()' value="Select" class="btn btn-small button-apply btn-success"/>
<input type="button" onclick='deSelectd()' value="Deselect" class="btn btn-small button-cancel btn-danger"/>
</div>
<div>
<div><?php echo vmText::('COM_VIRTUEMART_OVERRIDE_ALL_FIELDS'); ?></div>
        <input type="button" onclick='selectso()' value="Select" class="btn btn-small button-apply btn-success"/> 
        <input type="button" onclick='deSelecto()' value="Deselect" class="btn btn-small button-cancel btn-danger"/> 
</div>
<div>
<div><?php echo vmText::('COM_VIRTUEMART_CLEAR_ALL_FIELDS'); ?></div>
        <input type="button" onclick='remove()' value="Clear" class="btn btn-small button-apply btn-danger"/> 
</div>
</div>
<?php }?>
</div>
</div>
<div class="uk-card-body">

<!-- BOF CUSTOMFIELDS   -->
<div   uk-grid>
<div class="uk-width-1-1">

<div class="filter-bar search-customfields-boundary">
<div class="uk-navbar-container uk-margin uk-navbar" uk-navbar="">
<div class="uk-navbar-left">
<div class="uk-navbar-item">
<div class="uk-button-group vmuikit-filter-search ">

<?php echo $this->customsList?>

</div>
</div>
</div>
</div>
</div>

</div>


<!-- DISPLAY CUSTOMFIELDS-->
<div id="vmuikit-js-customcf-container"
class="vmuikit-js-customcf-container uk-width-1-1 uk-grid uk-grid-small uk-child-width-1-1"
uk-grid>
</div>
<!-- EOF DISPLAY CUSTOMFIELDS -->


</div>

<!-- EOF CUSTOMFIELDS  -->
</div>


</div>
<?php
$adminTemplate 
VMPATH_ROOT '/administrator/templates/vmadmin/html/com_virtuemart/';
$adminTemplatePath '/administrator/templates/vmadmin/html/com_virtuemart/';

$js "
var template = jQuery('#vmuikit-js-customcf-template').html()
var rendered = Mustache.render(template,
{
'customcfs': " 
json_encode($customcfs) . " ,
}
)
jQuery('#vmuikit-js-customcf-container').html(rendered)
"
;

vmJsApi::addJScript('customcf.mustache'$js);


/administrator/templates/vmadmin/html/com_virtuemart/product/product_edit_custom.php
<?php
/**
 *
 * Handle the Product Custom Fields
 *
 * @package    VirtueMart
 * @subpackage Product
 * @author RolandD, Patrick khol
 * @link https://virtuemart.net
 * @copyright Copyright (c) 2004 - Copyright (C) 2004 - 2022 Virtuemart Team. All rights reserved. VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: product_edit_custom.php 10649 2022-05-05 14:29:44Z Milbo $
 */


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

?>



<?php
$relatedcategories
=array();
$relatedproducts=array();
$customcfs=array();
$i 0;
$tables = array('categories' => '''products' => '''fields' => '''customPlugins' => '',);
if (isset(
$this->product->customfields)) {
$customfieldsModel VmModel::getModel('customfields');


$i 0;

foreach ($this->product->customfields as $k => $customfield) {

$checkValue $customfield->virtuemart_customfield_id;
$title '';
$text '';
$customfield->display $customfieldsModel->displayProductCustomfieldBE($customfield$this->product$i);

$checkValue $customfield->virtuemart_customfield_id;
if ($customfield->override != or $customfield->disabler != 0) {

if (!empty($customfield->disabler)) {
$checkValue $customfield->disabler;
}
if (!empty($customfield->override)) {
$checkValue $customfield->override;
}
$title vmText::sprintf('COM_VIRTUEMART_CUSTOM_OVERRIDE'$checkValue) . '</br>';
if ($customfield->disabler != 0) {
$title vmText::sprintf('COM_VIRTUEMART_CUSTOM_DISABLED'$checkValue) . '</br>';
}

if ($customfield->override != 0) {
$title vmText::sprintf('COM_VIRTUEMART_CUSTOM_OVERRIDE'$checkValue) . '</br>';
}

} else {
if ($customfield->virtuemart_product_id == $this->product->product_parent_id) {
$title vmText::_('COM_VIRTUEMART_CUSTOM_INHERITED') . '</br>';
}
}
$disableDerivedCheckbox='';
$nonInheritableCheckbox='';
if (!empty($title)) {
$tip 'COM_VIRTUEMART_CUSTOMFLD_DIS_DER_TIP';
$text '<span style="white-space: nowrap;" uk-tooltip="' htmlentities(vmText::_($tip)) . '">d:' VmHtml::checkbox('field[' $i '][disabler]'$customfield->disabler$checkValue) . '</span>';
$disableDerived '<span style="white-space: nowrap;" uk-tooltip="' htmlentities(vmText::_($tip)) . '">d:' VmHtml::checkbox('field[' $i '][disabler]'$customfield->disabler$checkValue) . '</span>';
$disableDerivedCheckbox =VmHtml::checkbox('field[' $i '][disabler]" class="disabler'$customfield->disabler$checkValue);
} else {
$tip 'COM_VIRTUEMART_CUSTOMFLD_DIS_INH_TIP';
$text '<span style="white-space: nowrap;" uk-tooltip="' htmlentities(vmText::_($tip)) . '">disinh:' VmHtml::checkbox('field[' $i '][noninheritable]'$customfield->noninheritable$checkValue) . '</span>';
$nonInheritableCheckbox=VmHtml::checkbox('field[' $i '][noninheritable]" class="noninheritable'$customfield->noninheritable$checkValue);
}


if ($customfield->is_cart_attribute) {
$cartIcone 'default';
} else {
$cartIcone 'default-off';
}
if ($customfield->field_type == 'Z') {
// R: related categories
$relatedcategory= new stdClass();
$relatedcategory->displayHTML=$customfield->display;
$relatedcategory->hiddenHTML=VirtueMartModelCustomfields::setEditCustomHidden($customfield$i);
$relatedcategory->title=$title;
$relatedcategory->disableDerivedCheckbox=$disableDerivedCheckbox;
$relatedcategory->nonInheritableCheckbox=$nonInheritableCheckbox;
$relatedcategories[] =$relatedcategory;

} elseif ($customfield->field_type == 'R') {
// R: related products
$relatedproduct= new stdClass();
$relatedproduct->displayHTML=$customfield->display;
$relatedproduct->hiddenHTML=VirtueMartModelCustomfields::setEditCustomHidden($customfield$i);
$relatedproduct->title=$title;
$relatedproduct->disableDerivedCheckbox=$disableDerivedCheckbox;
$relatedproduct->nonInheritableCheckbox=$nonInheritableCheckbox;
$relatedproducts[] =$relatedproduct;
} else {
$customcf= new stdClass();
if (isset($this->fieldTypes[$customfield->field_type])) {
$type $this->fieldTypes[$customfield->field_type];
} else {
$type 'deprecated';
}
$customcf->type=$type;
$colspan '';

if ($customfield->field_type == 'C' or $customfield->field_type == 'RC') {
$colspan 'colspan="2" ';
}
$customcf->overrideCheckbox='';
if (!empty($title)) {
$text .= '<span style="white-space: nowrap;" uk-tooltip="' htmlentities(vmText::_('COM_VIRTUEMART_DIS_DER_CUSTOMFLD_OVERR_DER_TIP')) . '">o:' VmHtml::checkbox('field[' $i '][override]'$customfield->override$checkValue) . '</span>';
$overrideCheckbox =  VmHtml::checkbox('field[' $i '][override]" class="override'$customfield->override$checkValue) ;
$customcf->overrideCheckbox=$overrideCheckbox;

}

$customcf->disableCheckbox='';
if (!empty($title)) {
$text .= '<span style="white-space: nowrap;" uk-tooltip="' htmlentities(vmText::_('COM_VIRTUEMART_CUSTOMFLD_DIS_DER_TIP')) . '">o:' VmHtml::checkbox('field[' $i '][disabler]'$customfield->disabler$checkValue) . '</span>';
$disableCheckbox =  VmHtml::checkbox('field[' $i '][disabler]" class="disabler' $customfield->disabler$checkValue) ;
$customcf->disableCheckbox=$disableCheckbox;

}

$tables['fields'] .= '<tr class="removable">
<td >
<b>' 
vmText::_($type) . '</b> ' vmText::_($customfield->custom_title) . '</span><br/>
$title ' ' $text '
<span class="vmicon vmicon-16-' 
$cartIcone '"></span>';
$customcf->type=vmText::_($type) ;
$customcf->title=vmText::_($customfield->custom_title) ;
$customcf->is_cart_attribute=(int)$customfield->is_cart_attribute;
$customcf->canMove=false;
$customcf->canRemove=false;
$customcf->searchable=(int)$customfield->searchable;
$customcf->layout_pos=$customfield->layout_pos;
if (($customfield->virtuemart_product_id == $this->product->virtuemart_product_id or $customfield->override != 0) and $customfield->disabler == 0) {
$tables['fields'] .= '<span class="vmicon vmicon-16-move"></span>
<span class="vmicon vmicon-16-remove 4remove"></span>'
;
$customcf->canMove=true;
$customcf->canRemove=true;
}
$tables['fields'] .= VirtueMartModelCustomfields::setEditCustomHidden($customfield$i)
'</td>
<td ' 
$colspan '>' $customfield->display '</td>
 </tr>'
;
$customcf->hiddenHTML=VirtueMartModelCustomfields::setEditCustomHidden($customfield$i);
$customcf->displayHTML=$customfield->display;
$customcfs[]=$customcf;
}

$i++;
}
}

$emptyTable '
<tr>
<td colspan="8">' 
vmText::_('COM_VIRTUEMART_CUSTOM_NO_TYPES') . '</td>
<tr>'
;


$this->relatedcategories=$relatedcategories;
$this->tables=$tables;
?>

<div class="uk-grid-small uk-child-width-1-1" uk-grid>
<div>
<?php
$this->relatedType="categories";
$this->virtuemart_custom_id '1';
$this->relatedDatas=$relatedcategories;
$this->relatedIcon='category';
echo $this->loadTemplate('custom_relatedcf');
$this->relatedType="";
$this->relatedDatas=array();
?>

</div>
<div>
<?php
$this->relatedType="products";
$this->virtuemart_custom_id '2';
$this->relatedDatas=$relatedproducts;
$this->relatedIcon='product';
echo $this->loadTemplate('custom_relatedcf') ;
$this->relatedType="";
$this->relatedDatas=array();
?>

</div>

<div>
<?php
$this->customcfs=$customcfs;
echo $this->loadTemplate('custom_customs')
?>

</div>
</div>