<?php
/* @var $this QuestionnaireQuestionController */
/* @var $model QuestionnaireQuestion */

$this->breadcrumbs = array(
    'Questionnaires' => array('questionnaire/admin'),
    Yii::t('admin', 'Manage'),
);

$this->menu = array(
    array('label' => 'Manage Questionnaire Question', 'url' => array('admin', 'questionnaire_id' => $model->questionnaire_id)),
    array('label' => 'Create Questionnaire Question', 'url' => array('create', 'questionnaire_id' => $model->questionnaire_id)),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#questionnaire-question-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<div class="page-header">
    <h1>
        <?php echo Yii::t("admin", "Manage Questionnaire Questions"); ?>
        <?php echo CHtml::link(Yii::t("admin", "Create Questionnaire Question"), array("create", 'questionnaire_id' => $model->questionnaire_id), array("class" => "btn btn-sm btn-primary pull-right")); ?>
    </h1>
</div>

<!--<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>-->

<?php echo CHtml::link('Advanced Search', '#', array('class' => 'search-button btn btn-xs')); ?>
<div class="search-form display-none">
    <?php
    $this->renderPartial('_search', array(
        'model' => $model,
    ));
    ?>
</div><!-- search-form -->

<?php
$this->widget('ext.widgets.FGridView', array(
    'id' => 'questionnaire-question-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        'id',
        array(
            'name' => 'type',
            'value' => 'QuestionnaireQuestion::getType($data->type);',
        ),
        'title',
//        'options',
        array(
            'class' => 'CButtonColumn',
            'viewButtonUrl' => 'Yii::app()->controller->createUrl("view",array("id"=>$data->primaryKey,"questionnaire_id" => $data->questionnaire_id))',
            'updateButtonUrl' => 'Yii::app()->controller->createUrl("update",array("id"=>$data->primaryKey,"questionnaire_id" => $data->questionnaire_id))',
            'deleteButtonUrl' => 'Yii::app()->controller->createUrl("delete",array("id"=>$data->primaryKey,"questionnaire_id" => $data->questionnaire_id))',
            'buttons' => [
                'update' => [
                    'visible' => function($row, $data){
                        $criteria = new CDbCriteria;
                        $criteria->condition = 'question_id = ' . $data->id;
                        $answer = QuestionnaireAnswer::model()->find($criteria);
                        return $answer ? false : true;
                    }
                ],
                'delete' => [
                    'visible' => function($row, $data){
                        $criteria = new CDbCriteria;
                        $criteria->condition = 'question_id = ' . $data->id;
                        $answer = QuestionnaireAnswer::model()->find($criteria);
                        return $answer ? false : true;
                    }
                ],
            ],
        ),
    ),
));
?>
