]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
basic form display done
authorJoey Hess <joey@kodama.kitenet.net>
Sat, 2 Aug 2008 18:35:23 +0000 (14:35 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Sat, 2 Aug 2008 20:41:36 +0000 (16:41 -0400)
IkiWiki/Plugin/websetup.pm

index e1536a1a7a238c1422960845ab49c3e6943721c4..a30475977e2b07ef74d24666f3c8af6c3389bd09 100644 (file)
@@ -12,6 +12,56 @@ sub import { #{{{
             call => \&formbuilder_setup);
 } # }}}
 
             call => \&formbuilder_setup);
 } # }}}
 
+sub addfields ($$@) {
+       my $form=shift;
+       my $section=shift;
+
+       while (@_) {
+               my $key=shift;
+               my %info=%{shift()};
+
+               next if ! $info{safe} || $info{type} eq "internal";
+
+               my $description=exists $info{description_html} ? $info{description_html} : $info{description};
+
+               my $value=$config{$key};
+               # multiple plugins can have the same key
+               my $name=$section.".".$key;
+
+               if ($info{type} eq "string") {
+                       $form->field(
+                               name => $name,
+                               label => $description,
+                               comment => exists $info{example} && length $info{example} && $info{example} ne $value ? "<br/ ><small>Example: <tt>$info{example}</tt></small>" : "",
+                               type => "text",
+                               value => $value,
+                               size => 60,
+                               fieldset => $section,
+                       );
+               }
+               elsif ($info{type} eq "integer") {
+                       $form->field(
+                               name => $name,
+                               label => $description,
+                               type => "text",
+                               value => $value,
+                               validate => '/^[0-9]+$/',
+                               fieldset => $section,
+                       );
+               }
+               elsif ($info{type} eq "boolean") {
+                       $form->field(
+                               name => $name,
+                               label => "",
+                               type => "checkbox",
+                               value => $value,
+                               options => [ [ 1 => $description ] ],
+                               fieldset => $section,
+                       );
+               }
+       }
+}
+
 sub showform ($$) { #{{{
        my $cgi=shift;
        my $session=shift;
 sub showform ($$) { #{{{
        my $cgi=shift;
        my $session=shift;
@@ -30,6 +80,7 @@ sub showform ($$) { #{{{
                header => 0,
                charset => "utf-8",
                method => 'POST',
                header => 0,
                charset => "utf-8",
                method => 'POST',
+               javascript => 0,
                params => $cgi,
                action => $config{cgiurl},
                template => {type => 'div'},
                params => $cgi,
                action => $config{cgiurl},
                template => {type => 'div'},
@@ -46,9 +97,12 @@ sub showform ($$) { #{{{
 
        $form->field(name => "do", type => "hidden", value => "setup",
                force => 1);
 
        $form->field(name => "do", type => "hidden", value => "setup",
                force => 1);
-
-       if (! $form->submitted) {
-               # TODO
+       addfields($form, gettext("main"), IkiWiki::getsetup());
+       require IkiWiki::Setup;
+       foreach my $pair (IkiWiki::Setup::getsetup()) {
+               my $plugin=$pair->[0];
+               my $setup=$pair->[1];
+               addfields($form, $plugin." ".gettext("plugin"), @{$setup});
        }
 
        if ($form->submitted eq "Cancel") {
        }
 
        if ($form->submitted eq "Cancel") {