<?php
/**
 * OpenMage
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available at https://opensource.org/license/afl-3-0-php
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
 * @copyright   Copyright (c) 2021-2022 The OpenMage Contributors (https://www.openmage.org)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * @see Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle
 * @var Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle $this
 */
?>
<script type="text/javascript">
if(typeof Bundle=='undefined') {
    Bundle = {};
}
</script>

<div class="entry-edit">
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('bundle')->__('Shipment') ?></h4>
    </div>
    <fieldset>
        <table cellspacing="0" class="form-list">
        <tr>
            <td class="label"><label for="shipment_type"><?php echo Mage::helper('bundle')->__('Ship Bundle Items') ?></label></td>
            <td class="value"><select <?php if ($this->isReadonly()): ?>disabled="disabled" <?php endif ?>id="shipment_type" name="<?php echo $this->getFieldSuffix() ?>[shipment_type]" class="select">
                <option value="1"><?php echo Mage::helper('bundle')->__('Separately') ?></option>
                <option value="0"<?php if ($this->getProduct()->getShipmentType() == 0): ?> selected="selected"<?php endif ?>><?php echo Mage::helper('bundle')->__('Together') ?></option>
            </select>
            </td>
        </tr>
        </table>
    </fieldset>
</div>

<div class="entry-edit custom-options bundle" id="product_bundle_container">
    <div class="entry-edit-head">
        <h4><?php echo $this->__('Bundle Items') ?></h4>
        <div class="right"><?php echo $this->getAddButtonHtml() ?></div>
    </div>

    <div id="product_options_container" class="box">
        <div id="product_bundle_container_top"></div>
        <?php echo $this->getOptionsBoxHtml() ?>
    </div>
</div>

<script type="text/javascript">
// re-bind form elements onchange
varienWindowOnload(true);
<?php if ($this->isReadonly()):?>
$('product_bundle_container').select('input', 'select', 'textarea', 'button').each(function(input){
    input.disabled = true;
    if (input.tagName.toLowerCase() == 'button') {
        input.addClassName('disabled');
    }
});
<?php endif ?>
Validation.add('validate-greater-zero-based-on-option', '<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Please enter a number greater 0 in this field.')) ?>', function(v, el) {
    var optionType = $(el).up('div.grid').previous('table.option-header').select('select.select-product-option-type')[0],
        v = Number(v) || 0;

    if (optionType && (optionType.value == 'checkbox' || optionType.value == 'multi') && v <= 0) {
        return false;
    }
    return true;
});
</script>

<div><input type="hidden" name="affect_bundle_product_selections" value="1" /></div>
