Permalink
Browse files

Merge pull request #1 from brabo/master

Added admin help
  • Loading branch information...
2 parents fdd2ac1 + dadfe73 commit 3d208d7206fdd7a42d61d1322c50ea2addd40d4b @brabo brabo committed Oct 7, 2011
Showing with 36 additions and 1 deletion.
  1. +21 −1 lib/DDGC/Web/Controller/Admin/Help.pm
  2. +15 −0 templates/admin/help/index.tt
View
22 lib/DDGC/Web/Controller/Admin/Help.pm
@@ -12,7 +12,27 @@ sub base :Chained('/admin/base') :PathPart('help') :CaptureArgs(0) {
sub index :Chained('base') :PathPart('') :Args(0) {
my ( $self, $c ) = @_;
- $c->stash->{helps} = [$c->model('DB::Language')->search({})->all];
+ $c->stash->{help} = [$c->model('DB::Help')->search({})->all];
+ my @keys = qw/ key name description /;
+ for my $l (@{$c->stash->{help}}) {
+ my $p = 'help_'.$l->id.'_';
+ if ($c->req->params->{$p.'delete'}) {
+ $l->delete;
+ } elsif ($c->req->params->{save_help}) {
+ for (@keys) {
+ $l->$_($c->req->params->{$p.$_}) if $c->req->params->{$p.$_};
+ }
+ $l->update;
+ }
+ }
+ my %new;
+ if ($c->req->params->{save_help}) {
+ for (@keys) {
+ $new{$_} = $c->req->params->{'help_0_'.$_} if $c->req->params->{'help_0_'.$_};
+ }
+ push @{$c->stash->{help}}, $c->model('DB::Help')->create(\%new) if (%new);
+ }
+
}
__PACKAGE__->meta->make_immutable;
View
15 templates/admin/help/index.tt
@@ -0,0 +1,15 @@
+<form action="<@ u('Admin::Help','index') @>" method="post" name="helpform" id="helpform">
+ <div class="mybox">
+ <@ FOREACH list_help IN help @>
+ <p>#<@ list_help.id @></p>
+ <@ INCLUDE admin/help/form.tt help=list_help @>
+ <p><input type="submit" value="Delete" name="help_<@ list_help.id @>_delete" /></p>
+ <@ END @>
+ </div>
+ <div class="mybox">
+ <@ INCLUDE admin/help/form.tt @>
+ <div>
+ <input type="submit" value="Save Help" name="save_help" />
+ </div>
+ </div>
+</form>

0 comments on commit 3d208d7

Please sign in to comment.