[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_@ [loop search=" fi=backup co=yes sf=sku se=[cgi ui_template] st=db tf=mod_time to=nr rf=code,page_name,mod_time "] [on-match]

[loc]Backup copies[/loc]

[/on-match] [list] [page href="__UI_BASE__/template_edit" form=" ui_template=[cgi ui_template] ui_template_backup=[loop-code] "][loop-param page_name] (save time [convert-date][loop-param mod_time][/convert-date]( [page href=__UI_BASE__/page_edit_diff form=" current=[cgi ui_template] previous=[loop-code] "]diff, [page href=__UI_BASE__/page_edit_diff form=" current=[cgi ui_template] previous=[loop-code] context=1 "]context diff from [cgi ui_template])
[/list] [on-match]
[/on-match] [/loop]
[perl tables="[list-databases] __UI_META_TABLE__"] # Some inits my $template_dir = $Variable->{UI_TEMPLATE_DIR} || 'templates'; my $out = ''; my $ver = $Tag->version(); $Values->{ui_theme} = $CGI->{ui_theme} if defined $CGI->{ui_theme}; $Values->{ui_theme} = $Variable->{THEME} unless defined $Values->{ui_theme}; sub bleach_it { my $val = shift; $val =~ s/\s+$//g; $val =~ s/^\s+//g; $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 } my $new; my $ary; my $tref; my $t_name; my $t_desc; 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 { #Debug("named template cgi=$CGI->{ui_template}"); $t_name = $CGI->{ui_template}; } #Debug(sprintf "template name=$t_name, length %d", length($t_name)); return tmp_error("No name for template.") unless $t_name =~ /\S/; # my $current; # if (! $CGI->{ui_template_backup}) { # $current = $Scratch->{ui_current_content}; # } # else { # $current = tag_data('backup', 'page_text', $CGI->{ui_template_backup}); # $current = $Tag->filter('decode_entities', $current); # if(! length($current)) { # return tmp_error( # "Backup retrieval (%s) failed.", # $CGI->{ui_template_backup}, # ); # } # } my %hidden; #Log("current begins: " . substr($current, 0, 1000) ); # 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 $t_revert; if($new and $CGI->{ui_template_template}) { #Log("found change of template"); $t_revert = $t_name; $t_name = $CGI->{ui_template_template}; } elsif ($Scratch->{ui_template_structure}) { $tref = delete $Scratch->{ui_template_structure}; $t_name = $tref->{ui_template_name}; } else { $t_name = $CGI->{ui_template}; } #Log("template reference: " . uneval($tref) ); if($t_name =~ m{/}) { $t_name =~ s:(.*)/(.*)::; my $p = $1; $t_name = bleach_it($2); $t_file = "$p/$t_name"; } else { $t_name = bleach_it($t_name); $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; TEMPLATE_READ: { last TEMPLATE_READ if $tref; last TEMPLATE_READ if ! $exists; ($ary) = $Tag->read_ui_template($t_file); $tref = shift @$ary; ref($tref) =~ /HASH/ or return tmp_error( "Template read error reading '%s'.", $t_name, ); last TEMPLATE_READ if $tref; } if($new and ! $tref) { $tref = {}; my $name_top = uc($t_name) . "_TOP"; my $name_bot = uc($t_name) . "_BOTTOM"; $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; $tref->{ui_definition} = $tref->{ui_short_definition} = <{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, }); $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; $$_ =~ s/\&/\&/g; $$_ =~ s/\[/[/g; $$_ =~ s/read_ui_page( { body => $current } ) || {}; return tmp_error("No page content!") unless $pref; my @settings; if($pref->{ui_component}[0]) { @settings = @{ $pref->{ui_component} }; for (my $i = 0; $i < @cobj; $i++) { my $grp = $cobj[$i]->{ui_component_type_current}; my $name = $settings[$i]->{component}; undef $grp if $grp eq 'ALL'; my $ref = $chash->{$name} || $chash->{none}; $cobj[$i] = { %$ref }; $cobj[$i]->{ui_component_type_current} = $grp; } } my $content; length($current) and $current =~ m{\n*(.*)\n*}is and $content = $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; } sub comp_selector { my ($type, $curr, $name) = @_; #Log("called type=$type curr=$curr name=$name"); $name = 'ui_component' unless $name; my $all = $ctype->{ALL} || [ 'none' ]; my $ary = $ctype->{$type} || $ctype->{EVERY}; $ary = $ctype->{EVERY} unless @$ary; #Log("ary is: " . uneval($ary) ); my @comps; push @comps, @$ary, @$all; my %seen; @comps = grep !$seen{$_}++, @comps; my $out = qq{}; } sub type_selector { my ($type, $curr, $name) = @_; #Log("called type=$type curr=$curr name=$name"); $name = 'ui_component_type' unless $name; my @comps = grep /\S/, split /[\0\s,]+/, $type; unshift @comps, $curr; my %seen; @comps = grep !$seen{$_}++, @comps; my $out = qq{}; } my $vsize; sub get_vsize { my ($body, $min, $max) = @_; my $size = $body =~ tr/\n/\n/; $max = 100 unless $max; $min = 20 unless $min; if($size < $min) { $size = $min; } elsif ($size > $max) { $size = $max; } else { $size++; } return $size; } my @globals; @globals = @{$tref->{ui_display_order}} if $tref->{ui_display_order}; push @controls, title_row("Page Settings"); my $glob = ''; for my $g (@globals) { $glob .= "$g:\n"; for(qw/description help options height width filter prefilter/) { $glob .= "\t$_: $tref->{$_}{$g}\n" if ref $tref->{$_}; } $glob .= "\n"; } $vsize = get_vsize($glob, 10); my $preamble_widget = < EOF push @controls, $preamble_widget; $vsize = get_vsize($template_top_display); push @controls, < EOF my $norest_select = $tref->{ui_template_limit_tag} ? '' : ' SELECTED'; my $content_widget = < EOF push @controls, title_row("Top Components") if @cobj; for(my $i = 0; $i < @cobj; $i++) { my $ref = $cobj[$i]; my $settings = $settings[$i] || {}; if($template_div and $i >= $template_div) { push @controls, title_row("Content"); push @controls, $content_widget; push @controls, title_row("Bottom Components"); undef $template_div; } my $c_name = $ref->{ui_component} || 'none'; 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/~NAME~/$c_name/g; $titlebar =~ s/~NAMESEL~/comp_selector($c_type_curr || $c_type, $c_name, "$i.ui_component")/ge; $titlebar =~ s/~NUMBER~/$i + 1/eg; $titlebar =~ s/~TYPE~/$c_type/g; $titlebar =~ s/~TYPESEL~/type_selector($c_type, $c_type_curr, "$i.ui_component_type")/eg; $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"; } if(defined $template_div) { push @controls, title_row("Content"); push @controls, $content_widget; undef $template_div; } $out .= join "\n", @controls; $out .= < EOF $hidden{good_template} = 1; my $hidden = ''; for(keys %hidden) { $hidden .= qq{\n}; } $Scratch->{tmp_hidden} = $hidden; return $out; [/perl]
$msg
$messages
Page Settings (accessed via scratch in header/footer)
Top of template
Content tag restrict
Restricts embedded ITL tags to page, area, and value
Bottom of template
or input below:
[set Preview] mv_todo=back mv_nextpage=__UI_BASE__/template_preview [/set] [set Save] mv_nextpage=__UI_BASE__/template_save [/set] [scratchd tmp_hidden]
[comment] Save template in page [/comment]
@_UI_STD_FOOTER_@