/[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 23 - (show annotations)
Fri Nov 30 23:23:14 2007 UTC (11 years, 10 months ago) by dpavlin
File size: 2907 byte(s)
another huge code dump:
- rename database columns to prevent conficts with standards
- added editing accessor to user which returns edit mode
- ToggleEdit action to change editing state (broken)
- tweaks all over templates to make units entry a breeze
- version bump [0.03]
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 $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 "## unit $unit";
63
64 div {
65 { class is 'form_field' };
66 if ( $record->current_user_can('update') && $self->current_user->editing ) {
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 return unless $self->current_user->editing;
85
86 my ( $object_type, $id, $unit ) = ( $self->object_type, get('id'), get('unit') );
87 my $record_class = $self->record_class;
88 my $create = $record_class->as_create_action(
89 moniker => "create-" . Jifty->web->serial,
90 );
91 warn "## unit $unit";
92
93 my $attach_to =
94 Jifty->web->current_region->parent ?
95 Jifty->web->current_region->parent->get_element( 'div.list' ) :
96 Jifty->web->current_region;
97
98 warn "## attach_to = $attach_to";
99
100 div {
101 { class is 'form_field' };
102 hyperlink(
103 label => _("Add"),
104 class => "float-crud-button",
105 onclick => [
106 {
107 submit => $create,
108 },
109 { refresh_self => 1 },
110 {
111 element => $attach_to,
112 append => $self->fragment_for('view'),
113 args => {
114 object_type => $object_type,
115 id => { result_of => $create, name => 'id' },
116 },
117 },
118 ],
119 as_button => 1,
120 );
121 render_param($create => 'material');
122 outs_raw( $create->hidden( unit => $unit ) );
123 };
124 };
125
126
127 1;

  ViewVC Help
Powered by ViewVC 1.1.26