OSDN Git Service

fix story editor to work
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Web / Controller / Admin / Story.pm
1 package Newslash::Web::Controller::Admin::Story;
2 use Mojo::Base 'Mojolicious::Controller';
3 use Mojo::Util qw(dumper);
4
5 sub edit {
6     my $c = shift;
7     my $users = $c->model('users');
8     my $authors = $users->select(author => 1);
9
10     my $sub_id = $c->param('subid');
11     my $stoid = $c->param('stoid');
12     my $source = {};
13     my $page = {};
14
15     if ($stoid) {
16         my $story = $c->model('stories')->select(stoid => $stoid);
17         if ($story) {
18             $source->{type} = "story";
19             $source->{id} = $stoid;
20             $source->{item} = $story;
21             $page->{type} = "story";
22             $page->{stoid} = $stoid;
23         }
24     }
25     elsif ($sub_id) {
26         my $sub = $c->model('submissions')->select(submission_id => $sub_id);
27         if ($sub) {
28             $source->{type} = "submission";
29             $source->{id} = $sub_id;
30             $source->{item} = $sub;
31         }
32     }
33
34     $c->render(authors => $authors, source => $source, page => $page);
35 }
36
37
38 1;
39