/[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 200 by dpavlin, Tue Jun 17 23:06:31 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  =head2 site-navigation
123    
124  =cut  =cut
125    
126  template 'sitemap' => page {  sub strix_link {
127            my ( $url, $label ) = @_;
128          title is _('Sitemap');          hyperlink(
129                    url => 'http://' . get('instance') . '.cms-qa.skole.hr' . $url,
130          my $site_id = get('site_id') || 1;                  label => $label || $url,
131                    target => 'strix',
132            );
133    }
134    
135          my $sitemap = strix->site_navigation( $site_id );  template 'site-navigation' => page {
136    
137          sub full_url {          title is _('Site navigation');
                 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]',  
                         );  
                 }  
         }  
138    
139          sub children {          render_region(
140                  my $c = shift;                  name => 'selected-instances',
141                  return unless defined $c->{children};                  path => '/strix/selected-instances'
142                  ul {          );
                         foreach my $p ( @{ $c->{children} } ) {  
                                 li {  
                                         full_url( $p );  
                                         children( $p );  
                                 }  
                         }  
                 }  
         }  
143    
144          ul {          render_region(
145                  foreach my $p ( @$sitemap ) {                  name => 'select-strix-site',
146                          li {                  path => '/strix/select-site'
147                                  full_url( $p );          );
                                 children( $p );  
                         }  
                 }  
         }  
148    
149  };  };
150    
# Line 180  template 'layout' => page { Line 165  template 'layout' => page {
165                  $category->{naziv},                  $category->{naziv},
166          );          );
167    
168          hyperlink(          render_region(
169                  url => 'http://' . $category->{sitename} . '/' . $category->{url},                  name => 'selected-instances',
170                  label => $category->{naziv},                  path => '/strix/selected-instances'
171          );          );
172    
173            strix_link( $category->{url}, $category->{naziv} );
174    
175          my $layout = strix->layout( $url );          my $layout = strix->layout( $url );
176    
177          pre {          pre {
# Line 209  template 'execute-sql' => sub { Line 196  template 'execute-sql' => sub {
196                  sticky_on_success => 1,                  sticky_on_success => 1,
197                  sticky_on_failure => 1,                  sticky_on_failure => 1,
198                  arguments => {                  arguments => {
199                          strix => get('strix')                          instance => get('instance')
200                  }                  }
201          );          );
202    
203          form {          form {
204                  render_action( $action => [ 'strix', 'sql' ] );                  render_action( $action => [ 'instance', 'sql' ] );
205                  form_submit( label => _('Execute SQL') );                  form_submit( label => _('Execute SQL') );
206          };          };
207    
# Line 261  template 'search-instances' => sub { Line 248  template 'search-instances' => sub {
248                  table {                  table {
249                          while (my $strix = $search->next) {                          while (my $strix = $search->next) {
250                                  row {                                  row {
251                                            cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
252                                          cell { tt { $strix->instance } }                                          cell { tt { $strix->instance } }
253                                          cell { $strix->_site_name }                                          cell { $strix->_site_name }
                                         cell { show( 'instance-op', 'Create', '+', $strix->instance ) }  
254                                  }                                  }
255                          }                          }
256                  }                  }
# Line 280  Show Selected instances for current user Line 267  Show Selected instances for current user
267  template 'selected-instances' => sub {  template 'selected-instances' => sub {
268          my $self = shift;          my $self = shift;
269    
270          warn "## IN selected-instances ",dump( @_ );  #       warn "## IN selected-instances ",dump( @_ );
271    
272          if ( my $op = get 'op' ) {          if ( my $op = get 'op' ) {
273                  my $instance = get 'instance' or die "no instance?";                  my $op_instance = get 'op_instance' or die "no op_instance?";
274                  warn "# selected-instances $op on $instance";                  warn "# selected-instances $op on $op_instance";
275    
276                  my $a;                  my $a;
277    
# Line 294  template 'selected-instances' => sub { Line 281  template 'selected-instances' => sub {
281                                  class => $op . 'StrixInstanceSelection',                                  class => $op . 'StrixInstanceSelection',
282                                  moniker => $op,                                  moniker => $op,
283                                  arguments => {                                  arguments => {
284                                          instance => $instance,                                          instance => $op_instance,
285                                          by_user => $self->current_user->id,                                          by_user => $self->current_user->id,
286                                  },                                  },
287                          );                          );
# Line 302  template 'selected-instances' => sub { Line 289  template 'selected-instances' => sub {
289                  } elsif ( $op eq 'Delete' ) {                  } elsif ( $op eq 'Delete' ) {
290    
291                          my $strix = A3C::Model::StrixInstanceSelection->new;                          my $strix = A3C::Model::StrixInstanceSelection->new;
292                          $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 );
293                          die "can't find instance $instance" unless $strix->id;                          warn "can't find instance $op_instance" unless $strix->id;
294                          $a = $strix->as_delete_action;                          $a = $strix->as_delete_action;
295    
296                  }                  }
297                  warn "# argument_values = ",dump( $a->argument_values );  #               warn "# argument_values = ",dump( $a->argument_values );
298                  $a->run;                  $a->run;
299                  warn "can't $op instance $instance" unless $a->result->success;  
300                    if ( $a->result->error ) {
301                            div {
302                                    { class is 'note error' }
303                                    $a->result->error;
304                            }
305                    }
306    
307                    set( op => '' );
308          }          }
309    
310          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
# Line 317  template 'selected-instances' => sub { Line 312  template 'selected-instances' => sub {
312    
313          if ( $selected->count > 0 ) {          if ( $selected->count > 0 ) {
314    
315                  div { _('%1 instances selected', $selected->count ) }                  my $instance = get('instance');
316                    warn "# selected-instances -- selected: $instance\n";
317    
318                    div { _('%1 instances selected', $selected->count ) };
319                  table {                  table {
320                          while (my $s = $selected->next) {                          while (my $s = $selected->next) {
321                                  row {                                  row {
322                                          cell { tt { $s->strix->instance } }                                          cell { tt {
323                                          cell { $s->strix->_site_name }                                                  if ( $s->instance->instance eq $instance ) {
324                                          cell { show( 'instance-op', 'Delete', '-', $s->strix->instance ) }                                                          b { $instance }
325                                                    } else {
326                                                            hyperlink(
327                                                                    url => '?instance=' . $s->instance->instance,
328                                                                    label => $s->instance->instance
329                                                            )
330                                                    }
331                                            } }
332                                            cell { $s->instance->_site_name }
333                                            cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
334                                  }                                  }
335                          }                          }
336                  }                  }
# Line 343  Display button to add/remove instance fr Line 350  Display button to add/remove instance fr
350  template 'instance-op' => sub {  template 'instance-op' => sub {
351          my $self = shift;          my $self = shift;
352    
353          warn "# instance-op = ",dump( @_ );  #       warn "# instance-op = ",dump( @_ );
354    
355          my ( $op, $label, $instance ) = @_;          my ( $op, $label, $instance ) = @_;
356    
# Line 354  template 'instance-op' => sub { Line 361  template 'instance-op' => sub {
361                                  refresh => 'selected-instances',                                  refresh => 'selected-instances',
362                                  path => '/strix/selected-instances',                                  path => '/strix/selected-instances',
363                                  args => {                                  args => {
364                                          instance => $instance,                                          op_instance => $instance,
365                                          op => $op,                                          op => $op,
366                                  }                                  }
367                          },                          },
# Line 363  template 'instance-op' => sub { Line 370  template 'instance-op' => sub {
370    
371  };  };
372    
373    =head2 select-site
374    
375    =cut
376    
377    template 'select-site' => sub {
378    
379            my $action = new_action(
380                    class   => 'StrixSelectSite',
381                    moniker => 'strix-select-site',
382            );
383    
384            warn "# action = ", dump( $action );
385    
386            warn "# argument_values = ", dump( $action->argument_values );
387    
388            if ( ! $action->argument_value('instance') ) {
389                    $action->argument_value( 'instance', get('instance') );
390                    warn "# run action with instance\n";
391                    $action->run;
392            }
393    
394            my $magic = [
395                    { submit => $action, refresh_self => 1 },
396                    # this is basically a closure
397                    { refresh => 'selected-instances', path => '/strix/selected-instances', args => {
398                            instance => { result_of => $action, name => 'instance' }
399                    } }
400            ];
401    
402            form {
403                    render_param( $action, 'instance', onchange => $magic );
404                    render_param( $action, 'site_id', onchange => $magic );
405                    form_submit( label => _('Show navigation'), onclick => $magic );
406            };
407    
408            warn "## select-site action ",dump( $action->result );
409    
410            if ( my $site_id = $action->result->content('site_id') ) {
411                    show('strix-site-navigation-tree', $action->result->content('instance'), $site_id);
412            }
413    };
414    
415    =head1 PRIVATE TEMPLATES
416    
417    =head2 strix-site-navigation-tree
418    
419      show('strix-site-navigation-tree',$instance,$site_id);
420    
421    =cut
422    
423    private template 'strix-site-navigation-tree' => sub {
424            my $self = shift;
425            my ( $instance, $site_id ) = @_;
426    
427            warn ">>>> instance: $instance site_id: $site_id";
428    
429            set 'instance' => $instance;
430    
431            sub full_url {
432                    my $p = shift;
433                    strix_link( $p->{url}, $p->{naziv} );
434                    if ( $p->{type} eq 'category' ) {
435                            outs_raw(' ');
436                            hyperlink(
437                                    url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
438                                    label => _('layout'),
439                                    class => 'layout',
440                            );
441                    }
442            }
443    
444            sub children {
445                    my $c = shift;
446                    return unless defined $c->{children};
447                    ul {
448                            foreach my $p ( @{ $c->{children} } ) {
449                                    li {
450                                            { class is $p->{class} };
451                                            full_url( $p );
452                                            children( $p );
453                                    }
454                            }
455                    }
456            }
457    
458            my $strix = Strix->new({ instance => $instance });
459    
460            my @navigation = @{ $strix->site_navigation( $site_id ) };
461            if ( @navigation ) {
462                    ul {
463                            foreach my $p ( @navigation ) {
464                                    li {
465                                            full_url( $p );
466                                            children( $p );
467                                    }
468                            }
469                    }
470            } else {
471                    div {
472                            { class is 'note error' }
473                            _('No navigation found for instance %1 site_id %2', $instance, $site_id)
474                    }
475    
476            }
477    
478    };
479    
480  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26