<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use home\modules\task\models\Category;
use qcbase\models\TaskStatus;
use home\modules\task\models\Task;
use common\widgets\Editor;
use common\widgets\DatePicker;
use common\widgets\Uploader;

/* @var $this \yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \home\modules\task\models\Task */

$attrLabels = $model->attributeLabels();

$form = ActiveForm::begin([
        'id' => 'main-form',
        'options' => ['class' => 'informationform f14'],
        'action' => $action,
        'fieldConfig' => [
            'options' => ['tag' => 'td'],
            'template' => "{input}{hint}{error}",
            'errorOptions' => ["class" => "error"]
        ]
    ]);
?>

<table cellpadding="0" cellspacing="10" width="100%">
    <tbody>
        <tr>
            <td align="right" width="10%"><?= $model->getAttributeLabel('name') ?>：</td>
            <?= $form->field($model, 'name', ['options' => ['width' => '30%']])->textInput(['class' => 'form-control']) ?>
            <td width="10%"><span class="redstar">*</span></span></td>

            <td align="right" width="10%"><?= $model->getAttributeLabel('task_no') ?>：</td>
            <?= $form->field($model, 'task_no', ['options' => ['width' => '30%']])->textInput(['class' => 'form-control', 'readonly' => ($model->isNewRecord) ? false : true]) ?>
            <td width="10%"><span class="redstar">*</span></span></td>
        </tr>
        <tr>
            <td align="right"><?= $model->getAttributeLabel('parent_id') ?>：</td>

            <?= $form->field($model, 'parent_name')->textInput(['class' => (isset($_GET['parent_id'])) ? 'form-control' : 'form-control select-task', 'readonly' => (isset($_GET['parent_id'])) ? true : false, 'placeholder' => '点击选择,留空则为顶级任务', 'data-hidden-id' => 'parent-id', 'data-url' => Url::to(['/link/task','type_permission'=>'create-child']), 'data-title' => '选择父任务', 'data-callback' => 'selectTaskCallback']) ?>
            <?= $form->field($model, 'parent_id', ['options' => ['tag' => 'div']])->hiddenInput(['id' => 'parent-id']) ?>

            <td>
                <?php if (!isset($_GET['parent_id'])) : ?>
                <span class="c6"><a href="javascript:;" class="clear-input clear-input-parent" data-input-id="task-parent_name" data-hidden-id="parent-id" style="color:#888;">清空</a></span>
                <?php endif; ?>
            </td>

            <td align="right"><?= $model->getAttributeLabel('category_id') ?>：</td>
            <td>
                <select class="form-control" name="Task[category_id]" id="category-select" >
<?php echo Category::getDropDownTreeList($model->category_id); ?>
                </select>
            </td>
            <td><span class="redstar">*</span></td>
        </tr>
        <tr>
            <td align="right"><?= $model->getAttributeLabel('status_id') ?>：</td>
<?= $form->field($model, 'status_id')->dropDownList(TaskStatus::getDropDownList()) ?>
            <td><span class="redstar">*</span></td>

            <td align="right"><?= $model->getAttributeLabel('workload') ?>：</td>
<?= $form->field($model, 'workload')->textInput(['class' => 'form-control']) ?>
            <td><span class="c6">H</span></td>
        </tr>
        <tr>
            <td align="right"><?= $model->getAttributeLabel('leader_name') ?>：</td>

            <?= $form->field($model, 'leader_name')->textInput(['class' => 'form-control select-single-user', 'placeholder' => '点击选择', 'data-hidden-id' => 'leader-id', 'data-url' => Url::to(['/link/single-user']),
                'data-title' => '选择负责人']) ?>
<?= $form->field($model, 'leader_id', ['options' => ['tag' => 'div']])->hiddenInput(['id' => 'leader-id']) ?>

            <td><span class="c6"><a href="javascript:;" class="clear-input" data-input-id="task-leader_name" data-hidden-id="leader-id" data-hidden-value="0" style="color:#888;">清空</a></span></td>

            <td align="right">选择关联：</td>
            <td>
                <select class="form-control link-select" id="link-type" name="Task[link_type]" style="width:33%; display: inline" >
                    <?php foreach (common\models\Common::getLinkTypes(['project', 'customer']) as $type) : ?>
                        <option value="<?= $type['type'] ?>" <?= $model->link_type == $type['type'] ? 'selected="selected"' : '' ?> data-class="<?= $type['class'] ?>" data-url="<?= Url::to([$type['url'][0], 'type_module' => 'task']) ?>" data-title="选择<?= $type['name'] ?>" ><?= $type['name'] ?></option>
                    <?php endforeach; ?>
                </select>
                <input type="input" id="link-input" class="form-control " placeholder="点击选择" value="<?= $model->link_name ?>" data-hidden-id="link-id" data-switch="0" style="width: 65%; display: inline" />
<?= $form->field($model, 'link_id', ['options' => ['tag' => 'div']])->hiddenInput(['id' => 'link-id']) ?>
            </td>
            <td><span class="c6 clear-input-span"><a href="javascript:;" class="clear-input" data-input-id="link-input" data-hidden-id="link-id" style="color:#888;">清空</a></span></td>
        </tr>
        <tr>
            <td align="right"><?= $model->getAttributeLabel('join_names') ?>：</td>

            <?= $form->field($model, 'join_names')->textInput(['class' => 'form-control select-multi-user', 'placeholder' => '点击选择', 'data-hidden-id' => 'join-ids', 'data-url' => Url::to(['/link/multi-user']), 'data-title' => '选择参与人']) ?>
            <?= $form->field($model, 'join_ids', ['options' => ['tag' => 'div']])->hiddenInput(['id' => 'join-ids']) ?>

            <td><span class="c6"><a href="javascript:;" class="clear-input" data-input-id="task-join_names" data-hidden-id="join-ids" style="color:#888;">清空</a></span></td>
            <td align="right"><?= $model->getAttributeLabel('follow_names') ?>：</td>

            <?= $form->field($model, 'follow_names')->textInput(['class' => 'form-control select-multi-user', 'placeholder' => '点击选择', 'data-hidden-id' => 'follow-ids', 'data-url' => Url::to(['/link/multi-user']), 'data-title' => '选择关注人']) ?>
            <?= $form->field($model, 'follow_ids', ['options' => ['tag' => 'div']])->hiddenInput(['id' => 'follow-ids']) ?>

            <td><span class="c6"><a href="javascript:;" class="clear-input" data-input-id="task-follow_names" data-hidden-id="follow-ids" style="color:#888;">清空</a></span></td>
        </tr>
        <tr>
            <td align="right"><?= $model->getAttributeLabel('begin_time') ?>：</td>
            <?= DatePicker::widget(['model' => $model, 'form' => $form, 'attribute' => 'begin_time', 'inputConfig' => ['class' => 'form-control']]) ?>
            <td></td>

            <td align="right"><?= $model->getAttributeLabel('end_time') ?>：</td>
            <?= DatePicker::widget(['model' => $model, 'form' => $form, 'attribute' => 'end_time', 'inputConfig' => ['class' => 'form-control']]) ?>
            <td></td>
        </tr>
        <tr class="pd4">
            <td align="right">任务描述：</td>
            <?= Editor::widget(['model' => $model, 'form' => $form, 'attribute' => 'description', 'fieldConfig' => ['options' => ['colspan' => '4']], 'inputConfig' => ['class' => '','rows' => '5'], 'editorType' => 'simple' ,'width' => '100%', 'height' => 100]) ?>
            <td></td>
        </tr>
        <tr>
            <td align="right"><?= $model->getAttributeLabel('remark') ?>：</td>
            <?= $form->field($model, 'remark', ['options' => ['colspan' => '4']])->textarea(['class' => 'form-control', 'rows' => '4']) ?>
            <td><span class="redstar"></span></td> 
        </tr>
        <tr>
            <td align="right">附件：</td>
            <td colspan="5">
            <?= Uploader::widget(['model' => $model, 'form' => $form, 'attribute' => 'attach_ids', 'type' => 'files']) ?>
            </td>
        </tr>
    </tbody>
</table>
<p>
<?= ($model->isNewRecord) ? '' : Html::hiddenInput('id', $model->task_id); ?>

</p>
<!--
<p class="tips">注：保存时换责任人弹出提示，因为一旦更换就没有这个任务的权限了</p>
-->

<?php ActiveForm::end(); ?>
