From 66ff89c3ab8917207688ec4d1b8c823b0a63f768 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Tue, 3 May 2022 19:45:01 +0200 Subject: [PATCH] check json format for custom fields, add position menu for custom fields, fix issues with boolean types --- bl-kernel/admin/views/editor.php | 79 +++++++++++++++++++++++---- bl-kernel/admin/views/login.php | 7 ++- bl-kernel/admin/views/settings.php | 9 ++- bl-kernel/boot/init.php | 9 ++- bl-kernel/helpers/bootstrap.class.php | 41 ++++++++++---- bl-kernel/js/functions.js | 14 ++++- bl-kernel/pages.class.php | 17 +++--- 7 files changed, 135 insertions(+), 41 deletions(-) diff --git a/bl-kernel/admin/views/editor.php b/bl-kernel/admin/views/editor.php index a4b67003..a231ca69 100644 --- a/bl-kernel/admin/views/editor.php +++ b/bl-kernel/admin/views/editor.php @@ -131,12 +131,21 @@ // Ctrl+S or Command+S if ((event.ctrlKey || event.metaKey) && event.which == 83) { event.preventDefault(); + + // Parse all custom fields inputs var customFields = {} $('input[name^="custom"]').each(function() { var field = $(this).data('field') var value = $(this).val() customFields[field] = value }); + $('select[name^="custom"]').each(function() { + var field = $(this).data('field'); + var value = $(this).val(); + customFields[field] = value; + }); + + // Create array with all inputs var args = { slug: $('#friendlyURL').val(), title: $('#title').val(), @@ -186,12 +195,20 @@ }); $('#btnSave').on('click', function() { + // Parse all custom fields inputs var customFields = {} $('input[name^="custom"]').each(function() { var field = $(this).data('field') var value = $(this).val() customFields[field] = value }); + $('select[name^="custom"]').each(function() { + var field = $(this).data('field'); + var value = $(this).val(); + customFields[field] = value; + }); + + // Create array with all inputs var args = { slug: $('#friendlyURL').val(), title: $('#title').val(), @@ -383,13 +400,20 @@ return false; } + // Parse all custom fields inputs var customFields = {} $('input[name^="custom"]').each(function() { var field = $(this).data('field') var value = $(this).val() customFields[field] = value }); + $('select[name^="custom"]').each(function() { + var field = $(this).data('field'); + var value = $(this).val(); + customFields[field] = value; + }); + // Create array with all inputs var args = { slug: $('#friendlyURL').val(), title: $('#title').val(), @@ -687,12 +711,12 @@ 'data' => array('field' => $field) )); } elseif ($options['type']=="bool") { - echo Bootstrap::formCheckbox(array( - 'name'=>'custom['.$field.']', - 'label'=>(isset($options['label'])?$options['label']:''), - 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), - 'checked'=>(($pageKey && $page->custom($field))?true:false), - 'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''), + echo Bootstrap::formSelectBlock(array( + 'name' => 'custom['.$field.']', + 'label' => (isset($options['label'])?$options['label']:''), + 'options' => array('true' => $L->g('Enabled'), 'false' => $L->g('Disabled')), + 'selected' => (($pageKey && $page->custom($field))?'true':'false'), + 'tip' => (isset($options['tip'])?$options['tip']:''), 'data' => array('field' => $field) )); } @@ -722,12 +746,12 @@ 'data' => array('field' => $field) )); } elseif ($options['type']=="bool") { - echo Bootstrap::formCheckbox(array( - 'name'=>'custom['.$field.']', - 'label'=>(isset($options['label'])?$options['label']:''), - 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), - 'checked'=>(($pageKey && $page->custom($field))?true:false), - 'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''), + echo Bootstrap::formSelectBlock(array( + 'name' => 'custom['.$field.']', + 'label' => (isset($options['label'])?$options['label']:''), + 'options' => array('true' => $L->g('Enabled'), 'false' => $L->g('Disabled')), + 'selected' => (($pageKey && $page->custom($field))?'true':'false'), + 'tip' => (isset($options['tip'])?$options['tip']:''), 'data' => array('field' => $field) )); } @@ -800,6 +824,37 @@ + + + customFields(); + foreach ($customFields as $field=>$options) { + if ( isset($options['position']) && ($options['position']=='menu') ) { + if ($options['type']=="string") { + echo '
'.(isset($options['label'])?$options['label']:'').'
'; + echo Bootstrap::formInputTextBlock(array( + 'name'=>'custom['.$field.']', + 'value'=>(($pageKey && $page->custom($field))?$page->custom($field):''), + 'tip'=>(isset($options['tip'])?$options['tip']:''), + 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), + 'class'=>'', + 'data' => array('field' => $field) + )); + } elseif ($options['type']=="bool") { + echo '
'.(isset($options['label'])?$options['label']:'').'
'; + echo Bootstrap::formSelectBlock(array( + 'name' => 'custom['.$field.']', + 'label' => '', + 'options' => array('true' => $L->g('Enabled'), 'false' => $L->g('Disabled')), + 'selected' => (($pageKey && $page->custom($field))?true:false), + 'tip' => (isset($options['tip'])?$options['tip']:''), + 'data' => array('field' => $field) + )); + } + } + } + ?> +
p('More options') ?>