shm_simple_form

This commit is contained in:
Shish 2020-01-26 13:25:02 +00:00
parent 1802b9c7f6
commit f5ccffdaf4
4 changed files with 66 additions and 54 deletions

View file

@ -1,4 +1,5 @@
<?php
use function MicroHTML\emptyHTML;
use function MicroHTML\FORM;
use function MicroHTML\INPUT;
use function MicroHTML\DIV;
@ -703,6 +704,12 @@ function SHM_FORM(string $target, string $method="POST", bool $multipart=false,
return $f;
}
function SHM_SIMPLE_FORM($target, ...$children) {
$form = SHM_FORM($target);
$form->appendChild(emptyHTML(...$children));
return $form;
}
function SHM_COMMAND_EXAMPLE(string $ex, string $desc)
{
return DIV(
@ -717,15 +724,16 @@ function SHM_USER_FORM(User $duser, string $target, string $title, $body, $foot)
if (is_string($foot)) {
$foot = TFOOT(TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>$foot]))));
}
$form = SHM_FORM(make_link($target));
$form->appendChild(P(
INPUT(["type"=>'hidden', "name"=>'id', "value"=>$duser->id]),
TABLE(
["class"=>"form"],
THEAD(TR(TH(["colspan"=>"2"], $title))),
$body,
$foot
return SHM_SIMPLE_FORM(
make_link($target),
P(
INPUT(["type"=>'hidden', "name"=>'id', "value"=>$duser->id]),
TABLE(
["class"=>"form"],
THEAD(TR(TH(["colspan"=>"2"], $title))),
$body,
$foot
)
)
));
return $form;
);
}

View file

@ -9,41 +9,43 @@ class BlocksTheme extends Themelet
$html = TABLE(["class"=>"form", "style"=>"width: 100%;"]);
foreach ($blocks as $block) {
$form = SHM_FORM(make_link("blocks/update"));
$form->appendChild(TR(
INPUT(["type"=>"hidden", "name"=>"id", "value"=>$block['id']]),
TH("Title"), TD(INPUT(["type"=>"text", "name"=>"title", "value"=>$block['title']])),
TH("Area"), TD(INPUT(["type"=>"text", "name"=>"area", "value"=>$block['area']])),
TH("Priority"), TD(INPUT(["type"=>"text", "name"=>"priority", "value"=>$block['priority']])),
TH("Pages"), TD(INPUT(["type"=>"text", "name"=>"pages", "value"=>$block['pages']])),
TH("Delete"), TD(INPUT(["type"=>"checkbox", "name"=>"delete"])),
TD(INPUT(["type"=>"submit", "value"=>"Save"]))
$html->appendChild(SHM_SIMPLE_FORM(
make_link("blocks/update"),
TR(
INPUT(["type"=>"hidden", "name"=>"id", "value"=>$block['id']]),
TH("Title"), TD(INPUT(["type"=>"text", "name"=>"title", "value"=>$block['title']])),
TH("Area"), TD(INPUT(["type"=>"text", "name"=>"area", "value"=>$block['area']])),
TH("Priority"), TD(INPUT(["type"=>"text", "name"=>"priority", "value"=>$block['priority']])),
TH("Pages"), TD(INPUT(["type"=>"text", "name"=>"pages", "value"=>$block['pages']])),
TH("Delete"), TD(INPUT(["type"=>"checkbox", "name"=>"delete"])),
TD(INPUT(["type"=>"submit", "value"=>"Save"]))
),
TR(
TD(["colspan"=>"11"], TEXTAREA(["rows"=>"5", "name"=>"content"], $block['content']))
),
TR(
TD(["colspan"=>"11"], rawHTML("&nbsp;"))
),
));
$form->appendChild(TR(
TD(["colspan"=>"11"], TEXTAREA(["rows"=>"5", "name"=>"content"], $block['content']))
));
$form->appendChild(TR(
TD(["colspan"=>"11"], rawHTML("&nbsp;"))
));
$html->appendChild($form);
}
$form = SHM_FORM(make_link("blocks/add"));
$form->appendChild(TR(
TH("Title"), TD(INPUT(["type"=>"text", "name"=>"title", "value"=>""])),
TH("Area"), TD(SELECT(["name"=>"area"], OPTION("left"), OPTION("main")),
TH("Priority"), TD(INPUT(["type"=>"text", "name"=>"priority", "value"=>'50'])),
TH("Pages"), TD(INPUT(["type"=>"text", "name"=>"pages", "value"=>'post/list*'])),
TD(["colspan"=>'3'], INPUT(["type"=>"submit", "value"=>"Add"]))
)));
$form->appendChild(TR(
TD(["colspan"=>"11"], TEXTAREA(["rows"=>"5", "name"=>"content"]))
$html->appendChild(SHM_SIMPLE_FORM(
make_link("blocks/add"),
TR(
TH("Title"), TD(INPUT(["type"=>"text", "name"=>"title", "value"=>""])),
TH("Area"), TD(SELECT(["name"=>"area"], OPTION("left"), OPTION("main"))),
TH("Priority"), TD(INPUT(["type"=>"text", "name"=>"priority", "value"=>'50'])),
TH("Pages"), TD(INPUT(["type"=>"text", "name"=>"pages", "value"=>'post/list*'])),
TD(["colspan"=>'3'], INPUT(["type"=>"submit", "value"=>"Add"]))
),
TR(
TD(["colspan"=>"11"], TEXTAREA(["rows"=>"5", "name"=>"content"]))
),
));
$html->appendChild($form);
$page->set_title("Blocks");
$page->set_heading("Blocks");
$page->add_block(new NavBlock());
$page->add_block(new Block("Block Editor", $html));
$page->add_block(new Block("Block Editor", (string)$html));
}
}

View file

@ -26,18 +26,20 @@ class ExtManagerTheme extends Themelet
{
$tbody = TBODY();
$form = SHM_FORM(make_link("ext_manager/set"));
$form->appendChild(TABLE(
["id"=>'extensions', "class"=>'zebra sortable'],
THEAD(TR(
$editable ? TH("Enabled") : null,
TH("Name"),
TH("Docs"),
TH("Description")
)),
$tbody,
$editable ? TFOOT(TR(TD(["colspan"=>'5'], INPUT(["type"=>'submit', "value"=>'Set Extensions'])))) : null
));
$form = SHM_SIMPLE_FORM(
make_link("ext_manager/set"),
TABLE(
["id"=>'extensions', "class"=>'zebra sortable'],
THEAD(TR(
$editable ? TH("Enabled") : null,
TH("Name"),
TH("Docs"),
TH("Description")
)),
$tbody,
$editable ? TFOOT(TR(TD(["colspan"=>'5'], INPUT(["type"=>'submit', "value"=>'Set Extensions'])))) : null
)
);
foreach ($extensions as $extension) {
if ((!$editable && $extension->visibility === ExtensionInfo::VISIBLE_ADMIN)

View file

@ -63,8 +63,8 @@ class UserPageTheme extends Themelet
$tac = $tfe->formatted;
}
$form = SHM_FORM(make_link("user_admin/create"));
$form->appendChild(
$form = SHM_SIMPLE_FORM(
make_link("user_admin/create"),
TABLE(
["class"=>"form"],
TBODY(
@ -119,8 +119,8 @@ class UserPageTheme extends Themelet
public function display_login_block(Page $page)
{
global $config, $user;
$form = SHM_FORM(make_link("user_admin/login"));
$form->appendChild(
$form = SHM_SIMPLE_FORM(
make_link("user_admin/login"),
TABLE(
["style"=>"width: 100%", "class"=>"form"],
TBODY(