/[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 28 - (show annotations)
Mon Dec 10 14:56:12 2007 UTC (16 years, 3 months ago) by dpavlin
File size: 3021 byte(s)
added UnitPicture model, first try at user interface for it
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 private template 'no_items_found' => sub {};
13
14 sub display_columns {
15 my $self = shift;
16 return ('material');
17 }
18
19 sub edit_columns {
20 my $self = shift;
21 return ('material');
22 }
23
24 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 template 'view' => sub :CRUDView {
54 my $self = shift;
55 my ( $id, $unit ) = get(qw(id unit));
56 my $record = $self->_get_record( $id );
57
58 my $delete = $record->as_delete_action(
59 moniker => "delete-" . Jifty->web->serial,
60 );
61
62 #warn "## unit $unit";
63
64
65 div {
66 { class is 'form_field' };
67 if ( $record->current_user_can('delete') && $self->current_user->editing ) {
68 hyperlink(
69 label => _("Delete material"),
70 class => "float-crud-button button-delete",
71 onclick => {
72 submit => $delete,
73 confirm => _('Really delete?'),
74 replace_with => '/__jifty/empty',
75 refresh_self => 1,
76 args => { id => $id },
77 },
78 as_button => 1,
79 );
80 };
81 label { { class is 'label' } _("Material") };
82 span { $record->material->name };
83 };
84
85 };
86
87 template 'new_item' => sub {
88 my $self = shift;
89 return unless $self->current_user->editing;
90
91 my ( $id, $unit ) = get(qw(id unit));
92 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
98 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 div {
106 { class is 'form_field' };
107 hyperlink(
108 label => _("Add material"),
109 class => "float-crud-button button-add",
110 onclick => [
111 {
112 submit => $create,
113 },
114 { refresh_self => 1 },
115 {
116 element => $attach_to,
117 append => $self->fragment_for('view'),
118 args => {
119 object_type => $self->object_type,
120 id => { result_of => $create, name => 'id' },
121 unit => $unit,
122 },
123 },
124 ],
125 as_button => 1,
126 );
127 render_param($create => 'material');
128 outs_raw( $create->hidden( unit => $unit ) );
129 };
130 };
131
132
133 1;

  ViewVC Help
Powered by ViewVC 1.1.26