attachments interface visibility toggling

master
Joey Hess 2008-07-02 15:42:32 -04:00
parent e998235240
commit d593533af5
2 changed files with 21 additions and 4 deletions

View File

@ -18,6 +18,7 @@ sub checkconfig () { #{{{
sub formbuilder_setup (@) { #{{{ sub formbuilder_setup (@) { #{{{
my %params=@_; my %params=@_;
my $form=$params{form}; my $form=$params{form};
my $q=$params{cgi};
if ($form->field("do") eq "edit") { if ($form->field("do") eq "edit") {
$form->field(name => 'attachment', type => 'file'); $form->field(name => 'attachment', type => 'file');
@ -25,6 +26,20 @@ sub formbuilder_setup (@) { #{{{
# are not added to the normal formbuilder button list. # are not added to the normal formbuilder button list.
$form->tmpl_param("field-upload" => '<input name="_submit" type="submit" value="Upload Attachment" />'); $form->tmpl_param("field-upload" => '<input name="_submit" type="submit" value="Upload Attachment" />');
$form->tmpl_param("field-link" => '<input name="_submit" type="submit" value="Insert Links" />'); $form->tmpl_param("field-link" => '<input name="_submit" type="submit" value="Insert Links" />');
# Add the javascript from the toggle plugin;
# the attachments interface uses it to toggle visibility.
require IkiWiki::Plugin::toggle;
$form->tmpl_param("javascript" => $IkiWiki::Plugin::toggle::javascript);
# Start with the attachments interface toggled invisible,
# but if it was used, keep it open.
if ($form->submitted ne "Upload Attachment" &&
! length $q->param("attachment_select")) {
$form->tmpl_param("attachments-class" => "toggleable");
}
else {
$form->tmpl_param("attachments-class" => "toggleable-open");
}
} }
elsif ($form->title eq "preferences") { elsif ($form->title eq "preferences") {
my $session=$params{session}; my $session=$params{session};
@ -136,7 +151,7 @@ sub formbuilder (@) { #{{{
} }
$form->field(name => 'editcontent', $form->field(name => 'editcontent',
value => $form->field('editcontent')."\n\n".$add, value => $form->field('editcontent')."\n\n".$add,
force => 1); force => 1) if length $add;
} }
# Generate the attachment list only after having added any new # Generate the attachment list only after having added any new

View File

@ -60,10 +60,10 @@ Optional comment about this change:<br />
</TMPL_IF> </TMPL_IF>
<TMPL_VAR FORM-SUBMIT> <TMPL_VAR FORM-SUBMIT>
<TMPL_VAR HELPONFORMATTINGLINK> <TMPL_VAR HELPONFORMATTINGLINK>
<a class="toggle" href="#attachments">Attachments</a>
<TMPL_IF NAME="FIELD-ATTACHMENT"> <TMPL_IF NAME="FIELD-ATTACHMENT">
<div id=attachments> <div class="<TMPL_VAR ATTACHMENTS-CLASS>" id="attachments">
<br /> <table>
<table><caption>Attachments</caption>
<tr><td colspan=5><TMPL_VAR FIELD-ATTACHMENT><TMPL_VAR FIELD-UPLOAD></td></tr> <tr><td colspan=5><TMPL_VAR FIELD-ATTACHMENT><TMPL_VAR FIELD-UPLOAD></td></tr>
<TMPL_LOOP NAME="ATTACHMENT_LIST"> <TMPL_LOOP NAME="ATTACHMENT_LIST">
<tr><td><TMPL_VAR FIELD-SELECT><TMPL_VAR LINK></td><td><TMPL_VAR SIZE></td><td><TMPL_VAR MTIME></td></tr> <tr><td><TMPL_VAR FIELD-SELECT><TMPL_VAR LINK></td><td><TMPL_VAR SIZE></td><td><TMPL_VAR MTIME></td></tr>
@ -86,3 +86,5 @@ Optional comment about this change:<br />
<TMPL_VAR PAGE_PREVIEW> <TMPL_VAR PAGE_PREVIEW>
</div> </div>
</TMPL_IF> </TMPL_IF>
<TMPL_VAR JAVASCRIPT>