/[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 20 by dpavlin, Fri Nov 30 17:50:34 2007 UTC revision 23 by dpavlin, Fri Nov 30 23:23:14 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    
36            if ( $editing ) {
37                    form {
38                            outs_raw($delete->button(
39                                    label => _('Delete'),
40                                    class => 'float-crud-button',
41                                    onclick => {
42                                            submit => $delete,
43                                            confirm => _('Really delete?'),
44    #                                       region => Jifty->web->current_region,
45                                            replace_with => '/__jifty/empty',
46                                            refresh_self => 1,
47                                            args => { id => $id },
48                                    },
49                            ));
50                    };
51            };
52    
53          form {          form {
54                  foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) {                  foreach my $f ( $self->display_columns ) {
55                          if ( $f eq 'material' ) {                          if ( $f eq 'material' ) {
56                                  set( search_collection => $record->material );                                  set( search_collection => $record->material );
57                                  render_region(                                  render_region(
# Line 35  template 'view' => sub :CRUDView { Line 64  template 'view' => sub :CRUDView {
64                                  );                                  );
65                          } else {                          } else {
66                                  my %opt;                                  my %opt;
67                                  $opt{render_mode} = 'read' if ! $can_write;                                  $opt{render_mode} = 'read' if ! $editing;
68                                  render_param( $update => $f, %opt );                                  render_param( $update => $f, %opt );
69                          }                          }
70                  };                  };
71                  if ( $can_write ) {                  if ( $editing ) {
72                          div {                          div {
73                                  { class is 'submit_button' };                                  { class is 'submit_button' };
74                                  hyperlink(                                  hyperlink(
# Line 55  template 'view' => sub :CRUDView { Line 84  template 'view' => sub :CRUDView {
84          hr {};          hr {};
85  };  };
86    
87    template 'new_item' => sub {
88            my $self = shift;
89            return unless $self->current_user->editing;
90    
91        my ( $object_type, $id ) = ( $self->object_type, get('id') );
92        my $record_class = $self->record_class;
93        my $create = $record_class->as_create_action;
94    
95            h1 { _("New unit") };
96    
97            form {
98    
99                    foreach my $f ( $self->display_columns ) {
100                            render_param( $create => $f ) unless $f eq 'material';
101                    }
102    
103                    div {
104                            { class is 'submit_button' };
105                            hyperlink(
106                                    label   => _("Add"),
107                                    onclick => [
108                                            {
109                                                    submit => $create,
110            #                                       args => {
111            #                                       },
112                                            },
113                                            {       refresh_self => 1       },
114                                            {
115                                                    element => Jifty->web->current_region->parent->get_element( 'div.list' ),
116                                                    append => $self->fragment_for('view'),
117                                                    args => {
118                                                            object_type => $object_type,
119                                                            id => { result_of => $create, name => 'id' },
120                                                            unit => get('unit'),
121                                                    },
122                                            },
123                                    ],
124                                    as_button => 1,
125                            );
126                    }
127    
128            };
129    };
130    
131  1;  1;

Legend:
Removed from v.20  
changed lines
  Added in v.23

  ViewVC Help
Powered by ViewVC 1.1.26