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

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

  ViewVC Help
Powered by ViewVC 1.1.26