From c5977fc0cbc85116c1fc40d71bc2dca04845ae43 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sat, 5 Oct 2019 21:20:58 +0200 Subject: [PATCH] Select parent page bug fix #1089 --- bl-kernel/admin/views/edit-content.php | 62 +++++++++++++++----- bl-kernel/admin/views/new-content.php | 80 ++++++++++++++------------ bl-kernel/ajax/get-parents.php | 45 --------------- bl-kernel/ajax/get-published.php | 24 ++++---- 4 files changed, 106 insertions(+), 105 deletions(-) delete mode 100644 bl-kernel/ajax/get-parents.php diff --git a/bl-kernel/admin/views/edit-content.php b/bl-kernel/admin/views/edit-content.php index 61987ee9..6c4b5d44 100644 --- a/bl-kernel/admin/views/edit-content.php +++ b/bl-kernel/admin/views/edit-content.php @@ -14,12 +14,6 @@ echo Bootstrap::formOpen(array( 'value'=>$security->getTokenCSRF() )); - // Parent - echo Bootstrap::formInputHidden(array( - 'name'=>'parent', - 'value'=>$page->parent() - )); - // UUID // The UUID is generated in the controller echo Bootstrap::formInputHidden(array( @@ -198,20 +192,62 @@ echo Bootstrap::formOpen(array( // Parent try { + $options = array(); $parentKey = $page->parent(); - $parent = new Page($parentKey); - $parentValue = $parent->title(); + if (!empty($parentKey)) { + $parent = new Page($parentKey); + $options = array($parentKey=>$parent->title()); + } } catch (Exception $e) { - $parentValue = ''; + // continue } - echo Bootstrap::formInputTextBlock(array( - 'name'=>'parentTMP', + echo Bootstrap::formSelectBlock(array( + 'name'=>'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.'), - 'value'=>$parentValue )); + ?> + + + + 'template', diff --git a/bl-kernel/admin/views/new-content.php b/bl-kernel/admin/views/new-content.php index 6a5c0ecd..f2f634e8 100644 --- a/bl-kernel/admin/views/new-content.php +++ b/bl-kernel/admin/views/new-content.php @@ -14,12 +14,6 @@ echo Bootstrap::formOpen(array( 'value'=>$security->getTokenCSRF() )); - // Parent - echo Bootstrap::formInputHidden(array( - 'name'=>'parent', - 'value'=>'' - )); - // UUID // The UUID is generated in the controller echo Bootstrap::formInputHidden(array( @@ -178,14 +172,52 @@ echo Bootstrap::formOpen(array( )); // Parent - echo Bootstrap::formInputTextBlock(array( - 'name'=>'parentTMP', + echo Bootstrap::formSelectBlock(array( + 'name'=>'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.'), - 'value'=>'' )); + ?> + + + + 'template', @@ -235,33 +267,7 @@ echo Bootstrap::formOpen(array( // Datepicker $("#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); - } - }); + }); diff --git a/bl-kernel/ajax/get-parents.php b/bl-kernel/ajax/get-parents.php deleted file mode 100644 index a792cd6b..00000000 --- a/bl-kernel/ajax/get-parents.php +++ /dev/null @@ -1,45 +0,0 @@ -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)); - -?> \ No newline at end of file diff --git a/bl-kernel/ajax/get-published.php b/bl-kernel/ajax/get-published.php index 7ce287ab..b4b92128 100644 --- a/bl-kernel/ajax/get-published.php +++ b/bl-kernel/ajax/get-published.php @@ -14,6 +14,8 @@ header('Content-Type: application/json'); // ---------------------------------------------------------------------------- // (string) $_GET['query'] $query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false; +// (boolean) $_GET['checkIsParent'] +$checkIsParent = empty($_GET['checkIsParent']) ? false : true; // ---------------------------------------------------------------------------- if ($query===false) { ajaxResponse(1, 'Invalid query.'); @@ -24,16 +26,18 @@ $pagesKey = $pages->getDB(); foreach ($pagesKey as $pageKey) { try { $page = new Page($pageKey); - // 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 = array('disabled'=>false); - $tmp['id'] = $page->key(); - $tmp['text'] = $page->title(); - $tmp['type'] = $page->type(); - array_push($result, $tmp); + if ($page->isParent() || !$checkIsParent) { + // 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 = array('disabled'=>false); + $tmp['id'] = $page->key(); + $tmp['text'] = $page->title(); + $tmp['type'] = $page->type(); + array_push($result, $tmp); + } } } } catch (Exception $e) {