<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * 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 through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="content-header">
    <table cellspacing="0">
        <tr>
            <td style="width:50%;"><h3 class="icon-head head-newsletter-report"><?php echo Mage::helper('newsletter')->__('Newsletter Problem Reports') ?></h3></td>
            <td class="form-buttons">

            </td>
        </tr>
    </table>
</div>
<div>
    <?php echo $this->getChildHtml('grid') ?>
</div>
<?php if($this->getShowButtons()): ?>
<div class="form-buttons">
    <?php echo $this->getUnsubscribeButtonHtml(); ?>
    <?php echo $this->getDeleteButtonHtml(); ?>
</div>
<?php endif ?>
<script type="text/javascript">
<!--
    var problemController = {
        checkCheckboxes: function(controlCheckbox) {
            var elements = $('problemGrid').getElementsByClassName('problemCheckbox');
            elements.each(function(obj){
                obj.checked = controlCheckbox.checked;
            });
        },
        rowClick: function (e) {
            if(!Event.element(e).hasClassName('problemCheckbox')) {
                var elements = Event.findElement(e, 'tr').getElementsByClassName('problemCheckbox');
                if(elements.length != 1) {
                    return;
                }
                elements[0].checked = !elements[0].checked;
            }
        },

        unsubscribe: function () {
            var elements = $$('input.problemCheckbox');
            var serializedElements = Form.serializeElements(elements, true);
            serializedElements._unsubscribe = '1';
            serializedElements.form_key = FORM_KEY;
            var url = problemGridJsObject.url;

            new Ajax.Updater('problemGrid', url + '?ajax=1',
                             {parameters:  serializedElements,
                              evalScripts: true,
                              onComplete:problemGridJsObject.initGrid.bind(problemGridJsObject)});
        },

        deleteSelected: function () {
            var elements = $$('input.problemCheckbox');
            var serializedElements = Form.serializeElements(elements, true);
            serializedElements._delete = '1';
            serializedElements.form_key = FORM_KEY;
            var url = problemGridJsObject.url;

            new Ajax.Updater('problemGrid', url + '?ajax=1',
                             {parameters:  serializedElements,
                              evalScripts: true,
                              onComplete:problemGridJsObject.initGrid.bind(problemGridJsObject)});
        }
    }

    varienGlobalEvents.attachEventHandler('gridRowClick', problemController.rowClick.bind(problemController));
//-->
</script>
