1 |
package Perly::View; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use Jifty::View::Declare -base; |
7 |
|
8 |
template '/' => page { |
9 |
h1 { _("Enter your code") } |
10 |
div { show 'code_editor' } |
11 |
}; |
12 |
|
13 |
private template 'code_editor' => sub { |
14 |
my $content; |
15 |
my $op = 'Create'; |
16 |
my $id; |
17 |
if ( $id = get 'id' ) { |
18 |
my $code = Perly::Model::Code->new(); |
19 |
$code->load( $id ) or die "can't load $id"; |
20 |
$content = $code->source; |
21 |
warn "loaded ", length( $content ), " bytes"; |
22 |
$op = 'Update'; |
23 |
} |
24 |
form { |
25 |
my $action = new_action( class => $op . 'Code', arguments => { id => $id, source => $content }, ); |
26 |
render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => 'Jifty::Plugin::CodePress::Textarea' ); |
27 |
#render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] ); |
28 |
form_submit( |
29 |
label => _($op), |
30 |
onclick => [ |
31 |
{ beforeclick => "CodePress.beforeSubmit();" }, |
32 |
], |
33 |
); |
34 |
} |
35 |
}; |
36 |
|
37 |
template '/upload' => page { |
38 |
h1 { _("Upload new file") }, |
39 |
form { |
40 |
my $action = new_action( class => 'Upload' ); |
41 |
render_action( $action => [ 'content', 'file', 'format' ] ); |
42 |
form_submit( |
43 |
label => _('Upload'), |
44 |
); |
45 |
} |
46 |
}; |
47 |
|
48 |
1; |