<?php

use wap\assets\AppAsset;
use common\assets\MobiscrollAsset;
use yii\helpers\Html;
use yii\helpers\Url;
use wap\assets\BlogAsset;
use yii\helpers\StringHelper;

$this->title = '写日志';

/* @var $this \yii\web\View */

MobiscrollAsset::register($this);
BlogAsset::register($this);
$asset = $this->getAssetManager()->getBundle(AppAsset::className());
$this->registerJsFile(Yii::getAlias('@web') . '/static/js/jquery/jquery.hotkeys.js', ['depends' => [AppAsset::className()]]);
$this->registerJsFile(Yii::getAlias('@web') . '/static/js/bootstrap/bootstrap-wysiwyg.js', ['depends' => [AppAsset::className()]]);
$this->registerJsFile(Yii::getAlias('@web') . '/static/js/jquery/jquery.ui.widget.js', ['depends' => [AppAsset::className()]]);
$this->registerJsFile(Yii::getAlias('@web') . '/static/js/jquery/jquery.iframe-transport.js', ['depends' => [AppAsset::className()]]);
$this->registerJsFile(Yii::getAlias('@web') . '/static/js/jquery/jquery.fileupload.js', ['depends' => [AppAsset::className()]]);
$this->registerJsFile($asset->baseUrl . '/js/scroll.load.js', ['depends' => [AppAsset::className()]]);
$this->registerJsFile($asset->baseUrl . '/js/blog.create.js', ['depends' => [AppAsset::className()]]);
?>
<style>
    #editor {
        max-height: 100px;
        height: 100px;
        background-color: white;
        border-collapse: separate;
        border: 1px solid rgb(204, 204, 204);
        padding: 4px;
        box-sizing: content-box;
        -webkit-box-shadow: rgba(0, 0, 0, 0.0745098) 0px 1px 1px 0px inset;
        box-shadow: rgba(0, 0, 0, 0.0745098) 0px 1px 1px 0px inset;
        border-top-right-radius: 3px;
        border-bottom-right-radius: 3px;
        border-bottom-left-radius: 3px;
        border-top-left-radius: 3px;
        overflow: scroll;
        outline: none;
    }
    #editor img {
        max-width:50%;
    }
    .btn_uploadfile{
        position:relative;
        width:49%;
        float:left;
        color:#005bb8;
        padding:6px 12px;
    }
    .btn_uploadfile_title{
        text-align:center;
        font-weight:800
    }
    .inputstyle{
        width: 100%;
        height: 100%;
        cursor: pointer;
        outline: medium none;
        position: absolute;
        filter:alpha(opacity=0);
        -moz-opacity:0;
        opacity:0;
        left:0px;
        top: 0px;
    }
</style>
<script>
    var blogCheckUrl = "<?= Url::to(['blog-check']) ?>";
    var workTime = "<?= Yii::$app->request->get('work_time', date('Y-m-d')) ?>";
</script>

<div class="modal fade" style="margin-top:15%">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-body">
            </div>
        </div>
    </div>
</div>

<?= $this->render('_calendar') ?>

<?= ($linkType == 'task') ? $this->render('/task/_task-overview', ['task' => $linkData]) : '' ?>

<div class="write-log">
    <form id="main-form" action="<?= Url::to(['create']) ?>" method="post">
        <table width="100%">

            <tr>
                <td width="40">标题</td>
                <td><input type="text" class="form-control" name="Blog[title]" value="<?= (!empty($model['title'])) ? $model['title'] : Yii::$app->request->get('link_title', '') ?>" style="width:73%; float:left" placeholder="请输入标题"><input type="text" name="Blog[workload]" value="<?= (!empty($model['workload']))
                                                                                                                                                                                                                                                       ? $model['workload']
                                                                                                                                                                                                                                                       : 8
?>" class="form-control" style="width:25%; float:right" placeholder="工作量(H)"></td>
            </tr>

            <tr>
                <td valign="top">内容</td>
                <td> 
                    <div id="editor"><?= (!empty($model['content'])) ? $model['content'] : '' ?></div>
                    <textarea name="Blog[content]" style="display:none;" row="3" ><?= (!empty($model['content'])) ? $model['content'] : '' ?></textarea>
                </td>
            </tr>

<?php foreach ($attachs as $attach) : ?>
                <tr class="file-tr" data-attach-id="<?= $attach['attach_id'] ?>">
                    <td></td>
                    <td class="icon-download-alt"><a  href="<?= Url::to('@web/index.php?r=attachment/download&id=' . $attach['attach_id']) ?>" ><?= StringHelper::truncate($attach['file_name'], 15) ?></a><button type="button" class="btn btn-filedelete delete-file  icon-trash"></button>
                    </td>
                </tr>
<?php endforeach; ?>

            <tr class="upload-tr">
                <td></td>
                <td> 
                    <div class="btn_uploadfile btn btn-default">
                        <div class="btn_uploadfile_title"><i class=" icon-upload-alt"></i>上传附件</div>
                        <input id="fileupload" type="file" class="inputstyle" style="" name="files[]" data-url="<?= Url::to('@web/index.php?r=attachment/upload') ?>" data-down-url="<?= Url::to('@web/index.php?r=attachment/download') ?>" multiple data-form-data='{"route":"wap/blog/create"}'>
                    </div>

                    <!--<button type="button" class="btn btn-default" style="width:49%; float:right; color:#005bb8; padding:6px 12px;"><i class="icon-camera"></i> 拍照</button>-->
                </td>
            </tr>

            <tr>
                <td></td>
                <td><button type="button" id="submit-btn" class="btn btn-primary" style="width:100%">提  交</button></td>
            </tr>
        </table>
        <input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>" />
        <input name="Blog[work_time]" type="hidden" value="<?= (!empty($_GET['work_time'])) ? Yii::$app->request->get('work_time') : date('Y-m-d') ?>" />
        <input name="Blog[link_id]" type="hidden" value="<?= $linkId ?>" />
        <input name="Blog[link_type]" type="hidden" value="<?= $linkType ?>" />
        <input name="Blog[blog_id]" type="hidden" value="<?= (!empty($model['blog_id'])) ? $model['blog_id'] : 0 ?>" />
        <input name="Blog[attach_ids]" type="hidden" value="<?= $model['attach_ids'] ?>" />
    </form>
</div>



<div class="common-list log-list">
    <ul id="scroll-ul" data-scroll-pagination="enabled" data-page-url="<?= Url::to(['index', 'link_id' => $linkId, 'link_type' => $linkType]) ?>" >
    </ul>
    <div id="loading" class="load">
        <p><img src="<?= Yii::getAlias('@web') ?>/static/images/scroll-loading.gif" alt="加载中"></p>
    </div>
    <div id="load-end">
        <p><a href="javascript:;">点击显示更多</a></p>
    </div>
    <div id="load-top"></div>

</div>


