Add submit button

This commit is contained in:
Tim Van Baak 2020-03-30 23:58:05 -07:00
parent e19a2a5b26
commit aa4b94d0c1
2 changed files with 31 additions and 10 deletions

View File

@ -46,18 +46,33 @@ function update(article) {
req.responseType = "json";
req.onreadystatechange = function () {
if (req.readyState == 4 && req.status == 200) {
// Update internal state with the returned article object
params.article = req.response.article;
var title = document.getElementById("editor-title").value;
var previewHtml = "<h1>" + title + "</h1>\n" + req.response.info.rendered;
document.getElementById("preview").innerHTML = previewHtml;
document.getElementById("preview-control").innerHTML = req.response.info.word_count;
// Set editor editability based on article status
updateEditorStatus();
// Update the preview with the parse information
updatePreview(req.response.info);
}
};
var payload = { article: article };
req.send(JSON.stringify(payload));
}
function updateEditorStatus() {
var ready = !!params.article.status.ready
document.getElementById("editor-title").disabled = ready;
document.getElementById("editor-content").disabled = ready;
var submitButton = document.getElementById("button-submit");
submitButton.innerText = ready ? "Edit article" : "Submit article";
}
function updatePreview(info) {
var title = document.getElementById("editor-title").value;
var previewHtml = "<h1>" + title + "</h1>\n" + info.rendered;
document.getElementById("preview").innerHTML = previewHtml;
document.getElementById("preview-control").innerHTML = info.word_count;
}
function onContentChange(timeout=2000) {
ifNoFurtherChanges(() => {
var article = buildArticleObject();
@ -65,6 +80,14 @@ function onContentChange(timeout=2000) {
}, timeout);
}
function submitArticle() {
ifNoFurtherChanges(() => {
params.article.status.ready = !params.article.status.ready;
var article = buildArticleObject();
update(article);
}, 0);
}
window.addEventListener("beforeunload", function(e) {
var content = document.getElementById("editor-content").value
var hasText = content.length > 0 && content != params.article.contents;

View File

@ -34,11 +34,9 @@
<a href="{{ url_for('lexicon.session', name=g.lexicon.name) }}">
{{ g.lexicon.title }}
</a>
<!-- <select id="editor-character">
{% for char in g.lexicon.get_characters_for_player(current_user.id) %}
<option value="{{ char.cid }}">{{ char.name }}</option>
{% endfor %}
</select> -->
{% if article %}
<button id="button-submit" onclick="submitArticle()">Submit article</button>
{% endif %}
<span>
<b>
{% if character %}