Feature page preview and switch button for publish and draft

This commit is contained in:
Diego Najar 2019-04-27 20:30:57 +02:00
parent 3fa5a420c2
commit 3066c091d2
6 changed files with 30 additions and 15 deletions

View File

@ -45,9 +45,6 @@ if (IMAGE_RESTRICT) {
define('PAGE_THUMBNAILS_DIRECTORY', PATH_UPLOADS_PAGES.PAGE_IMAGES_KEY.DS.'thumbnails'.DS); define('PAGE_THUMBNAILS_DIRECTORY', PATH_UPLOADS_PAGES.PAGE_IMAGES_KEY.DS.'thumbnails'.DS);
define('PAGE_THUMBNAILS_HTML', HTML_PATH_UPLOADS_PAGES.PAGE_IMAGES_KEY.'/thumbnails/'); define('PAGE_THUMBNAILS_HTML', HTML_PATH_UPLOADS_PAGES.PAGE_IMAGES_KEY.'/thumbnails/');
define('PAGE_THUMBNAILS_URL', DOMAIN_UPLOADS_PAGES.PAGE_IMAGES_KEY.'/thumbnails/'); define('PAGE_THUMBNAILS_URL', DOMAIN_UPLOADS_PAGES.PAGE_IMAGES_KEY.'/thumbnails/');
// Create the directory to store the images
Filesystem::mkdir(PAGE_THUMBNAILS_DIRECTORY, true);
} else { } else {
define('PAGE_IMAGES_DIRECTORY', (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS)); define('PAGE_IMAGES_DIRECTORY', (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS));
define('PAGE_IMAGES_URL', (IMAGE_RELATIVE_TO_ABSOLUTE? '' : DOMAIN_UPLOADS)); define('PAGE_IMAGES_URL', (IMAGE_RELATIVE_TO_ABSOLUTE? '' : DOMAIN_UPLOADS));

View File

@ -61,7 +61,7 @@ echo Bootstrap::formOpen(array(
<div id="jseditorToolbarLeft"> <div id="jseditorToolbarLeft">
<button type="button" class="btn btn-sm btn-primary" id="jsbuttonSave"><?php echo $L->g('Save') ?></button> <button type="button" class="btn btn-sm btn-primary" id="jsbuttonSave"><?php echo $L->g('Save') ?></button>
<button type="button" class="btn btn-sm btn-secondary" id="jsbuttonSave"><?php $L->p('Discard') ?></button> <button id="jsbuttonPreview" type="button" class="btn btn-sm btn-secondary"><?php $L->p('Preview') ?></button>
<span id="jsswitchButton" data-switch="<?php echo ($page->draft()?'draft':'publish') ?>" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-<?php echo ($page->draft()?'draft':'publish') ?>"></i> <?php echo ($page->draft()?$L->g('Draft'):$L->g('Publish')) ?></span> <span id="jsswitchButton" data-switch="<?php echo ($page->draft()?'draft':'publish') ?>" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-<?php echo ($page->draft()?'draft':'publish') ?>"></i> <?php echo ($page->draft()?$L->g('Draft'):$L->g('Publish')) ?></span>
</div> </div>
@ -394,6 +394,16 @@ $(document).ready(function() {
} }
}); });
// Button preview
$("#jsbuttonPreview").on("click", function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var content = editorGetContent();
var ajax = new bluditAjax();
ajax.autosave(uuid, title, content, false);
window.open("<?php echo DOMAIN_PAGES.'autosave-'.$page->uuid().'?preview='.md5('autosave-'.$page->uuid()) ?>", "_blank");
});
// Button Save // Button Save
$("#jsbuttonSave").on("click", function() { $("#jsbuttonSave").on("click", function() {
// If the switch is setted to "published", get the value from the selector // If the switch is setted to "published", get the value from the selector

View File

@ -54,9 +54,9 @@ echo Bootstrap::formOpen(array(
</div> </div>
<div id="jseditorToolbarLeft"> <div id="jseditorToolbarLeft">
<button type="button" class="btn btn-sm btn-primary" id="jsbuttonSave"><?php $L->p('Save') ?></button> <button id="jsbuttonSave" type="button" class="btn btn-sm btn-primary" ><?php $L->p('Save') ?></button>
<button type="button" class="btn btn-sm btn-secondary" id="jsbuttonSave"><?php $L->p('Discard') ?></button> <button id="jsbuttonPreview" type="button" class="btn btn-sm btn-secondary"><?php $L->p('Preview') ?></button>
<span id="jsswitchButton" data-switch="publish" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?></span> <span id="jsbuttonSwitch" data-switch="publish" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?></span>
</div> </div>
</div> </div>
<script> <script>
@ -334,7 +334,7 @@ $(document).ready(function() {
} }
// Button switch // Button switch
$("#jsswitchButton").on("click", function() { $("#jsbuttonSwitch").on("click", function() {
if ($(this).data("switch")=="publish") { if ($(this).data("switch")=="publish") {
$(this).html('<i class="fa fa-square switch-icon-draft"></i> <?php $L->p('Draft') ?>'); $(this).html('<i class="fa fa-square switch-icon-draft"></i> <?php $L->p('Draft') ?>');
$(this).data("switch", "draft"); $(this).data("switch", "draft");
@ -344,10 +344,20 @@ $(document).ready(function() {
} }
}); });
// Button preview
$("#jsbuttonPreview").on("click", function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var content = editorGetContent();
var ajax = new bluditAjax();
ajax.autosave(uuid, title, content, false);
window.open("<?php echo DOMAIN_PAGES.'autosave-'.$uuid.'?preview='.md5('autosave-'.$uuid) ?>", "_blank");
});
// Button Save // Button Save
$("#jsbuttonSave").on("click", function() { $("#jsbuttonSave").on("click", function() {
// If the switch is setted to "published", get the value from the selector // If the switch is setted to "published", get the value from the selector
if ($("#jsswitchButton").data("switch")=="publish") { if ($("#jsbuttonSwitch").data("switch")=="publish") {
var value = $("#jstypeSelector option:selected").val(); var value = $("#jstypeSelector option:selected").val();
$("#jstype").val(value); $("#jstype").val(value);
} else { } else {

View File

@ -16,11 +16,6 @@ if (empty($uuid)) {
ajaxResponse(1, 'Autosave fail. UUID not defined.'); ajaxResponse(1, 'Autosave fail. UUID not defined.');
} }
// Check content length to create the autosave page
if (Text::length($content)<100) {
ajaxResponse(1, 'Autosave not completed. The content length is less than 100 characters.');
}
$autosaveUUID = 'autosave-'.$uuid; $autosaveUUID = 'autosave-'.$uuid;
$page = array( $page = array(
'uuid'=>$autosaveUUID, 'uuid'=>$autosaveUUID,

View File

@ -18,6 +18,9 @@ $uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
if ($uuid && IMAGE_RESTRICT) { if ($uuid && IMAGE_RESTRICT) {
$imageDirectory = PATH_UPLOADS_PAGES.$uuid.DS; $imageDirectory = PATH_UPLOADS_PAGES.$uuid.DS;
$thumbnailDirectory = $imageDirectory.'thumbnails'.DS; $thumbnailDirectory = $imageDirectory.'thumbnails'.DS;
if (!Filesystem::directoryExists($thumbnailDirectory)) {
Filesystem::mkdir($thumbnailDirectory, true);
}
} else { } else {
$imageDirectory = PATH_UPLOADS; $imageDirectory = PATH_UPLOADS;
$thumbnailDirectory = PATH_UPLOADS_THUMBNAILS; $thumbnailDirectory = PATH_UPLOADS_THUMBNAILS;

View File

@ -50,7 +50,7 @@ if ($pages->scheduler()) {
)); ));
} }
// Set home page if the user defined them // Set home page if the user defined one
if ($site->homepage() && $url->whereAmI()==='home') { if ($site->homepage() && $url->whereAmI()==='home') {
$pageKey = $site->homepage(); $pageKey = $site->homepage();
if ($pages->exists($pageKey)) { if ($pages->exists($pageKey)) {