<?php
cs()->registerScriptFile(Yii::app()->baseUrl . '/js/permissionInheritance/permissionInheritance.js', CClientScript::POS_HEAD);

$form = $this->beginWidget('ext.PlGrid.PlActiveForm', array(
    'id' => 'calendar-form',
    'gridId' => 'calendar-grid',
    'action' => $model->isNewRecord ? array('create') : array()
        ));

echo $form->textFieldRow($model, 'title', array(
    'class' => 'span3',
    'data-translation-id' => 'CALENDAR_MODEL_TITLE',
));

echo $form->colorFieldRow($model, 'color', array(
    'class' => 'span3',
    'data-translation-id' => 'CALENDAR_MODEL_COLOR',
));

if ($model->isNewRecord()) {
    $listdata = array(
        CalendarType::personal => __('CALENDAR_MODEL_TYPE_PRIVATE'),
        CalendarType::group => __('CALENDAR_MODEL_TYPE_GROUP'),
    );
    asort($listdata);
    echo $form->dropDownListRow($model, 'type', $listdata, array(
        'class' => 'span3',
        'data-translation-id' => 'CALENDER_MODEL_TYPE',
        'data-translation-target' => 'CALENDER_TYPES_DROPDOWN_TARGET',
        'options' => array(
            '1' => array(
                'value' => CalendarType::personal,
                'label' => __('CALENDAR_MODEL_TYPE_PRIVATE'),
                'data-translation-id' => 'CALENDAR_MODEL_TYPE_PRIVATE',
                'data-translation-target' => 'test',
            ),
            '2' => array(
                'value' => CalendarType::group,
                'label' => __('CALENDAR_MODEL_TYPE_GROUP'),
                'data-translation-id' => 'CALENDAR_MODEL_TYPE_GROUP',
                'data-translation-target' => 'test',
            ),
        )
    ));
}

$groups = new Groups();
$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'test-grid',
    'type' => 'striped bordered condensed',
    'itemsCssClass' => 'plTable',
    'dataProvider' => $groups->search('nestedIndex', false),
    'filter' => $groups,
    'summaryText' => false,
    'columns' =>
    array(
        array(
            'name' => 'nestedName',
            'header' => $groups->getAttributeLabel('name'),
            'headerHtmlOptions' => array('data-translation-id' => 'USERGROUPS_MODEL_NAME'),
        ),
        array(
            'type' => 'raw',
            'id' => 'read_calendar',
            'header' => __('USERGROUP_MODEL_READ_CALENDAR_PERMISSION'),
            'value' => array($model, 'renderPermissions'),
            'headerHtmlOptions' => array('data-translation-id' => 'USERGROUP_MODEL_READ_CALENDAR_PERMISSION'),
            'htmlOptions' => array('data-custom-contexthelp-key' => 'PERMISSIONS_READ_CALENDAR_CONTEXT_HELP')
        ),
        array(
            'type' => 'raw',
            'id' => 'write_calendar',
            'header' => __('USERGROUP_MODEL_WRITE_CALENDAR_PERMISSION'),
            'value' => array($model, 'renderPermissions'),
            'headerHtmlOptions' => array('data-translation-id' => 'USERGROUP_MODEL_WRITE_CALENDAR_PERMISSION'),
            'htmlOptions' => array('data-custom-contexthelp-key' => 'PERMISSIONS_WRITE_CALENDAR_CONTEXT_HELP')
        ),
    ),
));
$this->endWidget();
?>

<script>
    $('.plColorPicerInput').minicolors({
        theme: 'yourThemeName'
    });

    setReadSelectorTo('read_calendar');
    setWriteSelectorTo('write_calendar');
    setAllUsedReadCheckBoxesToTrue(readSelector, writeSelector);
</script>