Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <% this.title = article.id ? '编辑帖子' : '发表帖子'; %>
- <% include header %>
- <style type="text/css">
- .am-panel-title{
- font-size: 1.6em;
- }
- </style>
- <div class="padding">
- <div class="ui top attached tabular menu">
- <a class="item active" data-tab="edit">编辑</a>
- <a class="item" data-tab="preview" id="preview_tab">预览</a>
- </div>
- <div class="ui bottom attached tab segment active" data-tab="edit">
- <div class="ui form">
- <div class="field">
- <label for="title">标题</label>
- <input type="text" id="title" name="title" value="<%= article.title %>">
- </div>
- <!-- <div class="field">
- <label for="content">内容</label>
- <textarea rows="15" id="content" name="content" class="markdown-edit"><%= article.content %></textarea>
- </div> -->
- <!-- 测试开始 -->
- <div class="field">
- <label>内容</label>
- <textarea id='tmp' style="display: none;"><%= article.content %></textarea>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/markdown-palettes@0.4.13/dist/markdown-palettes.css">
- <script src="https://cdn.jsdelivr.net/npm/markdown-palettes@0.4.13/dist/markdown-palettes.min.js"></script>
- <div id="editor-container" style="height: 700px;">
- <div id="editor"></div>
- </div>
- </div>
- <!-- 测试结束 -->
- </div>
- <% if (user && user.is_admin) { %>
- <div class="ui <% if (article.is_notice) { %>checked <% } %>checkbox" style="margin-top: 15px; ">
- <input <% if (article.is_notice) { %>checked=""<% } %> name="is_notice" type="checkbox">
- <label><strong>公告</strong></label>
- <p style="margin-top: 5px; ">选择后将显示在首页公告栏。</p>
- </div>
- <% } %>
- </div>
- <div class="ui bottom attached tab segment" data-tab="preview">
- <div class="ui header" id="pv-title"></div>
- <div id="pv-content" class="font-content"></div>
- </div>
- <div style="text-align: center; ">
- <!-- <button id="submit_button" type="submit" class="ui labeled submit icon button">
- <i class="icon edit"></i> 提交
- </button> -->
- <button id="submit_button" class="ui labeled submit icon button" onclick="javascript:submit(<%= article.id %>)">
- <i class="icon edit"></i> 发布文章
- </button>
- </div>
- </div>
- <script type="text/javascript">
- var markdownEditor = new MarkdownPalettes("#editor");
- markdownEditor.content = $('#tmp').val();
- function submit(id) {
- console.log("1111");
- console.log("1111");
- console.log("1111");
- console.log("1111");
- console.log("1111");
- console.log("1111");
- $.ajax({
- url: `/article/${id}/edit`,
- type: 'POST',
- data: {
- 'title': $('#title').val(),
- 'content': markdownEditor.content,
- 'is_notice': ($('#is_notice').is(':checked') ? "on" : "off")
- },
- async: true,
- success: function (data) {
- error_code = data.error_code;
- switch (error_code) {
- case 4001:
- show_error("请登录后继续。");
- break;
- case 4002:
- show_error("无此版块。");
- break;
- case 4003:
- show_error("无此题目。");
- break;
- case 4004:
- show_error("您没有权限进行此操作。");
- break;
- case 4005:
- show_error("标题名不能为空。");
- break;
- case 4006:
- show_error("无效的比赛ID。");
- break;
- case 1:
- success(data.article_id);
- return;
- default:
- show_error("未知错误。错误代码 " + error_code);
- break;
- }
- },
- error: show_error("未知错误")
- });
- }
- function show_error(error) {
- swal({
- title: "文章发布失败。",
- icon: "error",
- text: error
- });
- }
- function success(id) {
- swal({
- title: "文章发布成功!",
- icon: "success"
- }).then(function () {
- window.location.href = location.protocol + '//' + location.host + '/article/' + id;
- });
- }
- </script>
- <% include footer %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement