<?php
/**
 * Copyright © 2016 maijindou.com All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Template for \Magento\Backend\Block\Widget\Grid
 *
 *  getId()
 *  getCollection()
 *  getColumns()
 *  getPagerVisibility()
 *  getVarNamePage()
 *
 */
/* @var $block \Magento\Backend\Block\Widget\Grid */
$numColumns = sizeof($block->getColumns());
?>
<?php if ($block->getCollection()): ?>

<?php if ($block->canDisplayContainer()): ?>
<div id="<?php echo $block->escapeHtml($block->getId()) ?>" data-grid-id="<?php echo $block->escapeHtml($block->getId()) ?>">
<?php else: ?>
<?php echo $block->getLayout()->getMessagesBlock()->getGroupedHtml() ?>
<?php endif; ?>

        <div class="admin__data-grid-header admin__data-grid-toolbar">
            <?php $massActionAvailable = $block->getChildBlock('grid.massaction') && $block->getChildBlock('grid.massaction')->isAvailable() ?>
            <?php if ($block->getPagerVisibility() || $block->getExportTypes() || $block->getChildBlock('grid.columnSet')->getFilterVisibility() || $massActionAvailable): ?>
            <div class="admin__data-grid-header-row">
                <?php if ($massActionAvailable): ?>
                    <?php echo $block->getMainButtonsHtml() ? '<div class="admin__filter-actions">' . $block->getMainButtonsHtml() . '</div>' : ''; ?>
                <?php endif; ?>

                <?php if ($block->getChildBlock('grid.export')): ?>
                    <?php echo $block->getChildHtml('grid.export'); ?>
                <?php endif; ?>
            </div>
            <?php endif; ?>
            <div class="<?php if($massActionAvailable) { echo '_massaction ';} ?>admin__data-grid-header-row">
                <?php if ($massActionAvailable): ?>
                    <?php echo $block->getChildHtml('grid.massaction') ?>
                <?php else: ?>
                    <?php echo $block->getMainButtonsHtml() ? '<div class="admin__filter-actions">' . $block->getMainButtonsHtml() . '</div>' : ''; ?>
                <?php endif; ?>
                    <?php $countRecords = $block->getCollection()->getSize(); ?>
                    <div class="admin__control-support-text">
                        <span id="<?php echo $block->escapeHtml($block->getHtmlId()) ?>-total-count" <?php /* @escapeNotVerified */ echo $block->getUiId('total-count') ?>>
                            <?php /* @escapeNotVerified */ echo $countRecords ?>
                        </span>
                        <?php /* @escapeNotVerified */ echo __('records found') ?>
                        <span id="<?php echo $block->escapeHtml($block->getHtmlId()) ?>_massaction-count"
                              class="mass-select-info _empty"><strong data-role="counter">0</strong> <span><?php /* @escapeNotVerified */ echo __('selected') ?></span></span>
                    </div>
                <?php if ($block->getPagerVisibility()): ?>
                    <div class="admin__data-grid-pager-wrap">
                        <select name="<?php /* @escapeNotVerified */ echo $block->getVarNameLimit() ?>"
                                id="<?php echo $block->escapeHtml($block->getHtmlId())?>_page-limit"
                                onchange="<?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.loadByElement(this)" <?php /* @escapeNotVerified */ echo $block->getUiId('per-page') ?>
                                class="admin__control-select">
                            <option value="20"<?php if ($block->getCollection()->getPageSize() == 20): ?>
                                selected="selected"<?php endif; ?>>20
                            </option>
                            <option value="30"<?php if ($block->getCollection()->getPageSize() == 30): ?>
                                selected="selected"<?php endif; ?>>30
                            </option>
                            <option value="50"<?php if ($block->getCollection()->getPageSize() == 50): ?>
                                selected="selected"<?php endif; ?>>50
                            </option>
                            <option value="100"<?php if ($block->getCollection()->getPageSize() == 100): ?>
                                selected="selected"<?php endif; ?>>100
                            </option>
                            <option value="200"<?php if ($block->getCollection()->getPageSize() == 200): ?>
                                selected="selected"<?php endif; ?>>200
                            </option>
                        </select>
                        <label for="<?php echo $block->escapeHtml($block->getHtmlId())?>_page-limit"
                            class="admin__control-support-text"><?php /* @escapeNotVerified */ echo __('per page') ?></label>
                        <div class="admin__data-grid-pager">
                            <?php $_curPage = $block->getCollection()->getCurPage() ?>
                            <?php $_lastPage = $block->getCollection()->getLastPageNumber() ?>

                            <?php if ($_curPage > 1): ?>
                                <button class="action-previous"
                                        type="button"
                                        onclick="<?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.setPage('<?php /* @escapeNotVerified */ echo($_curPage - 1) ?>');return false;">
                                            <span><?php /* @escapeNotVerified */ echo __('Previous page') ?></span>
                                </button>
                            <?php else: ?>
                                <button type="button" class="action-previous disabled"><span><?php /* @escapeNotVerified */ echo __('Previous page') ?></span></button>
                            <?php endif; ?>

                            <input type="text"
                                   id="<?php echo $block->escapeHtml($block->getHtmlId())?>_page-current"
                                   name="<?php /* @escapeNotVerified */ echo $block->getVarNamePage() ?>"
                                   value="<?php /* @escapeNotVerified */ echo $_curPage ?>"
                                   class="admin__control-text"
                                   onkeypress="<?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.inputPage(event, '<?php /* @escapeNotVerified */ echo $_lastPage ?>')" <?php /* @escapeNotVerified */ echo $block->getUiId('current-page') ?> />

                            <label class="admin__control-support-text" for="<?php echo $block->escapeHtml($block->getHtmlId())
                            ?>_page-current">
                                <?php /* @escapeNotVerified */ echo __('of %1', '<span>' . $block->getCollection()->getLastPageNumber() . '</span>') ?>
                            </label>
                            <?php if ($_curPage < $_lastPage): ?>
                                <button title="<?php /* @escapeNotVerified */ echo __('Next page') ?>"
                                        class="action-next"
                                        onclick="<?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.setPage('<?php /* @escapeNotVerified */ echo($_curPage + 1) ?>');return false;">
                                    <span><?php /* @escapeNotVerified */ echo __('Next page') ?></span>
                                </button>
                            <?php else: ?>
                                <button type="button" class="action-next disabled"><span><?php /* @escapeNotVerified */ echo __('Next page') ?></span></button>
                            <?php endif; ?>
                        </div>
                    </div>
                <?php endif ?>
            </div>
        </div>
        <div class="admin__data-grid-wrap admin__data-grid-wrap-static">
        <?php if ($block->getGridCssClass()): ?>
            <table class="<?php /* @escapeNotVerified */ echo $block->getGridCssClass() ?> data-grid" id="<?php echo $block->escapeHtml($block->getId()) ?>_table">
                <!-- Rendering column set -->
                <?php echo $block->getChildHtml('grid.columnSet'); ?>
            </table>
        <?php else: ?>

            <table class="data-grid" id="<?php echo $block->escapeHtml($block->getId()) ?>_table">
                <!-- Rendering column set -->
                <?php echo $block->getChildHtml('grid.columnSet'); ?>
            </table>

            <?php if ($block->getChildBlock('grid.bottom.links')): ?>
                <?php echo $block->getChildHtml('grid.bottom.links') ?>
            <?php endif; ?>

        <?php endif ?>
        </div>
<?php if ($block->canDisplayContainer()): ?>
</div>
<script>
    var deps = [];

    <?php if ($block->getDependencyJsObject()): ?>
    deps.push('uiRegistry');
    <?php endif; ?>

    <?php if (strpos($block->getRowClickCallback(), 'order.') !== false): ?>
    deps.push('Magento_Sales/order/create/form')
    <?php endif; ?>

    deps.push('mage/adminhtml/grid');

    require(deps, function(<?php echo ($block->getDependencyJsObject() ? 'registry' : '') ?>){
        <?php //TODO: getJsObjectName and getRowClickCallback has unexpected behavior. Should be removed ?>

        <?php if ($block->getDependencyJsObject()): ?>
            registry.get('<?php /* @escapeNotVerified */ echo $block->getDependencyJsObject() ?>', function (<?php /* @escapeNotVerified */ echo $block->getDependencyJsObject() ?>) {
        <?php endif; ?>

        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?> = new varienGrid('<?php echo $block->escapeHtml($block->getId()) ?>', '<?php /* @escapeNotVerified */ echo $block->getGridUrl() ?>', '<?php /* @escapeNotVerified */ echo $block->getVarNamePage() ?>', '<?php /* @escapeNotVerified */ echo $block->getVarNameSort() ?>', '<?php /* @escapeNotVerified */ echo $block->getVarNameDir() ?>', '<?php /* @escapeNotVerified */ echo $block->getVarNameFilter() ?>');
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.useAjax = <?php /* @escapeNotVerified */ echo $block->getUseAjax() ? 'true' : 'false' ?>;
        <?php if ($block->getRowClickCallback()): ?>
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.rowClickCallback = <?php /* @escapeNotVerified */ echo $block->getRowClickCallback() ?>;
        <?php endif; ?>
        <?php if ($block->getCheckboxCheckCallback()): ?>
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.checkboxCheckCallback = <?php /* @escapeNotVerified */ echo $block->getCheckboxCheckCallback() ?>;
        <?php endif; ?>
        <?php if ($block->getSortableUpdateCallback()): ?>
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.sortableUpdateCallback = <?php /* @escapeNotVerified */ echo $block->getSortableUpdateCallback()?>;
        <?php endif; ?>
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.bindSortable();
        <?php if ($block->getRowInitCallback()): ?>
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.initRowCallback = <?php /* @escapeNotVerified */ echo $block->getRowInitCallback() ?>;
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.initGridRows();
        <?php endif; ?>
        <?php if ($block->getChildBlock('grid.massaction') && $block->getChildBlock('grid.massaction')->isAvailable()): ?>
        <?php /* @escapeNotVerified */ echo $block->getChildBlock('grid.massaction')->getJavaScript() ?>
        <?php endif ?>
        <?php /* @escapeNotVerified */ echo $block->getAdditionalJavaScript(); ?>

        <?php if ($block->getDependencyJsObject()): ?>
            });
        <?php endif; ?>
    });
</script>
<?php endif; ?>

<?php if ($block->getChildBlock('grid.js')): ?>
    <?php echo $block->getChildHtml('grid.js'); ?>
<?php endif; ?>

<?php endif ?>
