<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/13/013
 * Time: 11:01
 */
use yii\helpers\Url;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>BIT System 后台管理平台</title>
    <?php include(Yii::getAlias("@cp_module_views")."/common/css_js_main.php") ?>
    <!--Kindeditor4 end -->
    <script charset="utf-8" src="<?= STATIC_URL ?>/static/cp/editor/kindeditor-min.js"></script>
    <script charset="utf-8" src="<?= STATIC_URL ?>/static/cp/editor/lang/zh_CN.js"></script>
    <script type="text/javascript">
        $().ready(function() {
            $('#imagePath').hide();
        });
    </script>

    <script>
        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
                uploadJson: '<?= Url::to(['/cp/file/upload']); ?>',
                fileManagerJson: '<?= Url::to(['/cp/file/file-manager']); ?>',
                allowFileManager: true,
                afterBlur: function () {
                    this.sync()
                },
                height: '400px',
                items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image','multiimage', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'map', 'code', 'link', 'unlink']
            });

            K('#fileManagerButton').click(function() {
                editor.loadPlugin('filemanager',
                    function() {
                        editor.plugin.filemanagerDialog({
                            viewType: 'VIEW',
                            dirName: 'image',
                            clickFn: function(url, title) {
                                K('#imagePath').val(url);
                                editor.hideDialog();
                                $('#image').hide();
                                $('.file, .ui-input-file').hide();
                                $('#imagePath').show();
                            }
                        });
                    });
            });

        });
    </script>
    <!--Kindeditor4 end -->

</head>
<body id="main">
<div class="main-nav"> <span class="fn-left"><?php if($isAddAction) { ?>添加<?php } else { ?>编辑<?php } ?>文章</span> <span class="fn-right"><a href="javascript:javascript:history.go(-1);"><i class="icon-chevron-left"></i>返回</a></span>
    <div class="fn-clear"></div>
</div>
<div class="main-content">
    <div class="form-or-table">
        <form class="form-horizontal" id="validateForm" action="<?php if($isAddAction){echo Url::to(['/cp/article/save']);} else {echo Url::to(['/cp/article/update']);} ?>" method="post" enctype="multipart/form-data">
            <input type="hidden" name="<?= Yii::$app->request->csrfParam ?>" value="<?= Yii::$app->request->getCsrfToken() ?>" />
            <input type="hidden" name="id" value="<?= !empty($article['id']) ? $article['id'] : '' ?>" />
            <fieldset>
                <div class="blank15"></div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>文章标题</label>
                    <div class="controls">
                        <input type="text" id="title" name="title" class="span5" value="<?= !empty($article['title']) ? $article['title'] : '' ?>"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">副标题</label>
                    <div class="controls">
                        <input type="text" id="subTitle" name="sub_title" class="span5" value="<?= !empty($article['sub_title']) ? $article['sub_title'] : '' ?>"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>文章分类</label>
                    <div class="controls">
                        <select id="parentId" name="article_category_id">
                            <option value="">请选择...</option>
                            <?php foreach ($articleCategoryTreeList as $articleCategoryTree) { ?>
                                <option value="<?= $articleCategoryTree['id'] ?>"<?php $bool = !array_diff($articleCategoryTree, (!empty($article['category']) ? $article['category'] : []));if(!empty($bool)) { ?> selected<?php } ?>>
                                <?php if($articleCategoryTree['grade'] != 0) { ?>
                                    <?php for($i=1;$i<=$articleCategoryTree['grade'];$i++) { ?>
                                        &nbsp;&nbsp;
                                    <?php } ?>
                                <?php } ?>
                                <?= $articleCategoryTree['name'] ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">作者</label>
                    <div class="controls">
                        <input type="text" id="author" name="author" class="input-mini" value="<?= !empty($article['author']) ? $article['author'] : '' ?>"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="fileInput">图片</label>
                    <div class="controls">
                        <input type="text" id="imagePath" class="input-file" name="image_path" readonly="readonly" />
                        <input type="file" id="image" name="image" class="input-file"/>
                        <input style="margin-left:20px;" class="btn span2" id="fileManagerButton" value="浏览服务器" />
                        <?php $bool = !empty($article['image_path']) ? $article['image_path'] : '';if (!empty($bool)) { ?>
                            <a class="link" href="<?= Url::to([$article['image_path']]) ?>" target="_blank">查看</a>
                        <?php } ?>
                        <p class="help-block">点击浏览服务器按钮,可选择已上传的图片</p>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">图片关键字</label>
                    <div class="controls">
                        <input type="text" id="metaImge" name="meta_imge" class="input-xlarge" value="<?= !empty($article['meta_imge']) ? $article['meta_imge'] : '' ?>"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="inlineCheckboxes">设置</label>
                    <div class="controls">
                        <label class="checkbox inline">
                            <input type="checkbox" id="isPublication" name="isPublication" value="1" <?= ((isset($isPublication) && $isPublication) || $isAddAction) ? 'checked="checked"' : '' ?>/> 发布
                           <!-- <@checkbox name="isPublication" value="${(article.isPublication)!true}" /> 发布-->
                        </label>
                        <label class="checkbox inline">
                            <input type="checkbox" id="isRecommend" name="isRecommend" value="2" <?= (isset($article['is_recommend']) && $article['is_recommend']) ? 'checked="checked"' : '' ?> /> 推荐
                            <!--<@checkbox name="isRecommend" value="${(article.isRecommend)!false}" /> 推荐-->
                        </label>
                        <label class="checkbox inline">
                            <input type="checkbox" id="isTop" name="isTop" value="3" <?= (isset($article['is_top']) && $article['is_top']) ? 'checked="checked"' : '' ?> /> 置顶
                            <!--<@checkbox name="isTop" value="${(article.isTop)!false}" /> 置顶-->
                        </label>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">跳转</label>
                    <div class="controls">
                        <input type="text" id="linkUrl" name="link_url" class="input-xlarge" value="<?= !empty($article['link_url']) ? $article['link_url'] : '' ?>"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="textarea">摘要</label>
                    <div class="controls">
              <textarea id="textarea" name="minContent" rows="3" ><?= !empty($article['min_content']) ? $article['min_content'] : '' ?>
</textarea>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="textarea"><span class="must-input">*</span>内容</label>
                    <div class="controls">
              <textarea id="content" name="content" rows="20"><?= !empty($article['content']) ? $article['content'] : '' ?>
</textarea>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="textarea">页面关键词</label>
                    <div class="controls">
              <textarea id="textarea" name="metaKeywords" rows="3" ><?= !empty($article['meta_keywords']) ? $article['meta_keywords'] : '' ?>
</textarea>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="textarea">页面描述</label>
                    <div class="controls">
              <textarea id="textarea" name="metaDescription" rows="6" ><?= !empty($article['meta_description']) ? $article['meta_description'] : '' ?>
</textarea>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>创建日期</label>
                    <div class="controls">
                        <input type="text" id="createDate" name="createDatex" class="span2" value="<?= !empty($article['createdatea']) ? $article['createdatea'] : '' ?>" title="请输入标识,只允许输入字母或数字!"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>修改日期</label>
                    <div class="controls">
                        <input type="text" id="modifyDate" name="modifyDatex" class="span2" value="<?= !empty($article['modifydatea']) ? $article['modifydatea'] : '' ?>" title="请输入标识,只允许输入字母或数字!"/>
                    </div>
                </div>
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary"><i class="icon-upload"></i> 提交</button>
                    <button type="reset" class="btn" onclick="javascript:history.go(-1);"><i class="icon-repeat"></i> 返回</button>
                </div>
            </fieldset>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
    $().ready(function() {
        var $validateForm = $("#validateForm");

        // 表单验证
        $validateForm.validate({
            rules: {
                title: "required",
                article_category_id: "required",
                image_path:"imageFile",
                content: "required",
                linkUrl:{
                    url: true,
                }
            },
            messages: {
                title: "请填写文章标题!",
                article_category_id: "请选择文章分类!",
                content: "请填写文章内容",
                image_path:"图片格式错误!"
            }
        });

    })
</script>
</html>