<?php

use yii\helpers\Html;
use backend\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\Policy */
/* @var $form backend\widgets\ActiveForm */
/* @var $configModels [] */
?>

<div class="box box-success">
    <div class="box-body">
        <?php $form = ActiveForm::begin([
                'enableClientValidation'=>false]); ?>

        <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
        <?= $form->field($model, 'author')->textInput(['maxlength' => true]) ?>
        <?= $form->field($model, 'type')->checkboxList(\common\models\Policy::getTypeList()) ?>
		<?php

        foreach ($configModels as $index => $configModel) {
	
			$value = explode("\r\n",$configModel['extra']);
            $value1 = explode("\r\n",$configModel['value']);
            
            if($configModel['name'] == 'cengci'){
                $arr = [];
    			foreach($value as &$val){
    				$val = trim($val);
    				$arr[$val] = $val;
    			}
    
                echo $form->field($model, 'id')->checkboxList($arr,[
    				'name'=>'cengci',
    				'value'=>$model->cengci
    			])->label($configModel['description']);
            }else{
                $arr = [];
    			foreach($value as $key=>&$val){
    				$k = trim($value1[$key]);
    				$arr[$k] = trim($val);
    			}
 
                echo $form->field($model, 'id')->checkboxList($arr,[
    				'name'=>$configModel['name'],
    				'value'=>$model->filter[$configModel['name']]
    			])->label($configModel['description']);
            }
      
			
        }
    
        ?>

        <?= $form->field($model, 'summary')->widget(\common\widgets\EditorWidget::className(), $model->isNewRecord ? ['type' => request('editor') ?: config('page_editor_type')] : ['isMarkdown' => $model->markdown]) ?>
        <?= $form->field($model, 'content')->widget(\common\widgets\EditorWidget::className(), $model->isNewRecord ? ['type' => request('editor') ?: config('page_editor_type')] : ['isMarkdown' => $model->markdown]) ?>

        <div class="form-group form-submit">
            <?= Html::submitButton($model->isNewRecord ? '创建' : '更新', ['class' => 'btn btn-flat bg-maroon btn-block']) ?>
        </div>


        <?php ActiveForm::end(); ?>
    </div>
</div>
<?php $this->beginBlock('js') ?>
<script>
    $(document).on('change', '#choose-editor', function () {
        var url = '<?= \yii\helpers\Url::to(['create']) ?>';
        var type = $(this).val();
        url = url.addQueryParams({editor: type});
        location.href = url;
    })
</script>
<?php $this->endBlock() ?>
