Permalink
Browse files

Admin related stuff

  • Loading branch information...
lestrrat committed Apr 14, 2009
1 parent 4ba538e commit 045987866592375a3608509981f48c4276eb9ef1
@@ -52,4 +52,30 @@ sub create {
}, $schema, $args, $item);
}
+sub activate {
+ my ($self, $args) = @_;
+
+ my $schema = Pixis::Registry->get(schema => 'Master');
+ $schema->txn_do( sub {
+ $self->resultset->search(
+ { id => $args->{jpa_member_id} }
+ )->update(
+ { is_active => 1 }
+ );
+ } );
+}
+
+sub deactivate {
+ my ($self, $args) = @_;
+
+ my $schema = Pixis::Registry->get(schema => 'Master');
+ $schema->txn_do( sub {
+ $self->resultset->search(
+ { id => $args->{jpa_member_id} }
+ )->update(
+ { is_active => 0 }
+ );
+ } );
+}
+
1;
@@ -11,20 +11,72 @@ sub list :Local :Args(0) :FormConfig {
my $list;
my $form = $c->stash->{form};
- if ($form->submitted_and_valid) {
- my $params = $form->params;
- my $attrs = {};
- foreach my $field qw(limit page offset) {
- next unless exists $params->{$field};
- $attrs->{$field} = $params->{$field};
+ if ($form->submitted) {
+ if (! $form->valid) {
+ $form->force_error_message(1);
+ } else {
+ my %params = %{$form->params};
+ my $attrs = {};
+ delete $params{submit};
+ delete $params{view};
+ foreach my $field qw(limit page offset) {
+ next unless exists $params{$field};
+ $attrs->{$field} = delete $params{$field};
+ }
+ $list = $c->registry(api => 'JPAMember')->search(\%params, $attrs);
}
- $list = $c->registry(api => 'JPAMember')->search($params, $attrs);
} else {
$list = $c->registry(api => 'JPAMember')->search(undef, { limit => 20, page => 1 });
}
-use Data::Dumper;
-warn Dumper($list);
$c->stash->{list} = $list;
+
+ my $view = $form->param("view") || 'HTML';
+ if ($view eq 'HTML') {
+ $c->forward('View::TT');
+ } elsif ($view eq 'CSV') {
+ my $csv = [
+ map { [
+ join(' ', $_->lastname, $_->firstname),
+ $_->member_id,
+ $_->is_active
+ ] } @$list
+ ];
+ $c->stash->{csv} = { data => $csv };
+ $c->forward('View::CSV');
+ } else {
+ $c->forward('View::TT');
+ }
+}
+
+sub load_member :Chained :PathPart("admin/jpa/member") CaptureArgs(1) {
+ my ($self, $c, $jpa_member_id) = @_;
+
+ $c->stash->{jpa_member} = $c->registry(api => 'JPAMember')->find($jpa_member_id);
+ $c->stash->{member} = $c->registry(api => 'Member')->find(
+ $c->stash->{jpa_member}->member_id
+ );
+}
+
+sub view :Chained("load_member") :PathPart('') :Args(0) {}
+
+sub disable :Chained("load_member") :Args(0) {
+ my ($self, $c) = @_;
+
+ $c->registry(api => 'JPAMember')->deactivate({
+ jpa_member_id => $c->stash->{jpa_member}->id
+ });
+ $c->stash->{jpa_member}->is_active(0);
+ $c->res->redirect($c->uri_for('/admin/jpa/member', $c->stash->{jpa_member}->id));
+}
+
+sub enable :Chained("load_member") :Args(0) {
+ my ($self, $c) = @_;
+
+ $c->registry(api => 'JPAMember')->activate({
+ jpa_member_id => $c->stash->{jpa_member}->id
+ });
+ $c->stash->{jpa_member}->is_active(1);
+ $c->res->redirect($c->uri_for('/admin/jpa/member', $c->stash->{jpa_member}->id));
}
1;
@@ -1,6 +1,26 @@
[% WRAPPER wrapper.tt %]
-[% USE dumper %]
+<h1>メンバー</h1>
+
+[% form %]
+
+<table>
+<tr>
+ <td>姓名</td>
+ <td>PixisメンバーID</td>
+ <td>会員ステータス</td>
+ <td>会員費/学生証確認</td>
+</tr>
[% FOREACH member IN list %]
-[% dumper.dump_html(member) %]
+<tr>
+ <td><a href="[% c.uri_for("/admin/jpa/member", member.id) %]">[% member.lastname %] [% member.firstname %]</a></td>
+ <td><a href="[% c.uri_for("/member", member.member_id) %]">[% member.member_id %]</a></td>
+ <td>[% IF member.is_active -%]
+ <span style="color:blue">有効</span> [<a href="[% c.uri_for("/admin/jpa/member", member.id, "disable") %]">無効化</a>]
+ [%- ELSE -%]
+ <span style="color:red">無効</span> [<a href="[% c.uri_for("/admin/jpa/member", member.id, "enable") %]">有効化</a>]
+ [%- END %]
+ </td>
+</tr>
[% END %]
+</table>
[% END %]
@@ -0,0 +1,25 @@
+[% WRAPPER wrapper.tt %]
+
+<h1>[% jpa_member.lastname %] [% jpa_member.firstname %]</h1>
+
+<table>
+<tr>
+ <td>姓</td>
+ <td>[% jpa_member.lastname %]</td>
+</tr>
+<tr>
+ <td>名</td>
+ <td>[% jpa_member.firstname %]</td>
+</tr>
+<tr>
+ <td>会員ステータス</td>
+ <td>[% IF jpa_member.is_active -%]
+ <span style="color:blue">有効</span> [<a href="[% c.uri_for("/admin/jpa/member", jpa_member.id, "disable") %]">無効化</a>]
+ [%- ELSE -%]
+ <span style="color:red">無効</span> [<a href="[% c.uri_for("/admin/jpa/member", jpa_member.id, "enable") %]">有効化</a>]
+ [%- END %]
+ </td>
+</tr>
+</table>
+
+[% END %]
@@ -1,13 +1,28 @@
---
+auto_fieldset: 1
+
elements:
- type: Select
name: limit
+ label_loc: Entries Per Page
options:
- [ 10, 10 ]
- [ 25, 25 ]
- [ 50, 50 ]
- [ 75, 75 ]
- [ 100, 100 ]
- - type: Hidden
+ - type: Text
name: page
+ label_loc: Page
default: 1
+ - type: Radiogroup
+ label_loc: Output Format
+ name: view
+ options:
+ - [ 'HTML', 'HTML' ]
+ - [ 'CSV', 'CSV' ]
+ default: HTML
+ - type: Submit
+ name: submit
+ value_loc: Submit
+

0 comments on commit 0459878

Please sign in to comment.