<?php
$this->widget('ext.PlNavbar', array(
    'brand' => __('ADMIN_LDAP_INTERFACE_SECTION_TITLE'),
    'htmlOptions' => array(
        'data-translation-id' => 'ADMIN_LDAP_INTERFACE_SECTION_TITLE',
    ),
    'helpBtnUrl' => 'adminLdapInterface-import',
    'items' => array(
        array(
            'class' => 'bootstrap.widgets.TbMenu',
            'items' => array(
                '---',
                array(
                    'label' => __('GLOBAL_BACK'),
                    'url' => $returnUrl,
                    'icon' => 'arrow-left',
                    'linkOptions' => array(
                        'id' => 'back_button',
                        'data-target' => '#',
                        'data-translation-id' => 'GLOBAL_BACK'
                    )
                ),
            ),
        ),
    ),
));

$this->widget(
        'bootstrap.widgets.TbButtonGroup', array(
    'toggle' => 'checkbox',
    'buttons' => array(
        array(
            'label' => __('ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_CREATED'),
            'htmlOptions' => array(
                'id' => 'hideCreatedBtn',
                'data-translation-id' => 'ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_CREATED',
                'onclick' => 'changeVisibility(id, "created")'
            )
        ),
        array(
            'label' => __('ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_INVALID'),
            'htmlOptions' => array(
                'id' => 'hideInvalidBtn',
                'data-translation-id' => 'ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_INVALID',
                'onclick' => 'changeVisibility(id, "invalid")'
            )
        ),
        array(
            'label' => __('ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_UPDATED'),
            'htmlOptions' => array(
                'id' => 'hideUpdatedBtn',
                'data-translation-id' => 'ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_UPDATED',
                'onclick' => 'changeVisibility(id, "updated")'
            )
        ),
        array(
            'label' => __('ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_UP_TO_DATE'),
            'htmlOptions' => array(
                'id' => 'hideUpToDateBtn',
                'data-translation-id' => 'ADMIN_LDAP_INTERFACE_PREVIEW_HIDE_UP_TO_DATE',
                'onclick' => 'changeVisibility(id, "upToDate")'
            )
        ),
    ),
        )
);
$this->widget('ext.PlGrid.PlGridView', array(
    'id' => 'adminLdapInterface-preview',
    'itemsCssClass' => 'plTable items',
    'rowCssClassExpression' => function($row, $data) {
        return $data['status'];
    },
    'navBarHtmlOptions' => array('style' => 'display:none'),
    'dataProvider' => $dataProvider,
    'columns' => $this->renderPreviewTable($columnAttributes)
        )
);

$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'button',
    'type' => 'primary',
    'label' => __('ADMIN_LDAP_INTERFACE_IMPORT_BTN'),
    'htmlOptions' => array(
        'id' => 'LdapInterfaceImportBtn',
        'data-translation-id' => 'ADMIN_LDAP_INTERFACE_IMPORT_BTN',
        'onclick' => 'ajaxImport()'
    ),
));
?>
<style>
    #LdapInterfaceImportBtn{
        margin-right:20px
    }
    .label {
        text-align: center;
    }
    .hideRow {
        display:none;
    }
</style>
<script>
    function ajaxImport() {
        $.ajax({
            url: '<?php echo url('adminLdapInterface/default/ajaxImport', array('id' => $id)); ?>',
            type: "POST",
            async: false,
            dataType: "json",
            success: function () {
                window.location = '<?php echo url('adminLdapInterface/default/index'); ?>';
            }
        });
    }

    function changeVisibility(buttonID, status)
    {
        var button = $('#' + buttonID);
        $('#adminLdapInterface-preview tbody tr').each(function (i, row) {
            if ($(row).hasClass(status)) {
                if (!button.hasClass('active')) {
                    $(row).addClass("hideRow");
                } else {
                    $(row).removeClass("hideRow");
                }
            }
        });
    }
</script>