/[Arh]/lib/Arh/View.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/Arh/View.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 78 - (show annotations)
Sat Apr 19 21:36:07 2008 UTC (12 years, 2 months ago) by dpavlin
File size: 2226 byte(s)
display last x (selectable by /?last=number) units entered into system
with quick link for view (if not logged in) or edit (if logged in)
1 package Arh::View;
2
3 use strict;
4 use warnings;
5
6 use Jifty::View::Declare -base;
7
8 use Data::Dump qw/dump/;
9
10 use Jifty::View::Declare::CRUD;
11 Jifty::View::Declare::CRUD->mount_view('Materials');
12 Jifty::View::Declare::CRUD->mount_view('UnitPictures');
13 Jifty::View::Declare::CRUD->mount_view('Units');
14 Jifty::View::Declare::CRUD->mount_view('Units', 'Arh::View::Units', '/units/bulk' );
15 #Jifty::View::Declare::CRUD->mount_view('locations');
16
17 template '/units' => page {
18 h1 { _("Units available in system") };
19
20 my $search = Arh::Model::UnitCollection->new;
21 $search->unlimit;
22
23 show( 'toggle_edit' ) if $search->count;
24
25 set( search_collection => $search );
26 render_region(
27 name => 'units',
28 path => '/units/list',
29 defaults => {
30 page => 1,
31 per_page => get('per_page'),
32 }
33 );
34
35 };
36
37 template 'toggle_edit' => sub {
38 my $self = shift;
39
40 # don't show editing for anonymous users
41 return unless $self->current_user->id;
42
43 my $toggleedit = new_action(
44 class => 'ToggleEdit',
45 # moniker => 'toggle-edit',
46 );
47
48 my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing");
49
50 warn "## $label\n";
51
52 form {
53 outs_raw( $toggleedit->button(
54 label => $label,
55 submit => $toggleedit,
56 ));
57 }
58
59 };
60
61 template 'raw_pic' => sub {
62 my $filename = get('filename') or die "no filename?";
63 my $image = Arh::Model::Picture->new;
64 $image->load_by_cols( filename => $filename );
65 if ( $image->id ) {
66 Jifty->handler->apache->content_type('image/jpg');
67 Jifty->web->out($image->content);
68 } else {
69 die "can't find picture $filename";
70 }
71 };
72
73 template '/index.html' => page {
74 my $units = Arh::Model::UnitCollection->new;
75 $units->unlimit;
76 $units->order_by( column => 'id', order => 'DESC' );
77
78 my $last = get('last') || 15;
79
80 h1 { _("Last %1 units entered", $last) };
81
82 ol {
83 class is 'units';
84 for ( 1 .. $last ) {
85 my $unit = $units->next || last;
86 li {
87 outs( $unit->name, ' ' );
88 hyperlink(
89 label => $unit->unit_id,
90 url => '/units/single?id=' . $unit->id,
91 );
92 span { class is 'unit details';
93 outs join(', ', grep(defined($_),
94 $unit->subcategory,
95 $unit->category->name,
96 $unit->location->name,
97 $unit->site->name,
98 ));
99 }
100 }
101 }
102 }
103
104 };
105
106 1;

  ViewVC Help
Powered by ViewVC 1.1.26