/[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 66 by dpavlin, Tue Apr 8 21:34:16 2008 UTC revision 77 by dpavlin, Fri Apr 18 16:17:31 2008 UTC
# Line 10  use Data::Dump qw/dump/; Line 10  use Data::Dump qw/dump/;
10    
11  sub object_type { 'Unit' };  sub object_type { 'Unit' };
12    
13  sub per_page { get('per_page') || 5 };  sub per_page {
14            my $per_page = get('per_page') || 3;
15            warn "## Units per_page = $per_page\n";
16            return $per_page;
17    };
18    
19  sub display_columns {  sub display_columns {
20          my $self = shift;          my $self = shift;
# Line 58  sub display_columns { Line 62  sub display_columns {
62    
63  #private template search_region => sub {};  #private template search_region => sub {};
64    
65    =for later
66    
67    template 'index.html' => page {
68            my $self = shift;
69            title is $self->object_type;
70            form {
71                    render_region(
72                            name     => $self->object_type.'-list',
73                            path     => $self->fragment_base_path.'/list'
74                    );
75            };
76    };
77    
78    template 'list' => sub {
79            my $self = shift;
80    
81            my ( $page ) = get('page');
82    
83            my $item_path = get('item_path') || $self->fragment_for("view");
84            my $collection =  $self->_current_collection();
85    
86            if ( $self->per_page == 1 ) {
87                    warn "## bulk import get to last page\n";
88                    $page = $collection->pager->last_page;
89            }
90    
91            div {
92                    {class is 'crud-'.$self->object_type};
93    
94                    show('./search_region');
95                    show( './paging_top',    $collection, $page );
96                    show( './paging_bottom', $collection, $page );
97                    show( './list_items',    $collection, $item_path );
98                    show( './paging_bottom', $collection, $page );
99    
100                    show( './new_item_region');
101            }
102    
103    };
104    
105    =cut
106    
107  private template 'paging_top' => sub {  private template 'paging_top' => sub {
108          my $self           = shift;          my $self           = shift;
109          my $collection = shift;          my $collection = shift;
# Line 75  private template 'paging_top' => sub { Line 121  private template 'paging_top' => sub {
121                                          $collection->pager->last_page                                          $collection->pager->last_page
122                                  )                                  )
123                          );                          );
124                          }                  }
125          }          }
   
126          show( './paging_bottom', $collection, $page );          show( './paging_bottom', $collection, $page );
127    };
128    
129    private template paging_bottom => sub {
130            my $self           = shift;
131            my $collection = shift;
132            my $page           = shift || 0;
133            div {
134                    { class is 'paging' };
135                    if ( $collection->pager->previous_page ) {
136                            span {
137                                    hyperlink(
138                                            label   => _("Previous Page"),
139                                            onclick => {
140                                                    args => { page => $collection->pager->previous_page }
141                                            }
142                                    );
143                            }
144                    }
145    
146                    my ( $f_p, $t_p ) = ( '...', '...' );
147    
148                    my $from = $page - 15;
149                    if ( $from < 0 ) {
150                            $from = $collection->pager->first_page;
151                            $f_p = '';
152                    }
153                    my $to = $page + 15;
154                    if ( $to > $collection->pager->last_page ) {
155                            $to = $collection->pager->last_page;
156                            $t_p = '';
157                    }
158    
159                    outs $f_p;
160    
161                    foreach my $p ( $from .. $to ) {
162                            if ( $p == $page ) {
163                                    b { $p }
164                            } else {
165                                    span {
166                                            hyperlink(
167                                                    label   => $p,
168                                                    onclick =>
169                                                            { args => { page => $p } }
170                                            );
171                                    }
172                            }
173                    }
174    
175                    outs $t_p;
176    
177                    if ( $collection->pager->next_page ) {
178                            span {
179                                    hyperlink(
180                                            label   => _("Next Page"),
181                                            onclick =>
182                                                    { args => { page => $collection->pager->next_page } }
183                                    );
184                            }
185                    }
186            };
187  };  };
188    
189    
# Line 102  template 'view' => sub :CRUDView { Line 206  template 'view' => sub :CRUDView {
206    
207          div { { class is 'unit' }          div { { class is 'unit' }
208    
209          if ( $editing ) {                  if ( $editing ) {
                 form {  
210                          outs_raw($delete->button(                          outs_raw($delete->button(
211                                  label => _('Delete unit'),                                  label => _('Delete unit'),
212                                  class => 'float-crud-button button-delete',                                  class => 'float-crud-button button-delete',
# Line 117  template 'view' => sub :CRUDView { Line 220  template 'view' => sub :CRUDView {
220                                  },                                  },
221                          ));                          ));
222                  };                  };
         };  
223    
   
         form {  
224                  foreach my $f ( $self->display_columns ) {                  foreach my $f ( $self->display_columns ) {
225                          if ( $f eq 'material' ) {                          if ( $f eq 'material' ) {
226                                  set( search_collection => $record->material );                                  set( search_collection => $record->material );
# Line 151  template 'view' => sub :CRUDView { Line 251  template 'view' => sub :CRUDView {
251                                                  submit => $update,                                                  submit => $update,
252                                                  refresh_self => 1,                                                  refresh_self => 1,
253                                          },                                          },
254                                  )                                  );
255                          };                          }
256                  }                  }
         };  
257    
258          }; # div class unit          }; # div class unit
259    
# Line 173  template 'new_item' => sub { Line 272  template 'new_item' => sub {
272    
273          h1 { _("New unit") };          h1 { _("New unit") };
274    
275          form {          div {
276    
277                  foreach my $f ( $self->display_columns ) {                  foreach my $f ( $self->display_columns ) {
278  #                       last if $f eq 'material' && ! $id;  #                       last if $f eq 'material' && ! $id;
# Line 204  template 'new_item' => sub { Line 303  template 'new_item' => sub {
303                                  ],                                  ],
304                                  as_button => 1,                                  as_button => 1,
305                          );                          );
306                  }                  };
307    
308          };          };
309  };  };

Legend:
Removed from v.66  
changed lines
  Added in v.77

  ViewVC Help
Powered by ViewVC 1.1.26