/[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 211 by dpavlin, Fri Jun 20 15:35:21 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                    label => $label || $url,
127                    target => 'strix',
128            );
129    }
130    
131  template 'sitemap' => page {  =head2 navigation
132    
133          title is _('Sitemap');  =cut
134    
135          my $site_id = get('site_id') || 1;  template 'navigation' => page {
136    
137          my $sitemap = strix->site_navigation( $site_id );          title is _('Site navigation');
138    
139          sub full_url {          render_region(
140                  my $p = shift;                  name => 'selected-instances',
141                  hyperlink(                  path => '/strix/selected-instances'
142                          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 );  
                                 }  
                         }  
                 }  
         }  
143    
144          ul {          render_region(
145                  foreach my $p ( @$sitemap ) {                  name => 'strix-site',
146                          li {                  path => '/strix/site'
147                                  full_url( $p );          );
                                 children( $p );  
                         }  
                 }  
         }  
148    
149  };  };
150    
# Line 167  template 'sitemap' => page { Line 152  template 'sitemap' => page {
152    
153  =cut  =cut
154    
155  template 'layout' => page {  template 'layout' => sub {
156    
157          my $url = get('url') || '/';          my $url = get('url') || '/';
158    
# Line 175  template 'layout' => page { Line 160  template 'layout' => page {
160    
161          warn dump( $category );          warn dump( $category );
162    
163          title is _('Layout %1 : %2',          strix_link( $category->{url}, $category->{naziv} );
                 $category->{sitename},  
                 $category->{naziv},  
         );  
   
         hyperlink(  
                 url => 'http://' . $category->{sitename} . '/' . $category->{url},  
                 label => $category->{naziv},  
         );  
164    
165          my $layout = strix->layout( $url );          my $layout = strix->layout( $url );
166    
# Line 209  template 'execute-sql' => sub { Line 186  template 'execute-sql' => sub {
186                  sticky_on_success => 1,                  sticky_on_success => 1,
187                  sticky_on_failure => 1,                  sticky_on_failure => 1,
188                  arguments => {                  arguments => {
189                          strix => get('strix')                          instance => get('instance')
190                  }                  }
191          );          );
192    
193          form {          form {
194                  render_action( $action => [ 'strix', 'sql' ] );                  render_action( $action => [ 'instance', 'sql' ] );
195                  form_submit( label => _('Execute SQL') );                  form_submit( label => _('Execute SQL') );
196          };          };
197    
# Line 261  template 'search-instances' => sub { Line 238  template 'search-instances' => sub {
238                  table {                  table {
239                          while (my $strix = $search->next) {                          while (my $strix = $search->next) {
240                                  row {                                  row {
241                                            cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
242                                          cell { tt { $strix->instance } }                                          cell { tt { $strix->instance } }
243                                          cell { $strix->_site_name }                                          cell { $strix->_site_name }
                                         cell { show( 'instance-op', 'Create', '+', $strix->instance ) }  
244                                  }                                  }
245                          }                          }
246                  }                  }
# Line 280  Show Selected instances for current user Line 257  Show Selected instances for current user
257  template 'selected-instances' => sub {  template 'selected-instances' => sub {
258          my $self = shift;          my $self = shift;
259    
260          warn "## IN selected-instances ",dump( @_ );  #       warn "## IN selected-instances ",dump( @_ );
261    
262          if ( my $op = get 'op' ) {          if ( my $op = get 'op' ) {
263                  my $instance = get 'instance' or die "no instance?";                  my $op_instance = get 'op_instance';
264                  warn "# selected-instances $op on $instance";                  return unless $op_instance;
265                    warn "# selected-instances $op on $op_instance";
266    
267                  my $a;                  my $a;
268    
# Line 294  template 'selected-instances' => sub { Line 272  template 'selected-instances' => sub {
272                                  class => $op . 'StrixInstanceSelection',                                  class => $op . 'StrixInstanceSelection',
273                                  moniker => $op,                                  moniker => $op,
274                                  arguments => {                                  arguments => {
275                                          instance => $instance,                                          instance => $op_instance,
276                                          by_user => $self->current_user->id,                                          by_user => $self->current_user->id,
277                                  },                                  },
278                          );                          );
# Line 302  template 'selected-instances' => sub { Line 280  template 'selected-instances' => sub {
280                  } elsif ( $op eq 'Delete' ) {                  } elsif ( $op eq 'Delete' ) {
281    
282                          my $strix = A3C::Model::StrixInstanceSelection->new;                          my $strix = A3C::Model::StrixInstanceSelection->new;
283                          $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 );
284                          die "can't find instance $instance" unless $strix->id;                          warn "can't find instance $op_instance" unless $strix->id;
285                          $a = $strix->as_delete_action;                          $a = $strix->as_delete_action;
286    
287                  }                  }
288                  warn "# argument_values = ",dump( $a->argument_values );  #               warn "# argument_values = ",dump( $a->argument_values );
289                  $a->run;                  $a->run;
290                  warn "can't $op instance $instance" unless $a->result->success;  
291                    if ( $a->result->error ) {
292                            div {
293                                    { class is 'note error' }
294                                    $a->result->error;
295                            }
296                    }
297    
298                    set( op => '' );
299          }          }
300    
301          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
# Line 317  template 'selected-instances' => sub { Line 303  template 'selected-instances' => sub {
303    
304          if ( $selected->count > 0 ) {          if ( $selected->count > 0 ) {
305    
306                  div { _('%1 instances selected', $selected->count ) }                  my $instance = get('instance');
307                    warn "# selected-instances -- selected: $instance\n";
308    
309                    div { _('%1 instances selected', $selected->count ) };
310                  table {                  table {
311                          while (my $s = $selected->next) {                          while (my $s = $selected->next) {
312                                  row {                                  row {
313                                          cell { tt { $s->strix->instance } }                                          cell { tt {
314                                          cell { $s->strix->_site_name }                                                  if ( $s->instance->instance eq $instance ) {
315                                          cell { show( 'instance-op', 'Delete', '-', $s->strix->instance ) }                                                          b { $instance }
316                                                    } else {
317                                                            hyperlink(
318                                                                    url => '?instance=' . $s->instance->instance,
319                                                                    label => $s->instance->instance
320                                                            )
321                                                    }
322                                            } }
323                                            cell { $s->instance->_site_name }
324                                            cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
325                                  }                                  }
326                          }                          }
327                  }                  }
# Line 343  Display button to add/remove instance fr Line 341  Display button to add/remove instance fr
341  template 'instance-op' => sub {  template 'instance-op' => sub {
342          my $self = shift;          my $self = shift;
343    
344          warn "# instance-op = ",dump( @_ );  #       warn "# instance-op = ",dump( @_ );
345    
346          my ( $op, $label, $instance ) = @_;          my ( $op, $label, $instance ) = @_;
347    
# Line 354  template 'instance-op' => sub { Line 352  template 'instance-op' => sub {
352                                  refresh => 'selected-instances',                                  refresh => 'selected-instances',
353                                  path => '/strix/selected-instances',                                  path => '/strix/selected-instances',
354                                  args => {                                  args => {
355                                          instance => $instance,                                          op_instance => $instance,
356                                          op => $op,                                          op => $op,
357                                  }                                  }
358                          },                          },
# Line 363  template 'instance-op' => sub { Line 361  template 'instance-op' => sub {
361    
362  };  };
363    
364    =head2 site
365    
366    =cut
367    
368    template 'site' => sub {
369    
370            my $action = new_action(
371                    class   => 'StrixSelectSite',
372                    moniker => 'strix-select-site',
373            );
374    
375            warn "# action = ", dump( $action );
376    
377            warn "# argument_values = ", dump( $action->argument_values );
378    
379            if ( ! $action->argument_value('instance') ) {
380                    $action->argument_value( 'instance', get('instance') );
381                    warn "# run action with instance\n";
382                    $action->run;
383            }
384    
385            my $magic = [
386                    { submit => $action, refresh_self => 1 },
387                    # this is basically a closure
388                    { refresh => 'selected-instances', path => '/strix/selected-instances', args => {
389                            instance => { result_of => $action, name => 'instance' }
390                    } },
391                    { refresh => 'strix-site-layout', path => '/__jifty/empty' },
392            ];
393    
394            form {
395                    render_param( $action, 'instance', onchange => $magic );
396                    render_param( $action, 'site_id', onchange => $magic );
397                    form_submit( label => _('Show navigation'), onclick => $magic );
398            };
399    
400            warn "## select-site action ",dump( $action->result );
401    
402            render_region(
403                    name => 'layout',
404                    path => '/__jifty/empty',
405            );
406    
407            if ( my $site_id = $action->result->content('site_id') ) {
408                    show('strix-site-navigation-tree', $action->result->content('instance'), $site_id);
409            }
410    };
411    
412    =head1 PRIVATE TEMPLATES
413    
414    =head2 strix-site-navigation-tree
415    
416      show('strix-site-navigation-tree',$instance,$site_id);
417    
418    =cut
419    
420    private template 'select-category' => sub {
421            my $self = shift;
422            my $p = shift;
423            strix_link( $p->{url}, $p->{naziv} );
424            if ( $p->{type} eq 'category' ) {
425                    outs_raw(' ');
426                    hyperlink(
427    #                       url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
428                            onclick => {
429                                    region => 'strix-site-layout',  # FIXME do we have to hard-code region name here?
430                                    replace_with => '/strix/layout',
431                                    args => {
432                                            url => $p->{url},
433                                            instance => get('instance'),
434                                    }
435                            },
436                            label => _('layout'),
437                            class => 'layout',
438                    );
439            }
440    };
441    
442    private template 'strix-site-navigation-tree' => sub {
443            my $self = shift;
444            my ( $instance, $site_id ) = @_;
445    
446            warn ">>>> instance: $instance site_id: $site_id";
447    
448            set 'instance' => $instance;
449    
450    
451            sub children {
452                    my $c = shift;
453                    return unless defined $c->{children};
454                    ul {
455                            foreach my $p ( @{ $c->{children} } ) {
456                                    li {
457                                            { class is $p->{class} };
458                                            show( 'select-category', $p );
459                                            children( $p );
460                                    }
461                            }
462                    }
463            }
464    
465            my $strix = Strix->new({ instance => $instance });
466    
467            my @navigation = @{ $strix->site_navigation( $site_id ) };
468            if ( @navigation ) {
469                    ul {
470                            foreach my $p ( @navigation ) {
471                                    li {
472                                            show( 'select-category', $p );
473                                            children( $p );
474                                    }
475                            }
476                    }
477            } else {
478                    div {
479                            { class is 'note error' }
480                            _('No navigation found for instance %1 site_id %2', $instance, $site_id)
481                    }
482    
483            }
484    
485    };
486    
487  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26