/[Arh]/lib/Arh/View/Materials.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

Annotation of /lib/Arh/View/Materials.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (hide annotations)
Mon Dec 10 14:56:12 2007 UTC (16 years, 4 months ago) by dpavlin
File size: 3021 byte(s)
added UnitPicture model, first try at user interface for it
1 dpavlin 15 package Arh::View::Materials;
2    
3     use strict;
4     use warnings;
5    
6     use base 'Jifty::View::Declare::CRUD';
7     use Jifty::View::Declare -base;
8    
9     sub object_type { 'UnitMaterial' };
10    
11     private template search_region => sub {};
12 dpavlin 18 private template 'no_items_found' => sub {};
13 dpavlin 15
14     sub display_columns {
15     my $self = shift;
16     return ('material');
17     }
18    
19     sub edit_columns {
20     my $self = shift;
21 dpavlin 18 return ('material');
22 dpavlin 15 }
23    
24 dpavlin 16 template 'list' => sub {
25     my $self = shift;
26    
27     my ( $page, $unit ) = get(qw(page unit));
28     my $item_path = get('item_path') || $self->fragment_for("view");
29     my $fragment_for_new_item = get('fragment_for_new_item') || $self->fragment_for('new_item');
30     my $collection = $self->_current_collection();
31     # XXX show just materials from current unit
32     $collection->limit( column => 'unit', value => $unit ) if $unit;
33     div {
34     { class is 'materials' };
35    
36     show('./search_region');
37     show( './paging_top', $collection, $page );
38     show( './list_items', $collection, $item_path );
39     show( './paging_bottom', $collection, $page );
40    
41     render_region(
42 dpavlin 23 name => 'new_item',
43     path => $fragment_for_new_item,
44 dpavlin 16 defaults => {
45     object_type => $self->object_type,
46     unit => $unit,
47     },
48     );
49     }
50    
51     };
52    
53 dpavlin 15 template 'view' => sub :CRUDView {
54     my $self = shift;
55 dpavlin 25 my ( $id, $unit ) = get(qw(id unit));
56     my $record = $self->_get_record( $id );
57 dpavlin 15
58 dpavlin 25 my $delete = $record->as_delete_action(
59     moniker => "delete-" . Jifty->web->serial,
60 dpavlin 15 );
61    
62 dpavlin 23 #warn "## unit $unit";
63 dpavlin 15
64 dpavlin 25
65 dpavlin 15 div {
66     { class is 'form_field' };
67 dpavlin 25 if ( $record->current_user_can('delete') && $self->current_user->editing ) {
68 dpavlin 15 hyperlink(
69 dpavlin 28 label => _("Delete material"),
70     class => "float-crud-button button-delete",
71 dpavlin 15 onclick => {
72 dpavlin 25 submit => $delete,
73     confirm => _('Really delete?'),
74     replace_with => '/__jifty/empty',
75     refresh_self => 1,
76     args => { id => $id },
77 dpavlin 15 },
78     as_button => 1,
79     );
80 dpavlin 25 };
81     label { { class is 'label' } _("Material") };
82     span { $record->material->name };
83 dpavlin 15 };
84    
85     };
86    
87     template 'new_item' => sub {
88     my $self = shift;
89 dpavlin 23 return unless $self->current_user->editing;
90 dpavlin 15
91 dpavlin 25 my ( $id, $unit ) = get(qw(id unit));
92 dpavlin 23 my $record_class = $self->record_class;
93     my $create = $record_class->as_create_action(
94     moniker => "create-" . Jifty->web->serial,
95     );
96     warn "## unit $unit";
97 dpavlin 15
98 dpavlin 23 my $attach_to =
99     Jifty->web->current_region->parent ?
100     Jifty->web->current_region->parent->get_element( 'div.list' ) :
101     Jifty->web->current_region;
102    
103     warn "## attach_to = $attach_to";
104    
105 dpavlin 15 div {
106     { class is 'form_field' };
107     hyperlink(
108 dpavlin 28 label => _("Add material"),
109     class => "float-crud-button button-add",
110 dpavlin 15 onclick => [
111     {
112     submit => $create,
113     },
114     { refresh_self => 1 },
115     {
116 dpavlin 23 element => $attach_to,
117 dpavlin 15 append => $self->fragment_for('view'),
118     args => {
119 dpavlin 25 object_type => $self->object_type,
120 dpavlin 15 id => { result_of => $create, name => 'id' },
121 dpavlin 25 unit => $unit,
122 dpavlin 15 },
123     },
124     ],
125     as_button => 1,
126     );
127     render_param($create => 'material');
128 dpavlin 23 outs_raw( $create->hidden( unit => $unit ) );
129     };
130 dpavlin 15 };
131    
132    
133     1;

  ViewVC Help
Powered by ViewVC 1.1.26