/[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 58 by dpavlin, Mon Apr 7 09:11:56 2008 UTC
# Line 6  use warnings; Line 6  use warnings;
6  use base 'Jifty::View::Declare::CRUD';  use base 'Jifty::View::Declare::CRUD';
7  use Jifty::View::Declare -base;  use Jifty::View::Declare -base;
8    
9    use Data::Dump qw/dump/;
10    
11  sub object_type { 'Unit' };  sub object_type { 'Unit' };
12    
13    sub display_columns {
14            my $self = shift;
15            return ( qw/
16                    unit_id
17                    name
18                    subcategory
19                    category
20                    site
21                    gps
22                    placement
23                    context
24                    discovery
25                    function
26                    reusage
27                    ownership
28                    presevation_place
29                    inventory_nr
30                    dimensions
31                    condition
32                    toplogy
33                    technique
34                    description
35                    construction
36                    iconography
37                    decoration
38                    motifs
39                    inscription
40                    language
41                    font
42                    author
43                    chronology
44                    chronostyle
45                    explored
46                    conservations
47                    restorations
48                    legal
49                    links
50                    sources
51                    bibliography
52                    copyright
53            / );
54    }
55    
56  #private template search_region => sub {};  #private template search_region => sub {};
57    
58  template 'view' => sub :CRUDView {  template 'view' => sub :CRUDView {
59          my $self   = shift;          my $self   = shift;
60          my $record = $self->_get_record( get('id') );          my $id = get('id');
61            my $record = $self->_get_record( $id );
62    
63          my $update = $record->as_update_action(          my $update = $record->as_update_action(
64                  moniker => "update-" . Jifty->web->serial,                  moniker => "update-" . Jifty->web->serial,
65          );          );
66    
67          my $can_write = $record->current_user_can('write');          my $delete = $record->as_delete_action(
68          #warn "write ",$can_write ? 'ok' : 'DENIED';                  moniker => "delete-" . Jifty->web->serial,
69            );
70            my $editing = $record->current_user_can('write');
71            warn "## current_user_can('write') = $editing\n";
72            $editing = 0 unless $self->current_user->editing;
73            warn "## editing ",$editing ? 'ok' : 'DENIED';
74    
75            div { { class is 'unit' }
76    
77            if ( $editing ) {
78                    form {
79                            outs_raw($delete->button(
80                                    label => _('Delete unit'),
81                                    class => 'float-crud-button button-delete',
82                                    onclick => {
83                                            submit => $delete,
84                                            confirm => _('Really delete?'),
85    #                                       region => Jifty->web->current_region,
86                                            replace_with => '/__jifty/empty',
87                                            refresh_self => 1,
88                                            args => { id => $id },
89                                    },
90                            ));
91                    };
92            };
93    
94    
95          form {          form {
96                  foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) {                  foreach my $f ( $self->display_columns ) {
97                          if ( $f eq 'material' ) {                          if ( $f eq 'material' ) {
98                                  set( search_collection => $record->material );                                  set( search_collection => $record->material );
99                                  render_region(                                  render_region(
# Line 35  template 'view' => sub :CRUDView { Line 106  template 'view' => sub :CRUDView {
106                                  );                                  );
107                          } else {                          } else {
108                                  my %opt;                                  my %opt;
109                                  $opt{render_mode} = 'read' if ! $can_write;                                  if ( ! $editing ) {
110                                            $opt{render_mode} = 'read';
111                                            # skip fields without values
112                                            $opt{render_as} = 'hidden' if ! defined( $update->record->$f );
113                                    }
114                                  render_param( $update => $f, %opt );                                  render_param( $update => $f, %opt );
115                          }                          }
116                  };                  };
117                  hyperlink(                  if ( $editing ) {
118                          label => _('Update'),                          div {
119                          onclick => {                                  { class is 'submit_button' };
120                                  submit => $update,                                  hyperlink(
121                                  refresh_self => 1,                                          label => _('Update'),
122                          },                                          onclick => {
123                  ) if $can_write;                                                  submit => $update,
124                                                    refresh_self => 1,
125                                            },
126                                    )
127                            };
128                    }
129          };          };
130    
131            }; # div class unit
132    
133            show('/unitpictures/fragment', $record);
134    
135          hr {};          hr {};
136  };  };
137    
138    template 'new_item' => sub {
139            my $self = shift;
140            return unless $self->current_user->editing;
141    
142        my ( $object_type, $id ) = ( $self->object_type, get('id') );
143        my $record_class = $self->record_class;
144        my $create = $record_class->as_create_action;
145    
146            h1 { _("New unit") };
147    
148            form {
149    
150                    foreach my $f ( $self->display_columns ) {
151    #                       last if $f eq 'material' && ! $id;
152                            render_param( $create => $f ); # unless $f eq 'material';
153                            #warn "## $f";
154                    }
155    
156                    div {
157                            { class is 'submit_button' };
158                            hyperlink(
159                                    label   => _("Add"),
160                                    onclick => [
161                                            {
162                                                    submit => $create,
163    #                                               args => {
164    #                                               },
165                                            },
166                                            {       refresh_self => 1       },
167                                            {
168                                                    element => Jifty->web->current_region->parent->get_element( 'div.list' ),
169                                                    append => $self->fragment_for('view'),
170                                                    args => {
171                                                            object_type => $object_type,
172                                                            id => { result_of => $create, name => 'id' },
173                                                            unit => get('unit'),
174                                                    },
175                                            },
176                                    ],
177                                    as_button => 1,
178                            );
179                    }
180    
181            };
182    };
183    
184  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26