Select parent page bug fix #1089
This commit is contained in:
parent
b86f317a2c
commit
c5977fc0cb
|
@ -14,12 +14,6 @@ echo Bootstrap::formOpen(array(
|
||||||
'value'=>$security->getTokenCSRF()
|
'value'=>$security->getTokenCSRF()
|
||||||
));
|
));
|
||||||
|
|
||||||
// Parent
|
|
||||||
echo Bootstrap::formInputHidden(array(
|
|
||||||
'name'=>'parent',
|
|
||||||
'value'=>$page->parent()
|
|
||||||
));
|
|
||||||
|
|
||||||
// UUID
|
// UUID
|
||||||
// The UUID is generated in the controller
|
// The UUID is generated in the controller
|
||||||
echo Bootstrap::formInputHidden(array(
|
echo Bootstrap::formInputHidden(array(
|
||||||
|
@ -198,20 +192,62 @@ echo Bootstrap::formOpen(array(
|
||||||
|
|
||||||
// Parent
|
// Parent
|
||||||
try {
|
try {
|
||||||
|
$options = array();
|
||||||
$parentKey = $page->parent();
|
$parentKey = $page->parent();
|
||||||
|
if (!empty($parentKey)) {
|
||||||
$parent = new Page($parentKey);
|
$parent = new Page($parentKey);
|
||||||
$parentValue = $parent->title();
|
$options = array($parentKey=>$parent->title());
|
||||||
} catch (Exception $e) {
|
|
||||||
$parentValue = '';
|
|
||||||
}
|
}
|
||||||
echo Bootstrap::formInputTextBlock(array(
|
} catch (Exception $e) {
|
||||||
'name'=>'parentTMP',
|
// continue
|
||||||
|
}
|
||||||
|
echo Bootstrap::formSelectBlock(array(
|
||||||
|
'name'=>'parent',
|
||||||
'label'=>$L->g('Parent'),
|
'label'=>$L->g('Parent'),
|
||||||
'placeholder'=>'',
|
'options'=>$options,
|
||||||
|
'selected'=>false,
|
||||||
|
'class'=>'',
|
||||||
'tip'=>$L->g('Start typing a page title to see a list of suggestions.'),
|
'tip'=>$L->g('Start typing a page title to see a list of suggestions.'),
|
||||||
'value'=>$parentValue
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var parent = $("#jsparent").select2({
|
||||||
|
placeholder: "",
|
||||||
|
allowClear: true,
|
||||||
|
theme: "bootstrap4",
|
||||||
|
minimumInputLength: 2,
|
||||||
|
ajax: {
|
||||||
|
url: HTML_PATH_ADMIN_ROOT+"ajax/get-published",
|
||||||
|
data: function (params) {
|
||||||
|
var query = {
|
||||||
|
checkIsParent: true,
|
||||||
|
query: params.term
|
||||||
|
}
|
||||||
|
return query;
|
||||||
|
},
|
||||||
|
processResults: function (data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
escapeMarkup: function(markup) {
|
||||||
|
return markup;
|
||||||
|
},
|
||||||
|
templateResult: function(data) {
|
||||||
|
var html = data.text
|
||||||
|
if (data.type=="static") {
|
||||||
|
html += " [" + data.type + "]"
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
// Template
|
// Template
|
||||||
echo Bootstrap::formInputTextBlock(array(
|
echo Bootstrap::formInputTextBlock(array(
|
||||||
'name'=>'template',
|
'name'=>'template',
|
||||||
|
|
|
@ -14,12 +14,6 @@ echo Bootstrap::formOpen(array(
|
||||||
'value'=>$security->getTokenCSRF()
|
'value'=>$security->getTokenCSRF()
|
||||||
));
|
));
|
||||||
|
|
||||||
// Parent
|
|
||||||
echo Bootstrap::formInputHidden(array(
|
|
||||||
'name'=>'parent',
|
|
||||||
'value'=>''
|
|
||||||
));
|
|
||||||
|
|
||||||
// UUID
|
// UUID
|
||||||
// The UUID is generated in the controller
|
// The UUID is generated in the controller
|
||||||
echo Bootstrap::formInputHidden(array(
|
echo Bootstrap::formInputHidden(array(
|
||||||
|
@ -178,14 +172,52 @@ echo Bootstrap::formOpen(array(
|
||||||
));
|
));
|
||||||
|
|
||||||
// Parent
|
// Parent
|
||||||
echo Bootstrap::formInputTextBlock(array(
|
echo Bootstrap::formSelectBlock(array(
|
||||||
'name'=>'parentTMP',
|
'name'=>'parent',
|
||||||
'label'=>$L->g('Parent'),
|
'label'=>$L->g('Parent'),
|
||||||
'placeholder'=>'',
|
'options'=>array(),
|
||||||
|
'selected'=>false,
|
||||||
|
'class'=>'',
|
||||||
'tip'=>$L->g('Start typing a page title to see a list of suggestions.'),
|
'tip'=>$L->g('Start typing a page title to see a list of suggestions.'),
|
||||||
'value'=>''
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var parent = $("#jsparent").select2({
|
||||||
|
placeholder: "",
|
||||||
|
allowClear: true,
|
||||||
|
theme: "bootstrap4",
|
||||||
|
minimumInputLength: 2,
|
||||||
|
ajax: {
|
||||||
|
url: HTML_PATH_ADMIN_ROOT+"ajax/get-published",
|
||||||
|
data: function (params) {
|
||||||
|
var query = {
|
||||||
|
checkIsParent: true,
|
||||||
|
query: params.term
|
||||||
|
}
|
||||||
|
return query;
|
||||||
|
},
|
||||||
|
processResults: function (data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
escapeMarkup: function(markup) {
|
||||||
|
return markup;
|
||||||
|
},
|
||||||
|
templateResult: function(data) {
|
||||||
|
var html = data.text
|
||||||
|
if (data.type=="static") {
|
||||||
|
html += " [" + data.type + "]"
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<?php
|
||||||
// Template
|
// Template
|
||||||
echo Bootstrap::formInputTextBlock(array(
|
echo Bootstrap::formInputTextBlock(array(
|
||||||
'name'=>'template',
|
'name'=>'template',
|
||||||
|
@ -235,33 +267,7 @@ echo Bootstrap::formOpen(array(
|
||||||
// Datepicker
|
// Datepicker
|
||||||
$("#jsdate").datetimepicker({format:DB_DATE_FORMAT});
|
$("#jsdate").datetimepicker({format:DB_DATE_FORMAT});
|
||||||
|
|
||||||
// Parent autocomplete
|
|
||||||
var parentsXHR;
|
|
||||||
var parentsList; // Keep the parent list returned to get the key by the title page
|
|
||||||
$("#jsparentTMP").autoComplete({
|
|
||||||
minChars: 1,
|
|
||||||
source: function(term, response) {
|
|
||||||
// Prevent call inmediatly another ajax request
|
|
||||||
try { parentsXHR.abort(); } catch(e){}
|
|
||||||
// Get the list of parent pages by title (term)
|
|
||||||
parentsXHR = $.getJSON(HTML_PATH_ADMIN_ROOT+"ajax/get-parents", {query: term},
|
|
||||||
function(data) {
|
|
||||||
parentsList = data;
|
|
||||||
term = term.toLowerCase();
|
|
||||||
var matches = [];
|
|
||||||
for (var title in data) {
|
|
||||||
if (~title.toLowerCase().indexOf(term))
|
|
||||||
matches.push(title);
|
|
||||||
}
|
|
||||||
response(matches);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onSelect: function(event, term, item) {
|
|
||||||
// parentsList = array( pageTitle => pageKey )
|
|
||||||
var parentKey = parentsList[sanitizeHTML(term)];
|
|
||||||
$("#jsparent").attr("value", parentKey);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
|
|
||||||
/*
|
|
||||||
| Returns a list of parent pages and the title contains the query string
|
|
||||||
| The returned list have published, sticky and statics pages
|
|
||||||
|
|
|
||||||
| @_POST['query'] string The string to search in the title of the pages
|
|
||||||
|
|
|
||||||
| @return array
|
|
||||||
*/
|
|
||||||
|
|
||||||
// $_GET
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// (string) $_GET['query']
|
|
||||||
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
if ($query===false) {
|
|
||||||
ajaxResponse(1, 'Invalid query.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp = array();
|
|
||||||
$pagesKey = $pages->getDB();
|
|
||||||
foreach ($pagesKey as $pageKey) {
|
|
||||||
try {
|
|
||||||
$page = new Page($pageKey);
|
|
||||||
// Check if the page is available to be parent
|
|
||||||
if ($page->isParent()) {
|
|
||||||
// Check page status
|
|
||||||
if ($page->published() || $page->sticky() || $page->isStatic()) {
|
|
||||||
// Check if the query contains in the title
|
|
||||||
$lowerTitle = Text::lowercase($page->title());
|
|
||||||
if (Text::stringContains($lowerTitle, $query)) {
|
|
||||||
$tmp[$page->title()] = $page->key();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
// continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit (json_encode($tmp));
|
|
||||||
|
|
||||||
?>
|
|
|
@ -14,6 +14,8 @@ header('Content-Type: application/json');
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// (string) $_GET['query']
|
// (string) $_GET['query']
|
||||||
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
|
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
|
||||||
|
// (boolean) $_GET['checkIsParent']
|
||||||
|
$checkIsParent = empty($_GET['checkIsParent']) ? false : true;
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
if ($query===false) {
|
if ($query===false) {
|
||||||
ajaxResponse(1, 'Invalid query.');
|
ajaxResponse(1, 'Invalid query.');
|
||||||
|
@ -24,6 +26,7 @@ $pagesKey = $pages->getDB();
|
||||||
foreach ($pagesKey as $pageKey) {
|
foreach ($pagesKey as $pageKey) {
|
||||||
try {
|
try {
|
||||||
$page = new Page($pageKey);
|
$page = new Page($pageKey);
|
||||||
|
if ($page->isParent() || !$checkIsParent) {
|
||||||
// Check page status
|
// Check page status
|
||||||
if ($page->published() || $page->sticky() || $page->isStatic()) {
|
if ($page->published() || $page->sticky() || $page->isStatic()) {
|
||||||
// Check if the query contains in the title
|
// Check if the query contains in the title
|
||||||
|
@ -36,6 +39,7 @@ foreach ($pagesKey as $pageKey) {
|
||||||
array_push($result, $tmp);
|
array_push($result, $tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue