<?php
/*
 * @author     M2E Pro Developers Team
 * @copyright  M2E LTD
 * @license    Commercial use is forbidden
 */

// @codingStandardsIgnoreFile

/** @var $this Ess_M2ePro_Block_Adminhtml_Walmart_Template_Synchronization_Edit_Tabs_Revise */

?>

<div id="block_notice_walmart_template_synchronization_revise" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Revise Rules'); ?>">
    <?php echo Mage::helper('M2ePro')->__(
    'Define the Revise Conditions based on which M2E Pro will automatically revise your Items on Walmart.<br>
    Selected Item properties will be automatically updated when any changes are made to the Policy settings that define these Item properties or Magento Attribute values used for these Item properties in the Policy template.<br><br>

    The detailed information can be found <a href="%url%" target="_blank">here</a>.',

    Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(null, null, 'walmart-integration')
    ); ?>
</div>

<?php
    $formData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data') ? Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->toArray() : array();
    $defaults = Mage::getModel('M2ePro/Walmart_Template_Synchronization_Builder')->getDefaultData();

    $formData = array_merge($defaults, $formData);
    $isEdit = !!$this->getRequest()->getParam('id');
?>

<script type="text/javascript">

    M2ePro.translator.add(<?php echo json_encode(array(
        'Wrong value. Only integer numbers.' => Mage::helper('M2ePro')->__('Wrong value. Only integer numbers.')
    )); ?>);

    Event.observe(window, 'load', function() {

        WalmartTemplateSynchronizationObj = new WalmartTemplateSynchronization();

        $('revise_update_qty')
            .observe('change', WalmartTemplateSynchronizationObj.reviseQty_change)
            .simulate('change');

        $('revise_update_qty_max_applied_value_mode')
            .observe('change', WalmartTemplateSynchronizationObj.reviseQtyMaxAppliedValueMode_change)
            .simulate('change');
    });

</script>

<div class="entry-edit" id="magento_block_walmart_template_synchronization_revise_products">

    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('M2ePro')->__('Revise Conditions'); ?></h4>
    </div>

    <div class="fieldset">
        <div class="hor-scroll">

            <table class="form-list" cellspacing="0" cellpadding="0">

                <tr>
                    <td class="label">
                        <label><?php echo Mage::helper('M2ePro')->__('Quantity'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="revise_update_qty" name="revise_update_qty" disabled="disabled" class="required-entry">
                            <option value="1" selected="selected"><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('
                                Automatically revises Item Quantity and Lag Time on Walmart when any changes are made to the Selling Policy settings that define these<br>
                                Item properties or Magento Attribute values used for these Item properties in the Selling Policy.<br>
                                <strong>Note:</strong> Revise of Item Quantity cannot be disabled.'
                            ); ?></span>
                        </p>
                    </td>
                </tr>

                <!-- max Affected value-->
                <tr id="revise_update_qty_max_applied_value_mode_tr" style="display: none;">
                    <td class="label">
                        <label><?php echo Mage::helper('M2ePro')->__('Conditional Revise'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="revise_update_qty_max_applied_value_mode" name="revise_update_qty_max_applied_value_mode" class="required-entry">
                            <option value="0" <?php if ($formData['revise_update_qty_max_applied_value_mode'] == 0): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('Disabled'); ?></option>
                            <option value="1" <?php if ($formData['revise_update_qty_max_applied_value_mode'] == 1): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('Revise When Less or Equal to'); ?></option>
                        </select>
                        <input id="revise_update_qty_max_applied_value" name="revise_update_qty_max_applied_value" value="<?php echo $this->escapeHtml($formData['revise_update_qty_max_applied_value']); ?>" type="text" class="input-text validate-qty input-text M2ePro-required-when-visible" style="width: 72px" />
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Set the Quantity In Stock limit at which the Revise Action should be triggered. We recommend keeping this value relatively low, between 10 and 20 Items.'); ?></span>
                        </p>
                    </td>
                </tr>

                <tr id="revise_update_qty_max_applied_value_line_tr">
                    <td class="value" colspan="2" style="width: auto;">
                        <hr style="border: 1px solid silver; border-bottom: none;">
                    </td>
                <tr>

                <tr>
                    <td class="label">
                        <label><?php echo Mage::helper('M2ePro')->__('Price'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="revise_update_price" name="revise_update_price" class="required-entry">
                            <option value="0" <?php if ($formData['revise_update_price'] == 0): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                            <option value="1" <?php if ($formData['revise_update_price'] == 1): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('
                                Automatically revises Item Price on Walmart when any changes are made to the Selling Policy settings that define this Item property or Magento Attribute values used for this Item property in the Selling Policy.
                            '); ?></span>
                        </p>
                    </td>
                </tr>

                <tr>
                    <td class="label">
                        <label><?php echo Mage::helper('M2ePro')->__('Promotions'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="revise_update_promotions" name="revise_update_promotions" class="required-entry">
                            <option value="0" <?php if ($formData['revise_update_promotions'] == 0): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                            <option value="1" <?php if ($formData['revise_update_promotions'] == 1): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('
                                Automatically revises Promotions on Walmart when any changes are made to the Selling Policy settings that define Promotion properties or Magento Attribute values used for Promotion properties in the Selling Policy.
                            '); ?></span>
                        </p>
                    </td>
                </tr>

                <tr>
                    <td class="label">
                        <label><?php echo Mage::helper('M2ePro')->__('Details'); ?>: </label>
                    </td>
                    <td class="value" style="width: auto;">
                        <select id="revise_update_details" name="revise_update_details" class="required-entry">
                            <option value="0" <?php if ($formData['revise_update_details'] == 0): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('No'); ?></option>
                            <option value="1" <?php if ($formData['revise_update_details'] == 1): echo ' selected="selected"'; endif; ?>><?php echo Mage::helper('M2ePro')->__('Yes'); ?></option>
                        </select>
                        <p class="note">
                            <span><?php echo Mage::helper('M2ePro')->__('Data will be automatically revised on Walmart Listing(s) if changes are made to the Magento Attributes related to Image, Description, or Selling Settings.'); ?></span>
                        </p>
                    </td>
                </tr>

            </table>

        </div>
    </div>

</div>

<div id="revise_qty_max_applied_value_confirmation_popup_template" style="display: none;">
    <div style="padding: 5px">
        <?php echo Mage::helper('M2ePro')->__(
                '<br/>Disabling this option might affect synchronization performance. Please read <a href="%url%" target="_blank">this article</a> before using the option.',
            Mage::helper('M2ePro/Module_Support')->getSupportUrl('/support/solutions/articles/9000200401')
        ); ?>
    </div>

    <div style="float: right; padding: 10px;">
        <a href="javascript:void(0)" onclick="Windows.getFocusedWindow().close()"><?php echo Mage::helper('M2ePro')->__('Cancel') ?></a>&nbsp;&nbsp;
        <button onclick="WalmartTemplateSynchronizationObj.reviseQtyMaxAppliedValueDisableConfirm()"><?php echo Mage::helper('M2ePro')->__('Confirm') ?></button>
    </div>
</div>
