Fix several submit bugs

parent d887c978
......@@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport'>
<meta name="referrer" content="same-origin">
<meta name="referrer" content="strict-origin-when-cross-origin">
<link rel="preload" as="font" href="/pub/css/fonts/OpenSans-Regular.ttf">
<@css materialize.min.css %>
<@js materialize.min.js %>
......@@ -32,7 +32,7 @@
<div id="dashboard_content" class="center">
<iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals"
onload="resize_iframe(this)" id="dashboard_sandbox" src="dashboard/cards" referrerpolicy="same-origin"
onload="resize_iframe(this)" id="dashboard_sandbox" src="dashboard/cards" referrerpolicy="strict-origin-when-cross-origin"
style="border:0">
</iframe>
</div>
......
......@@ -103,8 +103,8 @@
</span>
</div>
<div id="editor-container" style="height:450px;"></div>
<button id="submit-button" class="btn blue darken-2 article-buttons" onclick="edit_submit()">Submit</button>
<button class="btn blue darken-2 article-buttons" onclick="cancel_edit()">Cancel</button>
<button type="button" id="submit-button" class="btn blue darken-2 article-buttons" onclick="edit_submit()">Submit</button>
<button type="button" class="btn blue darken-2 article-buttons" onclick="cancel_edit()">Cancel</button>
</div>
</div>
</div>
......
......@@ -8,7 +8,7 @@
<meta name="language" content="english">
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="referrer" content="same-origin">
<meta name="referrer" content="strict-origin-when-cross-origin">
<@css materialize.min.css %>
<@css blog.css %>
<@css custom-blue-theme.css %>
......
......@@ -98,7 +98,7 @@
</div>
<div id="editor-container"></div>
</div>
<button class="btn blue darken-2 article-buttons" onclick="submit_post()" id="submit-button">Submit</button>
<button type="button" class="btn blue darken-2 article-buttons" onclick="submit_post()" id="submit-button">Submit</button>
</div>
</body>
<@js editor.js %>
......
......@@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport'>
<meta name="referrer" content="same-origin">
<meta name="referrer" content="strict-origin-when-cross-origin">
<link rel="preload" as="font" href="/pub/css/fonts/OpenSans-Regular.ttf">
<@css materialize.min.css %>
<@js materialize.min.js %>
......@@ -69,8 +69,8 @@
</div>
<div class="card-action left-align">
<button type="reset" onclick="reset_settings()" class="waves-effect waves-blue blue-text btn-flat">reset</button>
<button type="submit" onclick="save_settings()" class="waves-effect waves-blue blue-text btn-flat">save</button>
<button type="button" onclick="reset_settings()" class="waves-effect waves-blue blue-text btn-flat">reset</button>
<button type="button" onclick="save_settings()" class="waves-effect waves-blue blue-text btn-flat">save</button>
</div>
</div>
</form>
......
......@@ -7,11 +7,11 @@
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport'>
<meta name="referrer" content="same-origin">
<meta name="referrer" content="strict-origin-when-cross-origin">
<link rel="preload" as="font" href="/pub/css/fonts/OpenSans-Regular.ttf">
<@css materialize.min.css %>
<@css blog.css %>
<@js jquery-3.3.1.min.js %>
<@js jquery-3.4.1.min.js %>
<@js materialize.min.js %>
<@js highlight.pack.js %>
<link rel="alternate" type="application/rss+xml" href="/feed/atom" />
......
......@@ -33,15 +33,17 @@ document.addEventListener('DOMContentLoaded', function() {
});
function try_to_load_page_with_auth(url) {
let status = fetch(url, { method: 'head' })
.then(response => { return response.status; });
if (401 == status) {
window.location.pathname = "/dashboard/login";
} else {
let dc = document.getElementById('dashboard_sandbox');
dc.src = url;
}
fetch(url, { method:'head' })
.then(response => { return response.status; })
.then(status => {
if (401 == status) {
window.location.pathname = "/dashboard/login";
} else {
let dc = document.getElementById('dashboard_sandbox');
dc.src = url;
}
})
.catch(error => alert(error));
}
function show_upload_button(e){
......@@ -116,7 +118,7 @@ function show_intro_page() {
}
function reset_settings() {
document.location.reload();
window.location.href = window.location.href;
}
function save_settings() {
......@@ -126,7 +128,7 @@ function save_settings() {
fetch('/v1/colt/change_setting', {
method: 'POST',
body: qstr
body: qstr,
})
.then(response => response.json())
.then(json => {
......@@ -139,5 +141,6 @@ function save_settings() {
alert(json.reason);
reset_settings();
}
});
})
.catch(error => console.log(error));
}
/*
@licstart The following is the entire license notice for the
JavaScript code in this page.
@licstart The following is the entire license notice for the
JavaScript code in this page.
Copyright (C) 2019 Mu Lei known as NalaGinrut <mulei@gnu.org>
Copyright (C) 2019 Mu Lei known as NalaGinrut <mulei@gnu.org>
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this page.
*/
@licend The above is the entire license notice
for the JavaScript code in this page.
*/
var children_nodes;
var quill;
var url_name;
......@@ -169,37 +169,37 @@ function edit_submit() {
// Quill will embed redundnat <br> which breaks XML validation, we fix it here.
article_content.replace("<p><br></p>", "");
$(document).ready(function () {
$.ajax({
type: "POST",
url: "/v1/colt/edit_article",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
"title": title,
"name": url_name,
"content": article_content,
"status": status,
"oid": article_oid,
"tags": tags,
"update_timestamp": update_timestamp.checked
}),
success: function (oid) {
if ("failed" === oid)
{
show_msg_layer("Edit failed, please check!");
submit_button.innerText = "Submit";
submit_button.disabled = false;
}
else if (typeof title == 'undefined')
window.location.pathname = "/about";
else
window.location.pathname = "/article/preview/oid/" + oid;
localStorage.setItem('colt.saved_content', "");
fetch('/v1/colt/edit_article', {
method: 'POST',
body: JSON.stringify({
"title": title,
"name": url_name,
"content": article_content,
"status": status,
"oid": article_oid,
"tags": tags,
"update_timestamp": update_timestamp.checked
}),
headers: {
'Content-Type': 'application/json; charset=utf-8'
}})
.then(response => response.text())
.then(oid => {
if ("failed" === oid)
{
show_msg_layer("Edit failed, please check!");
submit_button.innerText = "Submit";
submit_button.disabled = false;
}
else if (typeof title == 'undefined')
window.location.pathname = "/about";
else
window.location.pathname = "/article/preview/oid/" + oid;
localStorage.setItem('colt.saved_content', "");
})
})
.catch(error => alert(error));
}
function submit_post() {
......@@ -218,37 +218,37 @@ function submit_post() {
// Quill will embed redundnat <br> which breaks XML validation, we fix it here.
article_content.replace("<p><br></p>", "");
$(document).ready(function () {
$.ajax({
type: "POST",
url: "/v1/colt/post_article",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
"name": url_name,
"author": author,
"title": title,
"tags": tags,
"status": status,
"content": article_content,
}),
success: function (oid) {
if ("failed" === oid)
{
show_msg_layer("Post new article failed, please check!");
return;
}
fetch('/v1/colt/post_article', {
method: 'POST',
body: JSON.stringify({
"name": url_name,
"author": author,
"title": title,
"tags": tags,
"status": status,
"content": article_content,
}),
headers: {
'Content-Type': 'application/json; charset=utf-8'
}})
.then(response => response.text())
.then(oid => {
alert(oid);
if ("failed" === oid)
{
show_msg_layer("Post new article failed, please check!");
return;
}
if ("_____colt_____Intro" === title)
window.location.pathname = "/about";
else
window.location.pathname = "/article/preview/oid/" + oid;
if ("_____colt_____Intro" === title)
window.location.pathname = "/about";
else
window.location.pathname = "/article/preview/oid/" + oid;
// We shouldn't clean the saved content before it submitted successfully
localStorage.setItem('colt.saved_content', "");
}
// We shouldn't clean the saved content before it submitted successfully
localStorage.setItem('colt.saved_content', "");
})
})
.catch(error => alert(error));
}
var mmr;
......@@ -269,25 +269,27 @@ function delete_post(obj) {
delete_button.innerText = "Deleting...";
delete_button.disabled = true;
$(document).ready(function () {
$.ajax({
type: "POST",
url: "/v1/colt/remove_article",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
"title": article_title,
"content": article_content,
"oid": article_oid
}),
success: function (data) {
if ("ok" === data)
location.reload();
else
show_msg_layer("Delete failed, please check!");
}
fetch('/v1/colt/remove_article', {
method: 'POST',
body: JSON.stringify({
"title": article_title,
"content": article_content,
"oid": article_oid
}),
headers: {
'Content-Type': 'application/json; charset=utf-8'
}})
.then(response => response.text())
.then(status => {
if ("ok" === status)
location.reload();
else
show_msg_layer("Delete failed, please check!");
// We shouldn't clean the saved content before it submitted successfully
localStorage.setItem('colt.saved_content', "");
})
})
.catch(error => alert(error));
}
function init_intro_page() {
......
This diff is collapsed.
This diff is collapsed.
<div class="left-menu">
<ul>
<li><a <a href="/">Home</a></li>
<li><a href="/dashboard/new_post">Compose</a></li>
<li><a href="/dashboard/edit">Edit</a></li>
<li>Comments</li>
<li>Statistics</li>
</ul>
</div>
\ No newline at end of file
<div class="navbar-fixed">
<nav class="blue darken-2">
<div class="nav-wrapper container">
<a href="/" class="brand-logo"><i class="material-icons">
create
</i></a>
<a href="#" data-target="mobile-demo" class="sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<li><a href="/">Home</a></li>
<li><a href="/dashboard/new_post">Compose</a></li>
<li><a href="/dashboard/edit">Edit</a></li>
<li><a href="/dashboard/comments">Comments</a></li>
<li><a href="/dashboard/statistics">Statistics</a></li>
</ul>
</div>
</nav>
</div>
<ul class="sidenav" id="mobile-demo">
<li><a href="/">Home</a></li>
<li><a href="/dashboard/new_post">Compose</a></li>
<li><a href="/dashboard/edit">Edit</a></li>
<li><a href="/dashboard/comments">Comments</a></li>
<li><a href="/dashboard/statistics">Statistics</a></li>
</ul>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment