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

// @codingStandardsIgnoreFile

/** @var $this Ess_M2ePro_Block_Adminhtml_Amazon_Template_Synchronization_Edit_Tabs_Revise */

?>

<div id="block_notice_amazon_template_synchronization_revise" class="block_notices_module" title="<?php echo Mage::helper('M2ePro')->__('Revise Rules'); ?>">
    <?php echo Mage::helper('M2ePro')->__(
    'Specify which Channel data should be automatically revised by M2E Pro.<br/><br/>

    Selected Item Properties will be automatically updated by the Module once any related changes are detected in Magento Attributes or Policy Templates.<br/><br/>

    More detailed information on how to work with this Page you can find <a href="%url%" target="_blank">here</a>.',
    Mage::helper('M2ePro/Module_Support')->getDocumentationUrl(null, null, 'revise-rules')
    ); ?>
</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/Amazon_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() {

        AmazonTemplateSynchronizationObj = new AmazonTemplateSynchronization();

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

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

</script>

<div class="entry-edit" id="magento_block_amazon_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, Production Time, Restock Date on Amazon when the related values are modified in Magento, Policy Template or Listing Settings accordingly.<br/>
                                The Quantity management is the basic functionality the Magento-to-Amazon integration is based on and it 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 Amazon when Product Price, Special Price or Magento Attribute used for Item Price are modified in Magento or Policy Template.
                            '); ?></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')->__('
                                Automatically revises Condition Note, Gift Message, Gift Wrap settings, data from Product Type, Shipping Template Policy and Product Tax Code Policy
                                in Amazon Listing when there are changes made to Magento Attribute of at least one mentioned parameter.
                            '); ?></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="AmazonTemplateSynchronizationObj.reviseQtyMaxAppliedValueDisableConfirm()"><?php echo Mage::helper('M2ePro')->__('Confirm') ?></button>
    </div>
</div>
