new page and draft
This commit is contained in:
parent
a5180135f6
commit
c39922d95d
|
@ -22,6 +22,14 @@ body.login {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
border-bottom: 1px solid #f0f0f0;
|
border-bottom: 1px solid #f0f0f0;
|
||||||
text-shadow: 2px 2px 3px rgba(255,255,255,0.1);
|
text-shadow: 2px 2px 3px rgba(255,255,255,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#toolbar .selected {
|
||||||
|
color: rgba(36, 122, 43, 0.77);
|
||||||
|
}
|
||||||
|
|
||||||
|
#draft-button,
|
||||||
|
#delete-button {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,13 +43,13 @@ div.editor-container {
|
||||||
background: #fdfdfd;
|
background: #fdfdfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TAGS */
|
/* SIDEBAR */
|
||||||
div.tags-list {
|
div.sidebar {
|
||||||
background: #333;
|
background: #333;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#currentTags li.list-group-item {
|
div.sidebar li.list-group-item {
|
||||||
background: none;
|
background: none;
|
||||||
color: #ccc;
|
color: #ccc;
|
||||||
border: none;
|
border: none;
|
||||||
|
@ -49,11 +57,11 @@ div.tags-list {
|
||||||
padding: 5px 15px;
|
padding: 5px 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#currentTags li.list-group-item:hover {
|
div.sidebar li.list-group-item:hover {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#currentTags li.tagSelected {
|
div.sidebar li.tagSelected {
|
||||||
background: #334E6A;
|
background: #334E6A;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<div id="toolbar" class="d-flex p-1">
|
<div id="toolbar" class="d-flex p-1">
|
||||||
<div id="message" class="mr-auto"></div>
|
<i class="align-self-center fa fa-terminal pr-1"></i>
|
||||||
<div class="pr-2">Draft</div>
|
<div id="message" class="mr-auto"></div>
|
||||||
<div>Delete</div>
|
<div id="draft-button" class="pr-2 selected">Draft</div>
|
||||||
|
<div id="delete-button" class="pr-2">Delete</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var _options = {
|
var _options = {
|
||||||
'alertTimeout': 5, // Second in dissapear the alert
|
'alertTimeout': 5, // Second in dissapear the alert
|
||||||
'autosaveTimeout': 5 // Second to activate before call the autosave
|
'autosaveTimeout': 3 // Second to activate before call the autosave
|
||||||
};
|
};
|
||||||
|
|
||||||
function showAlert(text) {
|
function showAlert(text) {
|
||||||
|
@ -24,7 +25,7 @@ var _key = null; // Current page key in the editor
|
||||||
var _tags = []; // Current tags from the content
|
var _tags = []; // Current tags from the content
|
||||||
var _content = ""; // Current content, this variable helps to know when the content was changed
|
var _content = ""; // Current content, this variable helps to know when the content was changed
|
||||||
var _autosaveTimer = null; // Timer object for the autosave
|
var _autosaveTimer = null; // Timer object for the autosave
|
||||||
|
var _draft = true;
|
||||||
|
|
||||||
function editorInitialize(content) {
|
function editorInitialize(content) {
|
||||||
_editor = new EasyMDE({
|
_editor = new EasyMDE({
|
||||||
|
@ -42,11 +43,6 @@ function editorInitialize(content) {
|
||||||
|
|
||||||
// Editor event change
|
// Editor event change
|
||||||
_editor.codemirror.on("change", function(){
|
_editor.codemirror.on("change", function(){
|
||||||
// If the content doesn't changed is not need to autosave
|
|
||||||
if (_content == editorGetContent()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset timer
|
// Reset timer
|
||||||
if (_autosaveTimer != null) {
|
if (_autosaveTimer != null) {
|
||||||
clearTimeout(_autosaveTimer);
|
clearTimeout(_autosaveTimer);
|
||||||
|
@ -54,22 +50,8 @@ function editorInitialize(content) {
|
||||||
|
|
||||||
// Activate timer
|
// Activate timer
|
||||||
_autosaveTimer = setTimeout(function() {
|
_autosaveTimer = setTimeout(function() {
|
||||||
log('Autosave running', '');
|
updatePage("Saved");
|
||||||
_content = editorGetContent();
|
}, _options["autosaveTimeout"]*1000);
|
||||||
var tags = parser.tags(_content);
|
|
||||||
var title = parser.title(_content);
|
|
||||||
var newContent = parser.removeFirstLine(_content);
|
|
||||||
|
|
||||||
// Update the page because was a change in the content
|
|
||||||
ajax.updatePage(_key, title, newContent, tags);
|
|
||||||
|
|
||||||
// Check if there are new tags in the editor
|
|
||||||
// If there are new tags get the new tags for the sidebar
|
|
||||||
if (JSON.stringify(_tags) != JSON.stringify(tags)) {
|
|
||||||
_tags = tags;
|
|
||||||
displayTags();
|
|
||||||
}
|
|
||||||
}, _options['autosaveTimeout']*1000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +59,30 @@ function editorGetContent() {
|
||||||
return _editor.value();
|
return _editor.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePage(alertMessage) {
|
||||||
|
log('Updating page...', '');
|
||||||
|
_content = editorGetContent();
|
||||||
|
var tags = parser.tags(_content);
|
||||||
|
var title = parser.title(_content);
|
||||||
|
var newContent = parser.removeFirstLine(_content);
|
||||||
|
|
||||||
|
// Update the page because was a change in the content
|
||||||
|
ajax.updatePage(_key, title, newContent, tags, _draft).then(function(key) {
|
||||||
|
_key = key;
|
||||||
|
showAlert(alertMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check if there are new tags in the editor
|
||||||
|
// If there are new tags get the new tags for the sidebar
|
||||||
|
if (JSON.stringify(_tags) != JSON.stringify(tags)) {
|
||||||
|
_tags = tags;
|
||||||
|
displayTags();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createPage() {
|
function createPage() {
|
||||||
|
// New pages is draft by default
|
||||||
|
setDraft(true);
|
||||||
let response = ajax.createPage();
|
let response = ajax.createPage();
|
||||||
response.then(function(key) {
|
response.then(function(key) {
|
||||||
// Log
|
// Log
|
||||||
|
@ -87,8 +92,32 @@ function createPage() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setDraft(value) {
|
||||||
|
let message = "";
|
||||||
|
if (value) {
|
||||||
|
_draft = true;
|
||||||
|
$("#draft-button").addClass("selected");
|
||||||
|
message = "Page saved as draft";
|
||||||
|
} else {
|
||||||
|
_draft = false;
|
||||||
|
$("#draft-button").removeClass("selected");
|
||||||
|
message = "Page published";
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePage(message);
|
||||||
|
}
|
||||||
|
|
||||||
// MAIN
|
// MAIN
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
// Click on draft button
|
||||||
|
$(document).on("click", "#draft-button", function() {
|
||||||
|
if (_draft) {
|
||||||
|
setDraft(false);
|
||||||
|
} else {
|
||||||
|
setDraft(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
showAlert("Welcome to Bludit");
|
showAlert("Welcome to Bludit");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<div class="tags-list col-lg-2 p-0 pt-4">
|
<div class="sidebar col-lg-2 p-0 pt-4">
|
||||||
<ul id="currentTags" class="list-group list-group-flush">
|
<ul id="menu" class="list-group list-group-flush">
|
||||||
|
<li id="newPage" class="list-group-item" data-action="untagged"><i class="fa fa-edit"></i> New page</li>
|
||||||
|
</ul>
|
||||||
|
<ul id="currentTags" class="list-group list-group-flush pt-4">
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
@ -53,6 +56,11 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Click on new page
|
||||||
|
$(document).on("click", "#newPage", function() {
|
||||||
|
createPage();
|
||||||
|
});
|
||||||
|
|
||||||
// Retrive and show the tags
|
// Retrive and show the tags
|
||||||
displayTags();
|
displayTags();
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,14 +22,15 @@ class Ajax {
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPage() {
|
async createPage() {
|
||||||
var url = this.apiURL+"pages";
|
let url = this.apiURL+"pages";
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
token: this.token,
|
token: this.token,
|
||||||
authentication: this.authentication
|
authentication: this.authentication,
|
||||||
|
type: "draft"
|
||||||
}),
|
}),
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
@ -44,9 +45,16 @@ class Ajax {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePage(key, title, content, tags) {
|
updatePage(key, title, content, tags, draft) {
|
||||||
log('this.updatePage()', key);
|
log('this.updatePage()', key);
|
||||||
var url = this.apiURL+"pages/"+key;
|
|
||||||
|
// Type
|
||||||
|
let type = "published";
|
||||||
|
if (draft) {
|
||||||
|
type = "draft";
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = this.apiURL+"pages/"+key
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
@ -55,7 +63,8 @@ class Ajax {
|
||||||
authentication: this.authentication,
|
authentication: this.authentication,
|
||||||
title: title,
|
title: title,
|
||||||
content: content,
|
content: content,
|
||||||
tags: tags
|
tags: tags,
|
||||||
|
type: type
|
||||||
}),
|
}),
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
@ -69,7 +78,7 @@ class Ajax {
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return false;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -304,7 +304,7 @@ function createPage($args) {
|
||||||
// Add to syslog
|
// Add to syslog
|
||||||
$syslog->add(array(
|
$syslog->add(array(
|
||||||
'dictionaryKey'=>'new-content-created',
|
'dictionaryKey'=>'new-content-created',
|
||||||
'notes'=>$args['title']
|
'notes'=>(empty($args['title'])?$key:$args['title'])
|
||||||
));
|
));
|
||||||
|
|
||||||
Alert::set( $L->g('new-content-created') );
|
Alert::set( $L->g('new-content-created') );
|
||||||
|
|
Loading…
Reference in New Issue