/[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 18 - (hide annotations)
Fri Nov 30 17:35:59 2007 UTC (16 years, 4 months ago) by dpavlin
File size: 2767 byte(s)
- don't show anything if there is no items
- show just material when adding 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     name => 'new_item',
43     path => $fragment_for_new_item,
44     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     my $record = $self->_get_record( get('id') );
56    
57     my $update = $record->as_update_action(
58     moniker => "update-" . Jifty->web->serial,
59     );
60    
61     my $unit = get('unit');
62     warn "## new item for unit $unit";
63    
64     div {
65     { class is 'form_field' };
66     if ( $record->current_user_can('update') ) {
67     hyperlink(
68     label => _("Edit"),
69     class => "float-crud-button",
70     onclick => {
71     replace_with => $self->fragment_for('update'),
72     args => { id => $record->id }
73     },
74     as_button => 1,
75     );
76     }
77     render_param( $update => 'material', render_mode => 'read' );
78     };
79    
80     };
81    
82     template 'new_item' => sub {
83     my $self = shift;
84     my ( $object_type, $id ) = ( $self->object_type, get('id') );
85    
86     my $record_class = $self->record_class;
87     my $create = $record_class->as_create_action;
88     my $unit = get('unit');
89     warn "## new item for unit $unit";
90    
91     div {
92     { class is 'form_field' };
93     hyperlink(
94     label => _("Add"),
95     class => "float-crud-button",
96     onclick => [
97     {
98     submit => $create,
99     args => {
100 dpavlin 16 unit => $unit,
101 dpavlin 15 },
102     },
103     { refresh_self => 1 },
104     {
105     element => Jifty->web->current_region->parent->get_element( 'div.list' ),
106     append => $self->fragment_for('view'),
107     args => {
108     object_type => $object_type,
109     id => { result_of => $create, name => 'id' },
110     },
111     },
112     ],
113     as_button => 1,
114     );
115     render_param($create => 'material');
116     render_param($create => 'unit', default_value => $unit, reader_as => 'hidden');
117     }
118     };
119    
120    
121     1;

  ViewVC Help
Powered by ViewVC 1.1.26