diff --git a/bl-kernel/admin/views/edit-content.php b/bl-kernel/admin/views/edit-content.php index 7977aae8..7e3a8047 100644 --- a/bl-kernel/admin/views/edit-content.php +++ b/bl-kernel/admin/views/edit-content.php @@ -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("", "_blank"); + bluditAjax.saveAsDraft(uuid, title, content).then(function(data) { + window.open("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() + "[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("p('Autosave') ?>"); } }); } diff --git a/bl-kernel/admin/views/new-content.php b/bl-kernel/admin/views/new-content.php index 3ff92b04..3a0aa372 100644 --- a/bl-kernel/admin/views/new-content.php +++ b/bl-kernel/admin/views/new-content.php @@ -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("", "_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() + "[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("p('Autosave') ?>"); } }); } diff --git a/bl-kernel/ajax/save-as-draft.php b/bl-kernel/ajax/save-as-draft.php index 39b6d301..d2a3b440 100644 --- a/bl-kernel/ajax/save-as-draft.php +++ b/bl-kernel/ajax/save-as-draft.php @@ -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 { diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 5b328560..3de2d6bc 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -314,7 +314,6 @@ function createPage($args) { 'notes'=>(empty($args['title'])?$key:$args['title']) )); - Alert::set( $L->g('new-content-created') ); return $key; } diff --git a/bl-kernel/js/bludit-ajax.php b/bl-kernel/js/bludit-ajax.php index 5158ca41..851e3c6b 100644 --- a/bl-kernel/js/bludit-ajax.php +++ b/bl-kernel/js/bludit-ajax.php @@ -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();