pages: parent edit interface

This commit is contained in:
E. S. 2024-11-05 03:47:14 +03:00
parent f791f8f4aa
commit 6e665d3f52
5 changed files with 39 additions and 9 deletions

View File

@ -434,6 +434,14 @@ class AdminHandler extends request_handler {
'text' => $page->md,
'title' => $page->title,
];
$parent = '';
if ($page->parentId) {
$parent_page = pages::getById($page->parentId);
if ($parent_page)
$parent = $parent_page->shortName;
}
render('admin/pageForm',
is_edit: true,
short_name: $page->shortName,
@ -441,6 +449,7 @@ class AdminHandler extends request_handler {
text: $page->md,
visible: $page->visible,
render_title: $page->renderTitle,
parent: $parent,
saved: $saved,
langs: PostLanguage::cases(),
js_text: $js_text);
@ -457,8 +466,8 @@ class AdminHandler extends request_handler {
csrf_check('editpage'.$page->shortName);
list($text, $title, $visible, $short_name, $render_title)
= input('text, title, b:visible, new_short_name, b:render_title');
list($text, $title, $visible, $short_name, $parent, $render_title)
= input('text, title, b:visible, new_short_name, parent, b:render_title');
$text = trim($text);
$title = trim($title);
@ -476,6 +485,8 @@ class AdminHandler extends request_handler {
ajax_error(['code' => $error_code]);
$new_short_name = $page->shortName != $short_name ? $short_name : null;
$parent_page = pages::getByName($parent);
$parent_id = $parent_page ? $parent_page->id : 0;
previous_texts::add(PreviousText::TYPE_PAGE, $page->get_id(), $page->md, $page->updateTs ?: $page->ts);
$page->edit([
@ -483,7 +494,8 @@ class AdminHandler extends request_handler {
'md' => $text,
'visible' => (bool)$visible,
'short_name' => $short_name,
'render_title' => (bool)$render_title
'render_title' => (bool)$render_title,
'parent_id' => $parent_id
]);
admin_log(new \AdminActions\PageEdit($short_name, $new_short_name));

View File

@ -166,8 +166,10 @@ extend(AdminWriteEditForm.prototype, {
// fd.append('lang', this.getCurrentLang())
if (this.isPost() || this.isEditing())
fd.append('visible', ge('visible_cb').checked ? 1 : 0);
if (this.isPage() && this.isEditing())
if (this.isPage() && this.isEditing()) {
fd.append('render_title', ge('render_title_cb').checked ? 1 : 0);
fd.append('parent', evt.target.elements.parent.value.trim());
}
// text-specific fields
var atLeastOneLangIsWritten = false;

View File

@ -64,6 +64,12 @@ class pages {
previous_texts::delete(PreviousText::TYPE_PAGE, $page->get_id());
}
static function getById(int $id): ?Page {
$db = DB();
$q = $db->query("SELECT * FROM pages WHERE id=?", $id);
return $db->numRows($q) ? new Page($db->fetch($q)) : null;
}
static function getByName(string $short_name): ?Page {
$db = DB();
$q = $db->query("SELECT * FROM pages WHERE short_name=?", $short_name);

View File

@ -319,6 +319,7 @@ function pageForm($ctx,
?bool $saved = null,
bool $visible = false,
bool $render_title = false,
null|string|Stringable $parent = null,
?array $js_text = null): array {
$form_url = '/'.$short_name.'/'.($is_edit ? 'edit' : 'create').'/';
@ -355,7 +356,7 @@ $html = <<<HTML
</div>
{$ctx->if_then_else($is_edit,
fn() => $ctx->pageFormEditOptions($short_name, $visible, $render_title),
fn() => $ctx->pageFormEditOptions($short_name, $parent, $visible, $render_title),
fn() => $ctx->pageFormAddOptions($short_name))}
</form>
@ -385,12 +386,12 @@ JS;
return [$html, $js];
}
function pageFormEditOptions($ctx, $short_name, $visible, $render_title) {
function pageFormEditOptions($ctx, $short_name, $parent, $visible, $render_title) {
return <<<HTML
<div class="form-field-wrap clearfix">
<table class="blog-write-options-table">
<tr>
<td>
<td width="40%">
<div class="clearfix">
<div class="form-field-label">{$ctx->lang('pages_write_form_short_name')}</div>
<div class="form-field">
@ -398,7 +399,15 @@ return <<<HTML
</div>
</div>
</td>
<td>
<td width="30%">
<div class="clearfix">
<div class="form-field-label">{$ctx->lang('pages_write_form_parent')}</div>
<div class="form-field">
<input class="form-field-input" type="text" name="parent" value="{$parent}" />
</div>
</div>
</td>
<td width="30%">
<div class="clearfix">
<div class="form-field-label">{$ctx->lang('pages_write_form_options')}</div>
<div class="form-field">
@ -409,7 +418,7 @@ return <<<HTML
</td>
</tr>
<tr>
<td rowspan="2">
<td rowspan="3">
<button type="submit" name="submit_btn"><b>{$ctx->lang('pages_write_form_submit_btn')}</b></button>
</td>
</tr>

View File

@ -105,6 +105,7 @@ pages_write_form_enter_title: Enter title..
pages_write_form_visible: Visible
pages_write_form_render_title: Title
pages_write_form_short_name: Short name
pages_write_form_parent: Parent
pages_write_form_toggle_wrap: Toggle wrap
pages_write_form_options: Options