<?php
Yii::app()->clientScript->registerCoreScript('jquery.ui');
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/plDialog/plDialog.js', CClientScript::POS_HEAD);

$this->widget('ext.PlGrid.PlGridView', array(
    'id' => 'alerts-grid',
    'headerTitle' => 'Header_title', // optional
    'itemsCssClass' => 'plTable items',
    'enableAddButton' => false,
    'enableSearchButton' => false,
    'modalUpdateHeader' => 'ALERT_MODEL_DESCRIPTION', // optional
    'dataProvider' => $model->search(),
    'filter' => $model,
    'customButtons' => $customButtons,
    'columns' => array(
        array(
            'name' => 'level',
            'header' => $model->getAttributeLabel('level'),
            'headerHtmlOptions' => array('data-translation-target' => 'ALERT_MODEL_LEVEL',
                'data-translation-id' => 'ALERT_MODEL_LEVEL'
            ),
            'value' => array($this, 'renderLevel'),
        ),
        array(
            'name' => 'created',
            'header' => $model->getAttributeLabel('created'),
            'headerHtmlOptions' => array('data-translation-target' => 'ALERT_MODEL_CREATED',
                'data-translation-id' => 'ALERT_MODEL_CREATED'
            ),
            'value' => array($this, 'renderDateTime'),
        ),
        array(
            'name' => 'component',
            'header' => $model->getAttributeLabel('component'),
            'headerHtmlOptions' => array('data-translation-target' => 'ALERT_MODEL_COMPONENT',
                'data-translation-id' => 'ALERT_MODEL_COMPONENT'
            ),
        ),
        array(
            'name' => 'shortDescr',
            'header' => $model->getAttributeLabel('shortDescr'),
            'headerHtmlOptions' => array('data-translation-target' => 'ALERT_MODEL_SHORT_DESCRIPTION',
                'data-translation-id' => 'ALERT_MODEL_SHORT_DESCRIPTION'
            ),
        ),
        array(
            'class' => 'ext.PlGrid.PlCButtonColumn',
            'template' => '{description}{delete}',
            'buttons' => array(
                'delete' => array(
                    'url' => 'url("systemOverview/default/deleteAlert", array("id"=>"$data->id"))',
                ),
                'description' => array(
                    'label' => __('ALERT_MODEL_DESCRIPTION'),
                    'url' => 'url("systemOverview/default/alertDescr", array("id"=>"$data->id"))',
                    'icon' => 'icon-search',
                    'click' => 'js:function(){showAlertDescription(this); return false;}',
                ),
            ),
        )
    ),
        )
);

if (app()->user->translateMode) {
    $this->renderPartial('_translationTags');
}
?>
<script>
    function showAlertDescription(btn) {
        var index = btn.href.indexOf('id=') + 3;
        var id = btn.href.substr(index);

        var shortDescr = '';
        var descr = '';

        $.ajax({
            url: "<?php echo url('systemOverview/default/alertDescr'); ?>",
            type: "POST",
            dataType: "json",
            data: {
                id: id
            },
            success: function (result) {
                if (result.status === 'ok') {
                    shortDescr = result.shortDescr;
                    descr = result.descr;
                    showDescriptionAlert(shortDescr, descr);
                }
            }
        });
    }

    function showDescriptionAlert(shortDescr, descr) {

        var options = {
            modalType: "alert",
            dialogHeader: "<?php echo __('SYSTEM_OVERVIEW_ALERT_DIALOG_HEADER'); ?>" + " " + shortDescr,
            confirmMessage: descr.replace(/(?:\r\n|\r|\n)/g, '<br />'),
            confirmText: "<?php echo __('GLOBAL_CLOSE_BUTTON'); ?>",
            height: 500,
            width: 800
        };

        var plDialog = new $.plDialog(options);
        plDialog.showConfirmDialog();
    }
</script>