diff --git a/bl-kernel/admin/views/editor.php b/bl-kernel/admin/views/editor.php index 743bc169..228e0b41 100644 --- a/bl-kernel/admin/views/editor.php +++ b/bl-kernel/admin/views/editor.php @@ -60,7 +60,6 @@ // Save the current page // This function set the global variable "_pageKey" function savePage(args = []) { - console.log(_pageKey); if (_pageKey == null) { logs('Error, page not created.'); @@ -132,15 +131,23 @@ // Ctrl+S or Command+S if ((event.ctrlKey || event.metaKey) && event.which == 83) { event.preventDefault(); + var customFields = {} + $('input[name^="custom"]').each(function() { + var field = $(this).data('field') + var value = $(this).val() + customFields[field] = value + }); var args = { title: $('#title').val(), content: editorGetContent(), + custom: customFields, coverImage: $('#coverImage').val(), category: $('#category option:selected').val(), tags: $("#tags option:selected").map(function() { return this.value }).get().join(",") } + savePage(args); disableBtnSave(); return false; @@ -178,15 +185,23 @@ }); $('#btnSave').on('click', function() { - var args = { - title: $('#title').val(), - content: editorGetContent(), - coverImage: $('#coverImage').val(), - category: $('#category option:selected').val(), - tags: $("#tags option:selected").map(function() { - return this.value - }).get().join(",") - } + var customFields = {} + $('input[name^="custom"]').each(function() { + var field = $(this).data('field') + var value = $(this).val() + customFields[field] = value + }); + + var args = { + title: $('#title').val(), + content: editorGetContent(), + custom: customFields, + coverImage: $('#coverImage').val(), + category: $('#category option:selected').val(), + tags: $("#tags option:selected").map(function() { + return this.value + }).get().join(",") + } savePage(args); disableBtnSave(); }); @@ -358,7 +373,25 @@ if (content.length < 100) { return false; } - savePage(); + + var customFields = {} + $('input[name^="custom"]').each(function() { + var field = $(this).data('field') + var value = $(this).val() + customFields[field] = value + }); + + var args = { + title: $('#title').val(), + content: content, + custom: customFields, + coverImage: $('#coverImage').val(), + category: $('#category option:selected').val(), + tags: $("#tags option:selected").map(function() { + return this.value + }).get().join(",") + } + savePage(args); disableBtnSave(); }, 1000 * 60 * AUTOSAVE_INTERVAL); @@ -628,10 +661,70 @@ + + customFields(); + foreach ($customFields as $field=>$options) { + if ( !isset($options['position']) || ($options['position']=='top') ) { + if ($options['type']=="string") { + echo Bootstrap::formInputTextBlock(array( + 'name'=>'custom['.$field.']', + 'label'=>(isset($options['label'])?$options['label']:''), + 'value'=>(($pageKey && $page->custom($field))?$page->custom($field):''), + 'tip'=>(isset($options['tip'])?$options['tip']:''), + 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), + 'class'=>'form-control-lg', + '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']:''), + 'data' => array('field' => $field) + )); + } + } + } + ?> + +
+ + + customFields(); + foreach ($customFields as $field=>$options) { + if ( isset($options['position']) && ($options['position']=='bottom') ) { + if ($options['type']=="string") { + echo Bootstrap::formInputTextBlock(array( + 'name'=>'custom['.$field.']', + 'label'=>(isset($options['label'])?$options['label']:''), + 'value'=>(($pageKey && $page->custom($field))?$page->custom($field):''), + 'tip'=>(isset($options['tip'])?$options['tip']:''), + 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), + 'class'=>'form-control-lg', + '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']:''), + 'data' => array('field' => $field) + )); + } + } + } + ?> +
diff --git a/bl-kernel/helpers/bootstrap.class.php b/bl-kernel/helpers/bootstrap.class.php index 2950a5f7..bc58b7d0 100644 --- a/bl-kernel/helpers/bootstrap.class.php +++ b/bl-kernel/helpers/bootstrap.class.php @@ -226,54 +226,52 @@ EOF; return ''; } - - public static function formInputTextBlock($args) { $name = $args['name']; + $id = isset($args['id'])?$args['id']:$name; $disabled = empty($args['disabled'])?'':'disabled'; + $readonly = empty($args['readonly'])?'':'readonly'; $placeholder = isset($args['placeholder'])?$args['placeholder']:''; $value = isset($args['value'])?$args['value']:''; - - $id = 'js'.$name; - if (isset($args['id'])) { - $id = $args['id']; - } + $type = isset($args['type'])?$args['type']:'text'; $tip = ''; if (!empty($args['tip'])) { $tip = '
'.$args['tip'].'
'; } - $class = 'mb-3 m-0'; - if (isset($args['class'])) { - $class = $args['class']; - } - - $labelClass = 'mt-4 mb-2 pb-2 border-bottom text-uppercase w-100'; - if (isset($args['labelClass'])) { - $labelClass = $args['labelClass']; - } - $label = ''; if (!empty($args['label'])) { - $label = ''; + $label = ''; } - $type = 'text'; - if (isset($args['type'])) { - $type = $args['type']; + $class = 'form-control'; + if (isset($args['class'])) { + $class = $class.' '.$args['class']; + } + + $data = 'data-current-value="'.$value.'"'; + if (isset($args['data'])) { + if (is_array($args['data'])) { + foreach ($args['data'] as $x => $y) { + $data .= ' data-'.$x.' = "'.$y.'"'; + } + } } return << +
$label - + $tip
EOF; } + + + public static function formInputFile($args) { $id = 'js'.$args['name']; @@ -335,12 +333,12 @@ EOF; } $disabled = isset($args['disabled'])?'disabled':''; - $class = 'mb-3 m-0'; + $class = 'mb-2 m-0'; if (isset($args['class'])) { $class = $args['class']; } - $labelClass = 'mt-4 mb-2 pb-2 border-bottom text-uppercase w-100'; + $labelClass = 'mb-2 pb-2 border-bottom text-uppercase w-100'; if (isset($args['labelClass'])) { $labelClass = $args['labelClass']; } @@ -358,11 +356,20 @@ EOF; $checked = $args['checked']?'checked':''; $value = $checked?'1':'0'; + $data = ''; + if (isset($args['data'])) { + if (is_array($args['data'])) { + foreach ($args['data'] as $x => $y) { + $data .= ' data-'.$x.' = "'.$y.'"'; + } + } + } + return << $label
- + $tip
diff --git a/bl-kernel/pages.class.php b/bl-kernel/pages.class.php index 96ec3dae..19c9c1ad 100644 --- a/bl-kernel/pages.class.php +++ b/bl-kernel/pages.class.php @@ -83,8 +83,10 @@ class Pages extends dbJSON { foreach ($args['custom'] as $customField=>$customValue) { $html = Sanitize::html($customValue); // Store the custom field as defined type - settype($html, $customFields[$customField]['type']); - $row['custom'][$customField]['value'] = $html; + if (isset($customFields[$customField])) { + settype($html, $customFields[$customField]['type']); + $row['custom'][$customField]['value'] = $html; + } } unset($args['custom']); continue; @@ -204,8 +206,10 @@ class Pages extends dbJSON { foreach ($args['custom'] as $customField=>$customValue) { $html = Sanitize::html($customValue); // Store the custom field as defined type - settype($html, $customFields[$customField]['type']); - $row['custom'][$customField]['value'] = $html; + if (isset($customFields[$customField])) { + settype($html, $customFields[$customField]['type']); + $row['custom'][$customField]['value'] = $html; + } } unset($args['custom']); continue;