<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/30/030
 * Time: 11:14
 */
?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
    <h4 class="modal-title">编辑公告/帮助</h4>
</div>
<form id="form" class="form-horizontal">
    <input type="hidden" name="id" value="<?= $notice['id'] ?>">
    <div class="modal-body">
        <div class="input-group">
            <span class="input-group-addon">类型</span>
            <select class="form-control" name="type">
                <option value="0" <?php if($notice['type']==0){ ?>selected="selected"<?php } ?>>会员公告</option>
                <option value="1" <?php if($notice['type']==1){ ?>selected="selected"<?php } ?>>代理商公告</option>
                <option value="2" <?php if($notice['type']==2){ ?>selected="selected"<?php } ?>>用户帮助中心</option>
                <option value="3" <?php if($notice['type']==3){ ?>selected="selected"<?php } ?>>代理帮助中心</option>
            </select>
        </div>

        <div class="hr-line-dashed"></div>
        <div class="input-group">
            <span class="input-group-addon">标题</span>
            <input name="title" type="text" class="form-control" placeholder="标题" value="<?= $notice['title'] ?>">
        </div>
        <div class="hr-line-dashed"></div>
        <div class="input-group">
            <span class="input-group-addon">内容</span>
            <textarea id="kindeditor" name="content" type="text" class="form-control"><?= isset($notice['content']) ? $notice['content'] : '' ?></textarea>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
        <button id="submit" type="button" class="btn btn-primary">提交</button>
    </div>
</form>

<script>
    KindEditor.ready(function(K) {});
</script>

<script type="text/javascript">

    var editor;
    KindEditor.ready(function(K) {
        editor=K.create('#kindeditor', {
            uploadJson: '/admin/kindeditor/upload',
            fileManagerJson: '/admin/kindeditor/file-manager',
            allowFileManager: true,
            //urlType: 'domain',
            width : '100%',
            height: '200px',
            items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'image','insertfile', 'link','source'],
        });
    });

    $("#submit").on("click",function(){
        editor.sync();
        $.ajax({
            type: "POST",
            url: "<?= \yii\helpers\Url::to(['/admin/notice/update']) ?>",
            data: $('#form').serialize(),
            dataType: "json",
            beforeSend: function() {},
            success: function(data) {
                if(data.code == 1){
                    $("#modal").modal("hide");
                    table.ajax.reload();
                }else{
                    toastr.error(data.message, "提示");
                }
            },
            complete: function(XMLHttpRequest, textStatus) {},
            error: function() {}
        });
    });

</script>

