/[A3C]/lib/A3C/View/Strix.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/A3C/View/Strix.pm

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

revision 174 by dpavlin, Mon Jun 16 16:48:16 2008 UTC revision 217 by dpavlin, Fri Jun 20 22:37:33 2008 UTC
# Line 53  template 'name_diff' => page { Line 53  template 'name_diff' => page {
53    
54          title is _('Strix name differences');          title is _('Strix name differences');
55    
56            render_region(
57                    name => 'selected-instances',
58                    path => '/strix/selected-instances'
59            );
60    
61          my $name_diff = A3C::SQL->new({ query => qq{          my $name_diff = A3C::SQL->new({ query => qq{
62                  select                  select
63                          instance,hreduorgurl,                          instance,hreduorgurl,
# Line 66  template 'name_diff' => page { Line 71  template 'name_diff' => page {
71    
72                  table {                  table {
73                          row {                          row {
74                                    th {}
75                                  th { _('Instance') }                                  th { _('Instance') }
76                                  th { _('Strix instance name') }                                  th { _('Strix instance name') }
77                                  th { _('hrEduOrg.o') }                                  th { _('hrEduOrg.o') }
78                          };                          };
79                          while ( my $row = $name_diff->next ) {                          while ( my $row = $name_diff->next ) {
80                                  row {                                  row {
81                                          cell { hyperlink( url => 'http://' . $row->hreduorgurl, label => $row->instance ) }                                          cell { show( 'instance-op', 'Create', '+', $row->instance ) }
82                                            cell { $row->instance }
83                                          cell { $row->_site_name }                                          cell { $row->_site_name }
84                                          cell { $row->o }                                          cell { $row->o }
85                                  }                                  }
# Line 108  template 'sql' => page { Line 115  template 'sql' => page {
115  };  };
116    
117  sub strix {  sub strix {
118          my $instance = get('instance') || shift || 'new';          my $instance = get('instance');
119          return Strix->new({ instance => $instance });          return Strix->new({ instance => $instance });
120  }  }
121    
122  =head2 sitemap  sub strix_link {
123            my ( $url, $label ) = @_;
124  =cut          hyperlink(
125                    url => 'http://' . get('instance') . '.cms-qa.skole.hr' . $url,
126  template 'sitemap' => page {                  label => $label || $url,
127                    target => 'strix',
128          title is _('Sitemap');          );
129    }
         my $site_id = get('site_id') || 1;  
   
         my $sitemap = strix->site_navigation( $site_id );  
   
         sub full_url {  
                 my $p = shift;  
                 hyperlink(  
                         url => 'http://new.cms-qa.skole.hr' . $p->{url},  
                         label => $p->{naziv},  
                 );  
                 if ( $p->{type} eq 'category' ) {  
                         outs_raw(' ');  
                         hyperlink(  
                                 url => '/strix/layout?url=' . $p->{url},  
                                 label => '[layout]',  
                         );  
                 }  
         }  
   
         sub children {  
                 my $c = shift;  
                 return unless defined $c->{children};  
                 ul {  
                         foreach my $p ( @{ $c->{children} } ) {  
                                 li {  
                                         full_url( $p );  
                                         children( $p );  
                                 }  
                         }  
                 }  
         }  
   
         ul {  
                 foreach my $p ( @$sitemap ) {  
                         li {  
                                 full_url( $p );  
                                 children( $p );  
                         }  
                 }  
         }  
   
 };  
130    
131  =head2 layout  =head2 navigation
132    
133  =cut  =cut
134    
135  template 'layout' => page {  template 'navigation' => page {
   
         my $url = get('url') || '/';  
   
         my $category = strix->category( $url );  
136    
137          warn dump( $category );          title is _('Site navigation');
138    
139          title is _('Layout %1 : %2',          render_region(
140                  $category->{sitename},                  name => 'selected-instances',
141                  $category->{naziv},                  path => '/strix/selected-instances'
142          );          );
143    
144          hyperlink(          render_region(
145                  url => 'http://' . $category->{sitename} . '/' . $category->{url},                  name => 'strix-site',
146                  label => $category->{naziv},                  path => '/strix/site'
147          );          );
148    
         my $layout = strix->layout( $url );  
   
         pre {  
                 dump( $layout );  
         }  
   
149  };  };
150    
151  =head1 REGIONS  =head1 REGIONS
# Line 209  template 'execute-sql' => sub { Line 164  template 'execute-sql' => sub {
164                  sticky_on_success => 1,                  sticky_on_success => 1,
165                  sticky_on_failure => 1,                  sticky_on_failure => 1,
166                  arguments => {                  arguments => {
167                          strix => get('strix')                          instance => get('instance')
168                  }                  }
169          );          );
170    
171          form {          form {
172                  render_action( $action => [ 'strix', 'sql' ] );                  render_action( $action => [ 'instance', 'sql' ] );
173                  form_submit( label => _('Execute SQL') );                  form_submit( label => _('Execute SQL') );
174          };          };
175    
# Line 261  template 'search-instances' => sub { Line 216  template 'search-instances' => sub {
216                  table {                  table {
217                          while (my $strix = $search->next) {                          while (my $strix = $search->next) {
218                                  row {                                  row {
219                                            cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
220                                          cell { tt { $strix->instance } }                                          cell { tt { $strix->instance } }
221                                          cell { $strix->_site_name }                                          cell { $strix->_site_name }
                                         cell { show( 'instance-op', 'Create', '+', $strix->instance ) }  
222                                  }                                  }
223                          }                          }
224                  }                  }
# Line 280  Show Selected instances for current user Line 235  Show Selected instances for current user
235  template 'selected-instances' => sub {  template 'selected-instances' => sub {
236          my $self = shift;          my $self = shift;
237    
238          warn "## IN selected-instances ",dump( @_ );  #       warn "## IN selected-instances ",dump( @_ );
239    
240          if ( my $op = get 'op' ) {          if ( my $op = get 'op' ) {
241                  my $instance = get 'instance' or die "no instance?";                  my $op_instance = get 'op_instance';
242                  warn "# selected-instances $op on $instance";                  return unless $op_instance;
243                    warn "# selected-instances $op on $op_instance";
244    
245                  my $a;                  my $a;
246    
# Line 294  template 'selected-instances' => sub { Line 250  template 'selected-instances' => sub {
250                                  class => $op . 'StrixInstanceSelection',                                  class => $op . 'StrixInstanceSelection',
251                                  moniker => $op,                                  moniker => $op,
252                                  arguments => {                                  arguments => {
253                                          instance => $instance,                                          instance => $op_instance,
254                                          by_user => $self->current_user->id,                                          by_user => $self->current_user->id,
255                                  },                                  },
256                          );                          );
# Line 302  template 'selected-instances' => sub { Line 258  template 'selected-instances' => sub {
258                  } elsif ( $op eq 'Delete' ) {                  } elsif ( $op eq 'Delete' ) {
259    
260                          my $strix = A3C::Model::StrixInstanceSelection->new;                          my $strix = A3C::Model::StrixInstanceSelection->new;
261                          $strix->load_by_cols( instance => $instance, by_user => $self->current_user->id );                          $strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id );
262                          die "can't find instance $instance" unless $strix->id;                          warn "can't find instance $op_instance" unless $strix->id;
263                          $a = $strix->as_delete_action;                          $a = $strix->as_delete_action;
264    
265                  }                  }
266                  warn "# argument_values = ",dump( $a->argument_values );  #               warn "# argument_values = ",dump( $a->argument_values );
267                  $a->run;                  $a->run;
268                  warn "can't $op instance $instance" unless $a->result->success;  
269                    if ( $a->result->error ) {
270                            div {
271                                    { class is 'note error' }
272                                    $a->result->error;
273                            }
274                    }
275    
276                    set( op => '' );
277          }          }
278    
279          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
# Line 317  template 'selected-instances' => sub { Line 281  template 'selected-instances' => sub {
281    
282          if ( $selected->count > 0 ) {          if ( $selected->count > 0 ) {
283    
284                  div { _('%1 instances selected', $selected->count ) }                  my $instance = get('instance');
285                    warn "# selected-instances -- selected: $instance\n";
286    
287                    div { _('%1 instances selected', $selected->count ) };
288                  table {                  table {
289                          while (my $s = $selected->next) {                          while (my $s = $selected->next) {
290                                  row {                                  row {
291                                          cell { tt { $s->strix->instance } }                                          cell { tt {
292                                          cell { $s->strix->_site_name }                                                  if ( $s->instance->instance eq $instance ) {
293                                          cell { show( 'instance-op', 'Delete', '-', $s->strix->instance ) }                                                          b { $instance }
294                                                    } else {
295                                                            hyperlink(
296                                                                    url => '?instance=' . $s->instance->instance,
297                                                                    label => $s->instance->instance
298                                                            )
299                                                    }
300                                            } }
301                                            cell { $s->instance->_site_name }
302                                            cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
303                                  }                                  }
304                          }                          }
305                  }                  }
# Line 343  Display button to add/remove instance fr Line 319  Display button to add/remove instance fr
319  template 'instance-op' => sub {  template 'instance-op' => sub {
320          my $self = shift;          my $self = shift;
321    
322          warn "# instance-op = ",dump( @_ );  #       warn "# instance-op = ",dump( @_ );
323    
324          my ( $op, $label, $instance ) = @_;          my ( $op, $label, $instance ) = @_;
325    
# Line 354  template 'instance-op' => sub { Line 330  template 'instance-op' => sub {
330                                  refresh => 'selected-instances',                                  refresh => 'selected-instances',
331                                  path => '/strix/selected-instances',                                  path => '/strix/selected-instances',
332                                  args => {                                  args => {
333                                          instance => $instance,                                          op_instance => $instance,
334                                          op => $op,                                          op => $op,
335                                  }                                  }
336                          },                          },
# Line 363  template 'instance-op' => sub { Line 339  template 'instance-op' => sub {
339    
340  };  };
341    
342    =head2 site
343    
344    =cut
345    
346    template 'site' => sub {
347    
348            my $action = new_action(
349                    class   => 'StrixSelectSite',
350                    moniker => 'strix-select-site',
351            );
352    
353            warn "# action = ", dump( $action );
354    
355            warn "# argument_values = ", dump( $action->argument_values );
356    
357            if ( ! $action->argument_value('instance') ) {
358                    $action->argument_value( 'instance', get('instance') );
359                    warn "# run action with instance\n";
360                    $action->run;
361            }
362    
363            my $magic = [
364                    { submit => $action, refresh_self => 1 },
365                    # this is basically a closure
366                    { refresh => 'selected-instances', path => '/strix/selected-instances', args => {
367                            instance => { result_of => $action, name => 'instance' }
368                    } },
369                    { refresh => 'strix-site-layout', path => '/__jifty/empty' },
370            ];
371    
372            form {
373                    render_param( $action, 'instance', onchange => $magic );
374                    render_param( $action, 'site_id', onchange => $magic );
375                    form_submit( label => _('Show navigation'), onclick => $magic );
376            };
377    
378            warn "## select-site action ",dump( $action->result );
379    
380            render_region(
381                    name => 'layout',
382                    path => '/__jifty/empty',
383            );
384    
385            if ( my $site_id = $action->result->content('site_id') ) {
386                    show('navigation-tree', $action->result->content('instance'), $site_id);
387            }
388    };
389    
390    =head2 layout
391    
392    Shows layout for C<url>
393    
394    =cut
395    
396    template 'layout' => sub {
397    
398            my $url = get('url') || '/';
399            my $category = strix->category( $url );
400            my $layout = strix->layout( $url );
401    
402            h1 { $category->{naziv} }
403            pre {
404                    dump( $layout );
405            }
406    
407    };
408    
409    =head2 category
410    
411    Show category data for C<url>
412    
413    =cut
414    
415    template 'category' => sub {
416    
417            my $url = get('url') || '/';
418            my $category = strix->category( $url );
419    
420            h1 { $category->{naziv} }
421            pre {
422                    dump( $category );
423            }
424    
425    };
426    
427    =head1 PRIVATE TEMPLATES
428    
429    =head2 navigation-tree-category
430    
431      show('navigation-tree-category',$kat_row);
432    
433    =cut
434    
435    private template 'navigation-tree-category' => sub {
436            my $self = shift;
437            #warn "## navigation-tree-category",dump( @_ );
438            my $p = shift;
439            hyperlink(
440                    onclick => {
441                            region => 'strix-site-layout',  # FIXME do we have to hard-code region name here?
442                            replace_with => '/strix/category',
443                            args => {
444                                    url => $p->{url},
445                                    instance => get('instance'),
446                            }
447                    },
448                    label => $p->{naziv},
449            );
450            outs_raw('&nbsp;');
451            if ( $p->{type} eq 'category' ) {
452                    hyperlink(
453    #                               url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
454                            onclick => {
455                                    region => 'strix-site-layout',  # FIXME do we have to hard-code region name here?
456                                    replace_with => '/strix/layout',
457                                    args => {
458                                            url => $p->{url},
459                                            instance => get('instance'),
460                                    }
461                            },
462                            label => _('layout'),
463                            class => 'layout',
464                    );
465            }
466            outs_raw('&nbsp;');
467            strix_link( $p->{url}, '>>' );
468    };
469    
470    =head2 navigation-tree
471    
472      show('navigation-tree',$instance,$site_id);
473    
474    =cut
475    
476    private template 'navigation-tree' => sub {
477            my $self = shift;
478            my ( $instance, $site_id ) = @_;
479    
480            warn "## navigation-tree instance: $instance site_id: $site_id";
481    
482            set 'instance' => $instance;
483    
484            sub children {
485                    my $c = shift;
486                    return unless defined $c->{children};
487                    ul {
488                            foreach my $p ( @{ $c->{children} } ) {
489                                    li {
490                                            if ( defined( $p->{class} ) ) {
491                                                    { class is $p->{class} };
492                                            }
493                                            show( 'navigation-tree-category', $p );
494                                            children( $p );
495                                    }
496                            }
497                    }
498            }
499    
500            my $strix = Strix->new({ instance => $instance });
501    
502            my $navigation = $strix->site_navigation( $site_id );
503            #warn "## navigation = ",dump( $navigation );
504            if ( $navigation ) {
505                    ul {
506                            { class is 'navigation' };
507                            foreach my $p ( @$navigation ) {
508                                    li {
509                                            show( 'navigation-tree-category', $p );
510                                            children( $p );
511                                    }
512                            }
513                    }
514            } else {
515                    div {
516                            { class is 'note error' }
517                            _('No navigation found for instance %1 site_id %2', $instance, $site_id)
518                    }
519    
520            }
521    
522    };
523    
524  1;  1;

Legend:
Removed from v.174  
changed lines
  Added in v.217

  ViewVC Help
Powered by ViewVC 1.1.26