package HTML::Mason::Commands; use strict; use vars qw($m $r); my $_escape = \&HTML::Mason::Parser::_escape_perl_expression; my $repeatable_elem_opts = sub { my ($t) = @_; my $id = $t->get_id; my $opts; foreach ($t->get_possible_data()) { if ($_->get_quantifier()) { # Pass the name with the tile ID as the value $opts->{$_->get_name()} = $_->get_name(); } } return $opts; }; my $related_summary = sub { my ($tile, $type, $widget) = @_; my $rel = $type eq 'story' ? $tile->get_related_story : $tile->get_related_media; my $button = $m->scomp( '/widgets/profile/imageSubmit.mc', formName => "theForm", callback => $widget ."|pick_related_".$type."_cb", image => "edit_lgreen", vspace => 4, ); $m->out(''); if ($rel) { # The summary info $m->out(''); } else { $m->out('
'); $m->comp('/widgets/summary/summary.mc', asset => $rel, type => $type, header => 'Currently Related '.ucfirst($type), frame => 0, button => $button ); $m->out('
'); $m->out('     No related '.ucfirst($type)); $m->out("$button"); } $m->out('
'); }; HTML::Mason::Component::FileBased->new ( 'code'=>sub { my %ARGS; if (@_ % 2 == 0) { %ARGS = @_ } else { die "Odd number of parameters passed to component expecting name/value pairs" } my $widget = (!exists $ARGS{'widget'} ? die "no value sent for required parameter 'widget'" : $ARGS{'widget'}); my $num = (!exists $ARGS{'num'} ? undef : $ARGS{'num'}); my $title = (!exists $ARGS{'title'} ? undef : $ARGS{'title'}); my $show_summary = (!exists $ARGS{'show_summary'} ? undef : $ARGS{'show_summary'}); my $_out = $m->current_sink; $m->debug_hook($m->current_comp->path) if (%DB::); # the tile object my $tile = get_state_data($widget, 'tile'); $title ||= $tile->get_name; my $start = get_state_data($widget, 'start'); # the contained tiles my @tiles = $tile->get_tiles(); my $elem_opts; my $repeatable_opts; # the possible data options my @pos_data = $tile->get_possible_data(); foreach (@pos_data) { my $key = 'data_' . $_->get_id(); $elem_opts->{$key} = $_->get_name(); if ($_->get_quantifier()) { $repeatable_opts->{$_->get_name()} = $_->get_name(); } } # the container options my @pos_cont = $tile->get_possible_containers(); foreach (@pos_cont) { my $key = 'cont_' . $_->get_id(); $elem_opts->{$key} = $_->get_name(); } my $at_id = $tile->get_element_id; my $at = Bric::Biz::AssetType->lookup({'id' => $at_id}); # Uncomment this when the related_tile flag is in at_type. my $is_related_story = $at->is_related_story ? 1 : 0; my $is_related_media = $at->is_related_media ? 1 : 0; # browser spacing stuff my $agent = $m->comp("/widgets/util/detectAgent.mc"); my $ieSpacer = ($agent->{browser} eq "Internet Explorer") ? qq{} : ''; my $shim = ($agent->{browser} eq "Netscape") ? -4 : 4; $_out->(' '); # Show the story summary if needed. if ($show_summary) { my $type = $tile->get_object_type; # Nab the story from the story_prof widget. my $asset = get_state_data($type.'_prof', $type); $m->comp('/widgets/summary/summary.mc', asset => $asset, number => 1); } # COUNT FOR REORDER JAVA SCRIPT my $total = scalar @tiles; my $x=0; $_out->(' '); # check if we should display if (@tiles || $elem_opts ) { $_out->(' '); $m->comp("/widgets/wrappers/sharky/table_top.mc", caption => $title, number => $num++ ); $_out->(' '); # COLUMN HEADER ROW my $rowspan = scalar(@tiles) + 2; $rowspan++ if ($repeatable_opts); $rowspan += scalar(@tiles) if ($agent->{browser} eq "Internet Explorer"); if (scalar(@tiles)) { # suppress labels if no results $_out->(' '); } # END if (scalar(@tiles)) { $_out->(' '); # BEGIN FOREACH TILES foreach my $dt (@tiles) { my $no_del; $_out->(' '); # START CONTENT ROWS $_out->(' '); if ($dt->is_container) { # START IF CONTAINER $_out->(' '); } else { # START ELSE ( DATA TILE DISPLAY ) my $at_obj = $dt->get_element_data_obj(); $no_del = $at_obj->get_required; my $meta = $at_obj->get_meta('html_info'); my $vals = { props => { %$meta } }; my $key = $widget . '|' . $dt->get_id; $vals->{'value'} = $dt->get_data() || $vals->{props}{value}; $_out->(' '); # END DATA AREA } # END ELSE (DATA TILE DISPLAY) $_out->(' '); # ORDER TABLE CELL $_out->(' '); # DELETE TABLE CELL $_out->(' '); $_out->( $ieSpacer ); $_out->(' '); } # END FOREACH TILES $_out->(' '); if (scalar @tiles) { $_out->(' '); } else { $_out->('   '); } $_out->(' '); # DISPLAY IF NO TILES if (!$total) { $_out->(' '); } $_out->(' '); # END TILE DISPLAY $_out->('
Name Content Position Delete
'); $_out->( $dt->get_name() ); $_out->(':  '); # START OPTIONAL BULK EDIT PULLDOWN if (my $opts = $repeatable_elem_opts->($dt)) { $_out->(' '); } # END IF OPTIONAL BULK EDIT PULLDOWN $_out->('
'); my $at = $dt->get_element; $_out->(' '); if ($at->is_related_media || $at->is_related_story) { $_out->(' '); my $info = ''; if ($at->is_related_media) { my $rel = $dt->get_related_media; $info = $rel->get_uri if $rel; } else { my $rel = $dt->get_related_story; $info = $rel->get_title if $rel; } $_out->('
'); $_out->( ($at->is_related_media) ? "URL:" : "Title:" ); $_out->('  '); $_out->( $info ); $_out->('
'); $m->comp('/widgets/profile/imageSubmit.mc', formName => "theForm", callback => "container_prof|edit". $dt->get_id() ."_cb", image => "edit_lgreen", vspace => 3); $_out->('
'); } else { $_out->(' '); $m->comp('/widgets/profile/imageSubmit.mc', formName => "theForm", callback => "container_prof|edit". $dt->get_id() ."_cb", image => "edit_lgreen", vspace => 3); $_out->(' '); } $_out->('
- or - '); $m->comp('/widgets/profile/imageSubmit.mc', formName => "theForm", callback => "container_prof|bulk_edit-" . $dt->get_id() ."_cb", image => "bulk_edit_lgreen"); $_out->(' '); $m->comp('/widgets/profile/select.mc', name => $widget.'|bulk_edit_tile_field-'.$dt->get_id, options => $opts, useTable => 0,); $_out->('
'); $_out->( $dt->get_name() ); $_out->(':  '); if ($dt->is_autopopulated()) { $_out->(' '); } else { $_out->(' '); } $_out->('
'); $m->comp('/widgets/profile/displayFormElement.mc', key => $key, vals => $vals, useTable => 0); $_out->(' Lock Val: ( $dt->is_locked() ? ' CHECKED' : '' ); $_out->('> 
'); my $f_key; if ($dt->is_container) { $f_key = "$widget|reorder_con" . $dt->get_id(); } else { $f_key = "$widget|reorder_dat" . $dt->get_id(); } my $vals = []; foreach (1 .. $total) { my $val = $_ - 1; push @$vals, [$val, $_]; } $_out->(' '); $m->comp('/widgets/profile/displayFormElement.mc', key => $f_key, vals => { value => $dt->get_place(), props => { type => 'select', vals => $vals, }, js => 'onChange="reorder(this, \'theForm\')"' }, useTable => 0); $_out->(' '); if ($no_del) { $_out->('   '); } elsif ($dt->is_container) { # START IF CONTAINER $_out->(' '); } else { $_out->(' '); } $_out->('
'); $m->comp('/widgets/profile/imageSubmit.mc', formName => "theForm", callback => "container_prof|reorder_cb", image => "reorder_lgreen", vspace => 3, hspace => 2); $_out->('  
    No elements have been added.
'); # Begin element picker if ($elem_opts) { $_out->(' '); if ($repeatable_opts) { $_out->(' '); } $_out->(' '); } # end data display $_out->('
'); $m->comp('/widgets/profile/imageSubmit.mc', formName => "theForm", callback => $widget ."|add_element_cb", image => "add_element_lgreen", vspace => 3, hspace => 4); $_out->(' '); $m->comp('/widgets/profile/select.mc', name => $widget.'|add_element', options => $elem_opts, useTable => 0, multiple => 0, size => 1,); $_out->(' '); if ($repeatable_opts) { $_out->('
'); $m->comp('/widgets/profile/imageSubmit.mc', formName => "theForm", callback => $widget ."|bulk_edit_this_cb", image => "bulk_edit_lgreen", vspace => 3, hspace => 4); $_out->(' '); $m->comp('/widgets/profile/select.mc', name => $widget.'|bulk_edit_field', options => $repeatable_opts, useTable => 0,); $_out->('
'); } else { $_out->('   '); } $_out->('
'); $m->comp("/widgets/wrappers/sharky/table_bottom.mc"); # end element display } $_out->(' '); ### Start Related Story Section ### if ($is_related_story) { $m->comp('/widgets/wrappers/sharky/table_top.mc', caption => 'Related Story', number => $num++); $_out->(' '); $related_summary->($tile, 'story', $widget); $_out->(' '); $m->comp('/widgets/wrappers/sharky/table_bottom.mc'); $_out->(' '); } $_out->(' '); ### End Related Story Section ### $_out->(' '); ### Start Related Media Section ### if ($is_related_media) { $_out->(' '); $m->comp('/widgets/wrappers/sharky/table_top.mc', caption => 'Related Media ', number => $num++); $_out->(' '); $related_summary->($tile, 'media', $widget); $_out->(' '); $m->comp('/widgets/wrappers/sharky/table_bottom.mc'); $_out->(' '); } ### End Related Media Section ### $_out->(' '); if ($show_summary) { $_out->('
Delete this Element
'); $m->comp('/widgets/profile/imageSubmit.mc', formName => "theForm", callback => $widget ."|up_cb", image => "cancel_red",); $_out->('
'); } $_out->(' '); # this script creates an array with the names # of select boxes that need ordering $_out->('"); return $num; $_out->(' '); $_out->(' '); $_out->(' '); return undef; }, 'create_time'=>1001676492, 'declared_args'=> { '$title' => { 'default' => ' undef' }, '$widget' => { 'default' => undef }, '$num' => { 'default' => ' undef' }, '$show_summary' => { 'default' => ' undef' } }, 'object_size'=>14988, 'parser_version'=>0.8 ) ;