line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::Form::TimelineUpdate; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13370969
|
use meon::Web::Util; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use meon::Web::TimelineEntry; |
5
|
|
|
|
|
|
|
use meon::Web::XML2Comment; |
6
|
|
|
|
|
|
|
use Path::Class 'dir'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use utf8; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use HTML::FormHandler::Moose; |
11
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
12
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has '+name' => (default => 'form-timeline-update'); |
15
|
|
|
|
|
|
|
has '+widget_wrapper' => ( default => 'Bootstrap' ); |
16
|
|
|
|
|
|
|
has '+enctype' => ( default => 'multipart/form-data'); |
17
|
|
|
|
|
|
|
sub build_form_element_class { ['form-horizontal'] }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has_field 'category' => ( |
20
|
|
|
|
|
|
|
type => 'Select', required => 1, label => 'Category', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has_field 'title' => ( |
24
|
|
|
|
|
|
|
type => 'Text', required => 1, label => 'Title', |
25
|
|
|
|
|
|
|
element_attr => { placeholder => 'title or a short message' } |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has_field 'intro' => ( |
29
|
|
|
|
|
|
|
type => 'TextArea', required => 0, label => 'Introduction', |
30
|
|
|
|
|
|
|
rows => '3', |
31
|
|
|
|
|
|
|
element_attr => { placeholder => 'short text or introduction' } |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has_field 'text' => ( |
35
|
|
|
|
|
|
|
type => 'TextArea', required => 0, label => 'Body text', |
36
|
|
|
|
|
|
|
element_attr => { placeholder => 'long text' } |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has_field 'image' => ( |
40
|
|
|
|
|
|
|
type => 'Upload', required => 0, label => 'Image', |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has_field 'attachment' => ( |
44
|
|
|
|
|
|
|
type => 'Upload', required => 0, label => 'File Upload', |
45
|
|
|
|
|
|
|
max_size => 1024*10_000, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has_field 'link' => ( |
49
|
|
|
|
|
|
|
type => 'Text', required => 0, label => 'Web Link', |
50
|
|
|
|
|
|
|
element_attr => { placeholder => 'http://' } |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has_field 'source_link' => ( |
54
|
|
|
|
|
|
|
type => 'Text', required => 0, label => 'Source Link', |
55
|
|
|
|
|
|
|
element_attr => { placeholder => 'http://' } |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has_field 'audio' => ( |
59
|
|
|
|
|
|
|
type => 'Text', required => 0, label => 'Audio Widget Code', |
60
|
|
|
|
|
|
|
element_attr => { placeholder => '<iframe ⦠>' } |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has_field 'video' => ( |
64
|
|
|
|
|
|
|
type => 'Text', required => 0, label => 'Video Widget Code', |
65
|
|
|
|
|
|
|
element_attr => { placeholder => '<iframe ⦠>' } |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
has_field 'quote_author' => ( |
69
|
|
|
|
|
|
|
type => 'Text', required => 0, label => 'Author', |
70
|
|
|
|
|
|
|
element_attr => { placeholder => 'author name' } |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has_field 'submit' => ( |
74
|
|
|
|
|
|
|
type => 'Submit', |
75
|
|
|
|
|
|
|
value => 'Post', |
76
|
|
|
|
|
|
|
element_class => 'btn btn-primary', |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub entry_fields { |
80
|
|
|
|
|
|
|
return qw(category title intro text image attachment link source_link audio video quote_author); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub submitted { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $c = $self->c; |
87
|
|
|
|
|
|
|
my %fields = map { |
88
|
|
|
|
|
|
|
$_ => $self->field($_)->value |
89
|
|
|
|
|
|
|
} $self->entry_fields; |
90
|
|
|
|
|
|
|
my $comment_to_uri = $c->stash->{back_link}; |
91
|
|
|
|
|
|
|
my $comment_to; |
92
|
|
|
|
|
|
|
if ($comment_to_uri) { |
93
|
|
|
|
|
|
|
$fields{category} = 'comment'; |
94
|
|
|
|
|
|
|
$comment_to = meon::Web::XML2Comment->new( |
95
|
|
|
|
|
|
|
path => $comment_to_uri, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
for my $upload_name (qw(image attachment)) { |
100
|
|
|
|
|
|
|
next unless defined $fields{$upload_name}; |
101
|
|
|
|
|
|
|
$fields{$upload_name} = $c->req->upload($upload_name); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $timeline_path = $self->get_config_text('timeline'); |
105
|
|
|
|
|
|
|
my $timeline_full_path = dir(meon::Web::Util->full_path_fixup($timeline_path)); |
106
|
|
|
|
|
|
|
my $entry = meon::Web::TimelineEntry->new( |
107
|
|
|
|
|
|
|
timeline_dir => $timeline_full_path, |
108
|
|
|
|
|
|
|
author => $c->user->username, |
109
|
|
|
|
|
|
|
( |
110
|
|
|
|
|
|
|
map { |
111
|
|
|
|
|
|
|
my $val = $fields{$_}; |
112
|
|
|
|
|
|
|
(defined($val) ? ($_ => $val) : ()), |
113
|
|
|
|
|
|
|
} ($self->entry_fields) |
114
|
|
|
|
|
|
|
), |
115
|
|
|
|
|
|
|
(defined($comment_to) ? (comment_to => $comment_to) : ()), |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
$entry->create; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$self->redirect($comment_to_uri // $timeline_path); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub options_category { |
123
|
|
|
|
|
|
|
my $self = shift; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
126
|
|
|
|
|
|
|
my $form_config = $self->config; |
127
|
|
|
|
|
|
|
my @options = map { |
128
|
|
|
|
|
|
|
+{ value => $_->getAttribute('value'), label => $_->textContent }, |
129
|
|
|
|
|
|
|
} $xpc->findnodes('w:category/w:option',$form_config); |
130
|
|
|
|
|
|
|
return \@options |
131
|
|
|
|
|
|
|
if @options; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
return [ |
134
|
|
|
|
|
|
|
{ value => 'news', label => "News" }, |
135
|
|
|
|
|
|
|
{ value => 'thought', label => "Thought" }, |
136
|
|
|
|
|
|
|
{ value => 'question', label => "Question" }, |
137
|
|
|
|
|
|
|
]; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |