[set page_title]Edit Template[/set] [set ui_class]Content[/set] [set help_name]page.main[/set] [set icon_name]icon_pages.gif[/set] @_UI_STD_HEAD_@
[perl tables="[list-databases] __UI_META_TABLE__"] # Some inits my $template_dir = $Variable->{UI_TEMPLATE_DIR} || 'templates'; my $out = ''; $Values->{ui_theme} = $CGI->{ui_theme} if defined $CGI->{ui_theme}; $Values->{ui_theme} = $Variable->{THEME} unless defined $Values->{ui_theme}; $CGI->{ui_show_template} = 1 unless defined $CGI->{ui_show_template}; sub bleach_it { my $val = shift; $val =~ s:.*/::; $val =~ s/\W+/_/g; $val =~ s/_+/_/g; return lc($val); } sub tmp_error { my $msg = errmsg(@_); my $messages = join "\n--message--\n", @messages; return < EOF } # Probably should offload this to mv_click=process_filter my @filters = grep /^ui_filter:/, keys %$CGI; foreach my $key (@filters) { my $val = delete $CGI->{$key}; $key =~ s/ui_filter://; next unless $val; next unless defined $CGI->{$key}; $CGI->{$key} = $Tag->filter($val, $CGI->{$key}, $key); } my $new; if($CGI->{ui_template_new}) { #Debug("found new template"); $t_desc = $CGI->{ui_template_description} || $CGI->{ui_template_new}; $t_name = bleach_it($CGI->{ui_template_new}); $new = 1; } else { $t_name = bleach_it($CGI->{ui_template}); } my $t_file = "$template_dir/$t_name"; push @messages, "template: $t_name; t_file=$t_file"; ### Add some code here to check for existing templates... my $exists = -f $t_file; my $read_from; if($exists and $new) { return tmp_error( "Template named '%s', already exists, please delete first.", $t_name, ); } elsif($new and $CGI->{ui_template_template}) { Debug("reading from example template"); $read_from = $CGI->{ui_template_template}; $exists = -f $read_from; Debug("example template=$read_from exists=$exists"); } elsif($exists) { Debug("reading from existing template $t_file"); $read_from = $t_file; } my $ary; my $tref; my $name_top = uc($t_name) . "_TOP"; my $name_bot = uc($t_name) . "_BOTTOM"; my $template_input; TEMPLATE_READ: { if($exists) { ($ary) = $Tag->read_ui_template($read_from); $tref = shift @$ary; ref($tref) =~ /HASH/ or return tmp_error( "Template read error reading '%s'.", $read_from, ); last TEMPLATE_READ; } $tref = {}; $tref->{ui_template} = $t_name; $tref->{ui_template_name} = $t_name; $tref->{ui_template_layout} = "$name_top, UI_CONTENT, $name_bot"; $tref->{ui_template_description} = $t_desc; my $content; if( $Values->{ui_upload_template} and $Tag->value_extended( { name => 'ui_upload_template', test => 'isfile', } ) ) { push @messages, "template from upload:\n$tref->{ui_definition}"; $template_input = $Tag->value_extended( { name => 'ui_upload_template', file_contents => 1, }); #push @messages, "template from upload is:\n$template_input"; $template_input =~ s{(.*)()}{$2}is; $template_top = $1; $template_top =~ s/^\s+//; $template_top =~ s/\s+$//; $template_input =~ s{()\n*(.*)}{$1\n}is; $template_bot = $2; $template_bot =~ s/^\s+//; $template_bot =~ s/\s+$//; $content = $template_input; $content =~ s/^\s*'}egsix; $template_div = $cnum unless $template_div; } } elsif ($template_top) { for(\$template_top, \$template_bot) { $$_ =~ s{ \[include\s+ [^\]]+ \[control\s+component [^\]]+ \] [^\]]* \] (?:\s*\[control\])?} {''}egsix; $template_div = $cnum unless $template_div; } my $ref = $tref->{ui_display_order} || []; @comp_order = @{$ref}[0..$cnum - 1]; } for (my $i = 0; $i < @comp_order; $i++) { my $compname = $comp_order[$i]; my $comptype = $comp_type[$i]; # Parens needed for array context my ($carray) = $Tag->read_ui_template("$compdir/$compname"); push @messages, ("Read component $compname=$carray."); if ($carray and scalar @$carray) { $carray->[0]->{ui_component_type_current} = $comptype; push @cobj, @$carray; } else { my $desc = -f "$compdir/$compname" ? 'Static component, no controls' : 'placeholder'; push @cobj, { ui_component => $compname, ui_component_name => $compname, ui_component_description => $desc, ui_component_type => $comptype, }; } } $template_top_display = $template_top; $template_bot_display = $template_bot; my $template_top_widget; my $template_bot_widget; for(\$template_top_display, \$template_bot_display, $content_display) { $$_ =~ s/\&/\&/g; $$_ =~ s/\[/[/g; $$_ =~ s/{ui_show_template}; EOF # Find the current settings if($current =~ m/ \[control \s+ reset \s* = \s* ["']? [^0] [^\]]* \] (.*) \[control \s+ reset \s* = \s* ["']? [^0] [^\]]* \] /six) { @comp_default = split /\s*\[control\]\s*/, $1; } my $idx = 0; my $num = $idx + 1; sub get_unified_ref { my ($name, $ref) = @_; my $uniref = {}; for(keys %$ref) { next unless ref($ref->{$_}) eq 'HASH'; $uniref->{$_} = $ref->{$_}{$name} || undef; } return $uniref; } my $sep_template = < EOF my $break_template = < EOF my $control_template = < EOF #Debug("calling read_ui_template $compdir/*"); my ($components) = $Tag->read_ui_template("$compdir/*"); my @copts; for(@$components) { #Debug("Found component: " . uneval($_)); my $hash = $_; my $key = $hash->{ui_component_name} || $hash->{ui_component}; my $val = $hash->{ui_component_label} || $hash->{ui_component_description}; my $tkey = $hash->{ui_component_type}; $key =~ s/"/"/g; $val =~ s/"/"/g; $val =~ s/,/,/g; push @copts, "$key=$val"; push @topts, grep /\S/, split /[\s,\0]+/, $tkey; } my $template_break; my $opt_string = join ",", "NONE=none", @copts; my %seen; my $topt_string = join ",", grep !$seen{$_}++, "ALL", @topts; for(my $i = 0; $i < @cobj; $i++) { $template_break = scalar(@controls) if $template_div == $i; my $ref = $cobj[$i]; my $c_name = $ref->{ui_component_name} || $ref->{ui_component} || 'None'; my $c_type = $ref->{ui_component_type}; my $c_type_curr = $ref->{ui_component_type_current}; my $c_label = $ref->{ui_component_label} || $ref->{ui_component_description} || 'no description'; push @messages, "ui_component_name=$ref->{ui_component_name}"; push @messages, "ui_component=$ref->{ui_component}"; push @messages, "ui_component_label=$ref->{ui_component_label}"; push @messages, "ui_component_description=$ref->{ui_component_description}"; my @def; my $titlebar = $sep_template; $titlebar =~ s/~INCREMENT~/$i + 1/eg; $titlebar =~ s/~NAME~/$c_name/g; $titlebar =~ s/~DESC~/$c_label/g; $titlebar =~ s/~VARNAME~/$i.ui_component/g; push @controls, $titlebar; my $def_string = $ref->{ui_definition}; $def_string =~ s/"/"/g; my $short_def = "ui_component: $c_name"; my $deftext = $comp_default[$i]; my $help =<{element}(or $ref->{element})"); $widget = $Tag->display( { name => "$i.ui_control_component", type => 'select', passed => $opt_string, override => $c_name, default => $c_name, help => $help, label => "Component", filter => 'null_to_comma', template => $control_template, }); push @messages, "widget='$widget'"; # No meta for now $widget =~ s/~[A-Z]{3,}~//g; push @controls, $widget; $widget = $Tag->display( { name => "$i.ui_control_component_type", type => 'select', passed => $topt_string, override => $c_type_curr, default => $c_type_curr, help => "Type of component for slot", label => "Component type", filter => 'null_to_comma', template => $control_template, }); push @messages, "widget='$widget'"; # No meta for now $widget =~ s/~[A-Z]{3,}~//g; push @controls, $widget; } $template_bot_widget = <{ui_show_template}; EOF $out .= < EOF for(my $n = 0; $n < $template_break; $n++) { $out .= $controls[$n]; } $out .= $template_top_widget if $template_top_widget; $out .= < EOF my @candidates = grep ! -f $_, $Tag->list_glob("$template_dir/*/regions"); for(@candidates) { s:/regions$::; s:.*/::; $Scratch->{available_themes} = join " ", @candidates; } for(my $n = $template_break; $n < @controls; $n++) { $out .= $controls[$n]; } $out .= $template_bot_widget if $template_bot_widget; return $out; return $out . tmp_error("Finished checking first part."); [/perl]
$msg
$messages
Top of template
Component #~INCREMENT~ current: ~NAME~ - ~DESC~
\$LABEL\$~META~
\$WIDGET\$ ~TKEY~\$HELP\${HELPURL}
help{/HELPURL}
Bottom of template
Top Region
Bottom Region
[set Preview] mv_nextpage=__UI_BASE__/template_preview mv_action=back [/set] [set Save] mv_nextpage=__UI_BASE__/template_save [/set] [set Munge] [perl] $CGI->{good_template} = 1; return; [/perl] [/set] Theme:      
Show template:
[if cgi ui_show_template] Yes    No [else] Yes    No [/else] [/if]
@_UI_STD_FOOTER_@