Autosave and preview improves

This commit is contained in:
Diego Najar 2019-05-10 11:35:23 +02:00
parent de2cfeb66e
commit 18778226eb
5 changed files with 25 additions and 29 deletions

View File

@ -400,8 +400,8 @@ $(document).ready(function() {
var title = $("#jstitle").val();
var content = editorGetContent();
var ajax = new bluditAjax();
bluditAjax.preview(uuid, title, content).then(function(data) {
window.open("<?php echo DOMAIN_PAGES.'autosave-'.$uuid.'?preview='.md5('autosave-'.$uuid) ?>", "_blank");
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
window.open("<?php echo DOMAIN_PAGES.'autosave-'.$page->uuid().'?preview='.md5('autosave-'.$page->uuid()) ?>", "_blank");
});
});
@ -435,19 +435,21 @@ $(document).ready(function() {
});
// Autosave
// Autosave works when the content of the page is bigger than 100 characters
var currentContent = editorGetContent();
setInterval(function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
var content = editorGetContent();
var ajax = new bluditAjax();
// Call autosave only when the user change the content
// Autosave when content has at least 100 characters
if (content.length<100) {
return false;
}
// Autosave only when the user change the content
if (currentContent!=content) {
currentContent = content;
bluditAjax.autosave(uuid, title, content).then(function(data) {
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
if (data.status==0) {
showAlert("Autosave success");
showAlert("<?php $L->p('Autosave') ?>");
}
});
}

View File

@ -349,7 +349,7 @@ $(document).ready(function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var content = editorGetContent();
bluditAjax.preview(uuid, title, content).then(function(data) {
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
window.open("<?php echo DOMAIN_PAGES.'autosave-'.$uuid.'?preview='.md5('autosave-'.$uuid) ?>", "_blank");
});
});
@ -372,18 +372,21 @@ $(document).ready(function() {
});
// Autosave
// Autosave works when the content of the page is bigger than 100 characters
var currentContent = editorGetContent();
setInterval(function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
var content = editorGetContent();
// Call autosave only when the user change the content
// Autosave when content has at least 100 characters
if (content.length<100) {
return false;
}
// Autosave only when the user change the content
if (currentContent!=content) {
currentContent = content;
bluditAjax.autosave(uuid, title, content).then(function(data) {
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
if (data.status==0) {
showAlert("Autosave success");
showAlert("<?php $L->p('Autosave') ?>");
}
});
}

View File

@ -2,7 +2,7 @@
header('Content-Type: application/json');
/*
| Create/Edit a page and save as draft
| Create/edit a page and save as draft
| If the UUID already exists the page is updated
|
| @_POST['title'] string Page title
@ -36,7 +36,7 @@ $page = array(
// Get the page key by the UUID
$pageKey = $pages->getByUUID($uuid);
// if pageKey is empty means the autosave page doesn't exist
// if pageKey is empty means the page doesn't exist
if (empty($pageKey)) {
createPage($page);
} else {

View File

@ -314,7 +314,6 @@ function createPage($args) {
'notes'=>(empty($args['title'])?$key:$args['title'])
));
Alert::set( $L->g('new-content-created') );
return $key;
}

View File

@ -1,6 +1,6 @@
class bluditAjax {
static async preview(uuid, title, content) {
static async saveAsDraft(uuid, title, content) {
let url = HTML_PATH_ADMIN_ROOT+"ajax/save-as-draft"
try {
const response = await fetch(url, {
@ -25,13 +25,8 @@ class bluditAjax {
}
}
// Autosave works only when the content has more than 100 characters
static async autosave(uuid, title, content) {
if ((content.length<100)) {
return false;
}
let url = HTML_PATH_ADMIN_ROOT+"ajax/save-as-draft"
static async removeLogo() {
let url = HTML_PATH_ADMIN_ROOT+"ajax/remove-logo"
try {
const response = await fetch(url, {
credentials: 'same-origin',
@ -40,10 +35,7 @@ class bluditAjax {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}),
body: new URLSearchParams({
'tokenCSRF': tokenCSRF,
'uuid': "autosave-" + uuid,
'title': title+" [Autosave]",
'content': content
'tokenCSRF': tokenCSRF
}),
});
const json = await response.json();