Improve function preview #1438
This commit is contained in:
parent
22bd590cf5
commit
16bb662cce
5 changed files with 31 additions and 23 deletions
|
@ -15,10 +15,14 @@ checkRole(array('admin', 'editor', 'author'));
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
$pageKey = false;
|
$pageKey = false;
|
||||||
|
$pageUUID = false;
|
||||||
|
$pagePreviewID = false;
|
||||||
if (!empty($layout['parameters'])) {
|
if (!empty($layout['parameters'])) {
|
||||||
try {
|
try {
|
||||||
$pageKey = $layout['parameters'];
|
$pageKey = $layout['parameters'];
|
||||||
$page = new Page($pageKey);
|
$page = new Page($pageKey);
|
||||||
|
$pageUUID = $page->uuid();
|
||||||
|
$pagePreviewID = $page->previewID();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::set(__METHOD__.LOG_SEP.'An error occurred while trying to get the page: '.$pageKey, LOG_TYPE_ERROR);
|
Log::set(__METHOD__.LOG_SEP.'An error occurred while trying to get the page: '.$pageKey, LOG_TYPE_ERROR);
|
||||||
Redirect::page('content');
|
Redirect::page('content');
|
||||||
|
|
|
@ -5,18 +5,23 @@
|
||||||
// Variables for the view
|
// Variables for the view
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
var _pageKey = <?php echo $pageKey ? '"' . $pageKey . '"' : 'null' ?>;
|
var _pageKey = <?php echo $pageKey ? '"' . $pageKey . '"' : 'null' ?>;
|
||||||
|
var _pageUUID = <?php echo $pageUUID ? '"' . $pageUUID . '"' : 'null' ?>;
|
||||||
|
var _pagePreviewID = <?php echo $pagePreviewID ? '"' . $pagePreviewID . '"' : 'null' ?>;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Functions for the view
|
// Functions for the view
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// Default function for the editor
|
// Default function for get the content inside the textarea from the Editor
|
||||||
// These functions work if the user does not activate any plugin
|
// This function is enable only when the user doesn't define a plugin as Editor
|
||||||
if (typeof editorGetContent != 'function') {
|
if (typeof editorGetContent != 'function') {
|
||||||
window.editorGetContent = function() {
|
window.editorGetContent = function() {
|
||||||
return $('#editor').val();
|
return $('#editor').val();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default function for insert content inside the textarea from the Editor
|
||||||
|
// This function is enable only when the user doesn't define a plugin as Editor
|
||||||
if (typeof editorInsertContent != 'function') {
|
if (typeof editorInsertContent != 'function') {
|
||||||
window.editorInsertContent = function(content, type = '') {
|
window.editorInsertContent = function(content, type = '') {
|
||||||
if (type == 'image') {
|
if (type == 'image') {
|
||||||
|
@ -28,8 +33,10 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the a page
|
// Create a new page
|
||||||
// This function set the global variable "_pageKey"
|
// This function set the global variable "_pageKey"
|
||||||
|
// This function set the global variable "_pageUUID"
|
||||||
|
// This function set the global variable "_pagePreviewID"
|
||||||
function createPage() {
|
function createPage() {
|
||||||
logs('Creating page.');
|
logs('Creating page.');
|
||||||
api.createPage().then(function(response) {
|
api.createPage().then(function(response) {
|
||||||
|
@ -37,8 +44,8 @@
|
||||||
logs('Page created. Key: ' + response.data.key);
|
logs('Page created. Key: ' + response.data.key);
|
||||||
// Set the global variable with the page key
|
// Set the global variable with the page key
|
||||||
_pageKey = response.data.key;
|
_pageKey = response.data.key;
|
||||||
// Set Friendly URL
|
_pageUUID = response.data.uuid;
|
||||||
//$('#friendlyURL').val(response.data.key);
|
_pagePreviewID = response.data.previewID;
|
||||||
// Get current files
|
// Get current files
|
||||||
fmGetFiles();
|
fmGetFiles();
|
||||||
} else {
|
} else {
|
||||||
|
@ -51,7 +58,7 @@
|
||||||
|
|
||||||
// Set the page in the editor
|
// Set the page in the editor
|
||||||
function setPage() {
|
function setPage() {
|
||||||
logs('Setting up the page');
|
logs('Setting up the page.');
|
||||||
// Get current files
|
// Get current files
|
||||||
fmGetFiles();
|
fmGetFiles();
|
||||||
return true;
|
return true;
|
||||||
|
@ -60,7 +67,7 @@
|
||||||
// Save the current page
|
// Save the current page
|
||||||
// This function set the global variable "_pageKey"
|
// This function set the global variable "_pageKey"
|
||||||
function savePage(args = []) {
|
function savePage(args = []) {
|
||||||
console.log(_pageKey);
|
console.log('Saving page. Key: ' + _pageKey);
|
||||||
if (_pageKey == null) {
|
if (_pageKey == null) {
|
||||||
logs('Error, page not created.');
|
logs('Error, page not created.');
|
||||||
showAlertError("Error, page not created.");
|
showAlertError("Error, page not created.");
|
||||||
|
@ -75,12 +82,6 @@
|
||||||
// Set the global variable with the page key
|
// Set the global variable with the page key
|
||||||
// The page key can change after save the page so you need to set again the variable
|
// The page key can change after save the page so you need to set again the variable
|
||||||
_pageKey = response.data.key;
|
_pageKey = response.data.key;
|
||||||
// Set friendly URL with the key
|
|
||||||
//$('#friendlyURL').val(response.data.key);
|
|
||||||
$('#btnPreview').attr('data-key', response.data.key);
|
|
||||||
if (response.data.preview) {
|
|
||||||
$('#btnPreview').attr('data-preview', response.data.preview);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logs('An error occurred while trying to save the current page.');
|
logs('An error occurred while trying to save the current page.');
|
||||||
showAlertError(response.message);
|
showAlertError(response.message);
|
||||||
|
@ -233,9 +234,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#btnPreview').click(function() {
|
$('#btnPreview').click(function() {
|
||||||
if ($(this).attr('data-key') && $(this).attr('data-preview')) {
|
window.open(DOMAIN_PAGES + _pageKey + '?preview=' + _pagePreviewID);
|
||||||
window.open('<?php echo DOMAIN_PAGES; ?>'+$(this).attr('data-key')+'?preview='+$(this).attr('data-preview'));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#category').on("change", function() {
|
$('#category').on("change", function() {
|
||||||
|
|
|
@ -762,7 +762,7 @@ function buildThePage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($page->draft() || $page->scheduled() || $page->autosave()) {
|
if ($page->draft() || $page->scheduled() || $page->autosave()) {
|
||||||
if ($url->parameter('preview')!==md5($page->uuid())) {
|
if ($url->parameter('preview')!==$page->previewID()) {
|
||||||
$url->setNotFound();
|
$url->setNotFound();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,6 +370,11 @@ class Page {
|
||||||
return $this->getValue('uuid');
|
return $this->getValue('uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function previewID()
|
||||||
|
{
|
||||||
|
return md5($this->getValue('uuid'));
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the field key
|
// Returns the field key
|
||||||
public function key()
|
public function key()
|
||||||
{
|
{
|
||||||
|
|
|
@ -526,10 +526,13 @@ class pluginAPI extends Plugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the current page to get the uuid and the previewID
|
||||||
|
$page = new Page($key);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'status'=>'0',
|
'status'=>'0',
|
||||||
'message'=>'Page created.',
|
'message'=>'Page created.',
|
||||||
'data'=>array('key'=>$key)
|
'data'=>array('key'=>$key, 'uuid'=>$page->uuid(), 'previewID'=>$page->previewID())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,13 +552,10 @@ class pluginAPI extends Plugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = new Page($newKey);
|
|
||||||
$preview = md5($page->uuid());
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'status'=>'0',
|
'status'=>'0',
|
||||||
'message'=>'Page edited.',
|
'message'=>'Page edited.',
|
||||||
'data'=>array('key'=>$newKey, 'preview'=>$preview)
|
'data'=>array('key'=>$newKey)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue