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

Diff of /lib/Arh/View/Units.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 15 by dpavlin, Fri Nov 30 16:46:39 2007 UTC revision 28 by dpavlin, Mon Dec 10 14:56:12 2007 UTC
# Line 8  use Jifty::View::Declare -base; Line 8  use Jifty::View::Declare -base;
8    
9  sub object_type { 'Unit' };  sub object_type { 'Unit' };
10    
11    sub display_columns {
12            my $self = shift;
13            return ( qw/name inv_id campaign material dimensions discovered_at description chronology location/ );
14    }
15    
16  #private template search_region => sub {};  #private template search_region => sub {};
17    
18  template 'view' => sub :CRUDView {  template 'view' => sub :CRUDView {
19          my $self   = shift;          my $self   = shift;
20          my $record = $self->_get_record( get('id') );          my $id = get('id');
21            my $record = $self->_get_record( $id );
22    
23          my $update = $record->as_update_action(          my $update = $record->as_update_action(
24                  moniker => "update-" . Jifty->web->serial,                  moniker => "update-" . Jifty->web->serial,
25          );          );
26    
27          my $can_write = $record->current_user_can('write');          my $delete = $record->as_delete_action(
28          #warn "write ",$can_write ? 'ok' : 'DENIED';                  moniker => "delete-" . Jifty->web->serial,
29            );
30            my $editing = $record->current_user_can('write');
31            warn "## current_user_can('write') = $editing\n";
32            $editing = 0 unless $self->current_user->editing;
33            warn "## editing ",$editing ? 'ok' : 'DENIED';
34    
35            div { { class is 'unit' }
36    
37            if ( $editing ) {
38                    form {
39                            outs_raw($delete->button(
40                                    label => _('Delete unit'),
41                                    class => 'float-crud-button button-delete',
42                                    onclick => {
43                                            submit => $delete,
44                                            confirm => _('Really delete?'),
45    #                                       region => Jifty->web->current_region,
46                                            replace_with => '/__jifty/empty',
47                                            refresh_self => 1,
48                                            args => { id => $id },
49                                    },
50                            ));
51                    };
52            };
53    
54    
55          form {          form {
56                  foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) {                  foreach my $f ( $self->display_columns ) {
57                          if ( $f eq 'material' ) {                          if ( $f eq 'material' ) {
58                                  set( search_collection => $record->material );                                  set( search_collection => $record->material );
59                                  render_region(                                  render_region(
# Line 35  template 'view' => sub :CRUDView { Line 66  template 'view' => sub :CRUDView {
66                                  );                                  );
67                          } else {                          } else {
68                                  my %opt;                                  my %opt;
69                                  $opt{render_mode} = 'read' if ! $can_write;                                  $opt{render_mode} = 'read' if ! $editing;
70                                  render_param( $update => $f, %opt );                                  render_param( $update => $f, %opt );
71                          }                          }
72                  };                  };
73                  hyperlink(                  if ( $editing ) {
74                          label => _('Update'),                          div {
75                          onclick => {                                  { class is 'submit_button' };
76                                  submit => $update,                                  hyperlink(
77                                  refresh_self => 1,                                          label => _('Update'),
78                          },                                          onclick => {
79                  ) if $can_write;                                                  submit => $update,
80                                                    refresh_self => 1,
81                                            },
82                                    )
83                            };
84                    }
85          };          };
86    
87            }; # div class unit
88    
89            show('/unitpictures/fragment', $record);
90    
91          hr {};          hr {};
92  };  };
93    
94    template 'new_item' => sub {
95            my $self = shift;
96            return unless $self->current_user->editing;
97    
98        my ( $object_type, $id ) = ( $self->object_type, get('id') );
99        my $record_class = $self->record_class;
100        my $create = $record_class->as_create_action;
101    
102            h1 { _("New unit") };
103    
104            form {
105    
106                    foreach my $f ( $self->display_columns ) {
107                            last if $f eq 'material' && ! $id;
108                            render_param( $create => $f ); # unless $f eq 'material';
109                    }
110    
111                    div {
112                            { class is 'submit_button' };
113                            hyperlink(
114                                    label   => _("Add"),
115                                    onclick => [
116                                            {
117                                                    submit => $create,
118            #                                       args => {
119            #                                       },
120                                            },
121                                            {       refresh_self => 1       },
122                                            {
123                                                    element => Jifty->web->current_region->parent->get_element( 'div.list' ),
124                                                    append => $self->fragment_for('view'),
125                                                    args => {
126                                                            object_type => $object_type,
127                                                            id => { result_of => $create, name => 'id' },
128                                                            unit => get('unit'),
129                                                    },
130                                            },
131                                    ],
132                                    as_button => 1,
133                            );
134                    }
135    
136            };
137    };
138    
139  1;  1;

Legend:
Removed from v.15  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26