po(formbuilder_setup): remove the rename/remove buttons on slave pages

This has to be done after the rename/remove plugins have added
their buttons, so we set this hook to be run last.

The canrename/canremove hooks already ensure this is forbidden
at the backend level, so this is only UI sugar.

Signed-off-by: intrigeri <intrigeri@boum.org>
master
intrigeri 2009-01-02 15:50:47 +01:00
parent e5222db332
commit fae3cef41a
2 changed files with 25 additions and 8 deletions

View File

@ -43,7 +43,7 @@ sub import {
hook(type => "canremove", id => "po", call => \&canremove);
hook(type => "canrename", id => "po", call => \&canrename);
hook(type => "editcontent", id => "po", call => \&editcontent);
hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup);
hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
hook(type => "formbuilder", id => "po", call => \&formbuilder);
$origsubs{'bestlink'}=\&IkiWiki::bestlink;
@ -447,11 +447,31 @@ sub formbuilder_setup (@) {
my $form=$params{form};
my $q=$params{cgi};
return unless (defined $form->field("do") && $form->field("do") eq "create");
return unless defined $form->field("do");
my $template=template("pocreatepage.tmpl");
$template->param(LANG => $config{po_master_language}{name});
$form->tmpl_param(message => $template->output);
if ($form->field("do") eq "create") {
# Warn the user: new pages must be written in master language.
my $template=template("pocreatepage.tmpl");
$template->param(LANG => $config{po_master_language}{name});
$form->tmpl_param(message => $template->output);
}
elsif ($form->field("do") eq "edit") {
# Remove the rename/remove buttons on slave pages.
# This has to be done after the rename/remove plugins have added
# their buttons, which is why this hook must be run last.
# The canrename/canremove hooks already ensure this is forbidden
# at the backend level, so this is only UI sugar.
if (istranslation($form->field("page"))) {
map {
for (my $i = 0; $i < @{$params{buttons}}; $i++) {
if (@{$params{buttons}}[$i] eq $_) {
delete @{$params{buttons}}[$i];
last;
}
}
} qw(Rename Remove);
}
}
}
# Do not allow to create pages of type po: they are automatically created.

View File

@ -576,6 +576,3 @@ Misc
* Can the form validation system be used instead of creating the
`cansave` hook?
* Use the formbuilder_setup hook to remove the rename/remove buttons
on slave edit pages. The canrename/canremove hook ensure this is
forbidden at the backend level, and this change would improve the UI.