/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations)
Fri Nov 30 17:16:34 2007 UTC (11 years, 7 months ago) by dpavlin
File size: 2729 byte(s)
transfer unit so that we know which materials to display (just for unit)
1 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
13 sub display_columns {
14 my $self = shift;
15 return ('material');
16 }
17
18 sub edit_columns {
19 my $self = shift;
20 return ('unit','material');
21 }
22
23 template 'list' => sub {
24 my $self = shift;
25
26 my ( $page, $unit ) = get(qw(page unit));
27 my $item_path = get('item_path') || $self->fragment_for("view");
28 my $fragment_for_new_item = get('fragment_for_new_item') || $self->fragment_for('new_item');
29 my $collection = $self->_current_collection();
30 # XXX show just materials from current unit
31 $collection->limit( column => 'unit', value => $unit ) if $unit;
32 div {
33 { class is 'materials' };
34
35 show('./search_region');
36 show( './paging_top', $collection, $page );
37 show( './list_items', $collection, $item_path );
38 show( './paging_bottom', $collection, $page );
39
40 render_region(
41 name => 'new_item',
42 path => $fragment_for_new_item,
43 defaults => {
44 object_type => $self->object_type,
45 unit => $unit,
46 },
47 );
48 }
49
50 };
51
52 template 'view' => sub :CRUDView {
53 my $self = shift;
54 my $record = $self->_get_record( get('id') );
55
56 my $update = $record->as_update_action(
57 moniker => "update-" . Jifty->web->serial,
58 );
59
60 my $unit = get('unit');
61 warn "## new item for unit $unit";
62
63 div {
64 { class is 'form_field' };
65 if ( $record->current_user_can('update') ) {
66 hyperlink(
67 label => _("Edit"),
68 class => "float-crud-button",
69 onclick => {
70 replace_with => $self->fragment_for('update'),
71 args => { id => $record->id }
72 },
73 as_button => 1,
74 );
75 }
76 render_param( $update => 'material', render_mode => 'read' );
77 };
78
79 };
80
81 template 'new_item' => sub {
82 my $self = shift;
83 my ( $object_type, $id ) = ( $self->object_type, get('id') );
84
85 my $record_class = $self->record_class;
86 my $create = $record_class->as_create_action;
87 my $unit = get('unit');
88 warn "## new item for unit $unit";
89
90 div {
91 { class is 'form_field' };
92 hyperlink(
93 label => _("Add"),
94 class => "float-crud-button",
95 onclick => [
96 {
97 submit => $create,
98 args => {
99 unit => $unit,
100 },
101 },
102 { refresh_self => 1 },
103 {
104 element => Jifty->web->current_region->parent->get_element( 'div.list' ),
105 append => $self->fragment_for('view'),
106 args => {
107 object_type => $object_type,
108 id => { result_of => $create, name => 'id' },
109 },
110 },
111 ],
112 as_button => 1,
113 );
114 render_param($create => 'material');
115 render_param($create => 'unit', default_value => $unit, reader_as => 'hidden');
116 }
117 };
118
119
120 1;

  ViewVC Help
Powered by ViewVC 1.1.26