Permalink
Browse files

* Fix multiple problems with creating a new page in the content

  editor. TODO: Check behavior with new templates and components.

* Change default for HTML files in File Transfer to view as text.

* Retain CWD for File Transfer. Before, since the [file-navigator ..]
  was used to display admin/content.html, it would get set to
  templates/components.
  • Loading branch information...
1 parent 4c19058 commit c8d4344f8143653123a0509fbdef9d7dbe366d60 @perusionmike perusionmike committed Jun 27, 2002
@@ -2,7 +2,7 @@
#
# UI::ContentEditor - Interchange page/component edit
#
-# $Id: ContentEditor.pm,v 2.3 2002-06-03 17:46:00 kwalsh Exp $
+# $Id: ContentEditor.pm,v 2.4 2002-06-27 20:18:36 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -23,7 +23,7 @@
package UI::ContentEditor;
-$VERSION = substr(q$Revision: 2.3 $, 10);
+$VERSION = substr(q$Revision: 2.4 $, 10);
$DEBUG = 0;
use POSIX qw/strftime/;
@@ -148,6 +148,7 @@ sub parse_template {
my ($tref, $opt) = @_;
$opt ||= {};
+
my $type = $tref->{ui_type};
my $tdb = get_tdb();
@@ -349,14 +350,20 @@ sub parse_page {
}
if(! $tref) {
+#::logDebug("no tref first try...");
my $topt = { %$opt };
undef $topt->{dir};
+ undef $topt->{new};
$topt->{type} = 'template';
#$topt->{single} = 1;
$tref = read_template($tpl, $topt);
}
+ assert('template_reference', $tref, 'HASH')
+ or undef $tref;
+
if (! $tref) {
+#::logDebug("no tref second try...");
pain('read_template', '%s %s not found', 'template', $tpl);
$tref = read_template('', { new => 1, type => 'template'});
}
@@ -373,12 +380,12 @@ sub parse_page {
my $body = delete $pref->{ui_body};
unless(defined $body) {
- ### Already parsed, match slots and leave
+ ### Already parsed, match slots and leave if not new page
match_slots($pref, $tref);
- return;
+ return unless $opt->{new};
}
- my @slots = @{ $tref->{ui_slots} || [] };
+ my @slots = @{ $pref->{ui_slots} || $tref->{ui_slots} || [] };
#$body =~ s/\r\n/\n/g;
@@ -485,7 +492,7 @@ sub parse_page {
while($controls =~ s{
(?:
\[
- (set|tmp(?:[-_]no)?|seti)
+ (seti?|tmpn?)
\s+
([^\]]+)
\]
@@ -724,6 +731,7 @@ sub read_template {
my $might_be_single;
if(! @data and $opt->{new}) {
+#::logDebug("no data, and new");
$opt->{type} ||= 'page';
my $prefix = "ui_$opt->{type}";
my $ref = {
@@ -752,6 +760,7 @@ sub read_template {
foreach my $dref (@data) {
my ($data, $source) = @{$dref || []};
+#::logDebug("data is $data");
my $type;
my $ref;
@@ -906,17 +915,20 @@ sub read_template {
}
sub page_component_editor {
my ($name, $pos, $comp, $pref, $opt) = @_;
-#::logDebug("called page_component_editor, comp=" . ::uneval($comp));
assert('page reference', $pref, 'HASH')
or return undef;
assert('component reference', $comp, 'HASH')
or return undef;
+ $name ||= $comp->{code};
+
+#::logDebug("called page_component_editor, name=$name comp=" . ::uneval($comp));
my $hidden = {
ui_name => $pref->{ui_name},
ui_source => $pref->{ui_source},
+ ui_page_template => $pref->{ui_page_template},
ui_type => $pref->{ui_type},
ui_content_op => 'modify_component',
ui_content_pos => $pos,
@@ -928,6 +940,7 @@ sub page_component_editor {
my $topt = { %$opt };
delete $topt->{dir};
+ delete $topt->{new};
$topt->{type} = 'component';
my $cref = $store->{$name} || read_template($name, $topt);
@@ -1182,6 +1195,7 @@ sub page_region {
for my $c (@$slots) {
$pos++;
my $r = { %$c };
+ $r->{component} ||= $r->{code};
#::logDebug("slot pos=$pos, slot=" . ::uneval($c));
delete $r->{_editor_table};
if($r->{where}) {
@@ -1447,7 +1461,7 @@ sub format_page {
push @bods, $body;
push @bods, "<!-- END CONTENT -->";
}
- else {
+ elsif ($var =~ /^[A-Z]/) {
push @bods, '@_' . $var . '_@';
}
}
@@ -2147,8 +2161,11 @@ sub page_editor {
my $tmp;
if(! $pref) {
- $opt->{new} = 1;
+#::logDebug("No page template");
+ $opt->{new_page} = 1;
+ $opt->{template} ||= $opt->{ui_page_template};
$pref = read_template($opt->{ui_name}, $opt);
+#::logDebug("page template=$pref");
$name = $opt->{ui_name} || $opt->{name} || 'new';
$pref->{ui_name} = $name;
}
@@ -2163,6 +2180,7 @@ sub page_editor {
$pstore->{$name} = $pref;
parse_page($pref, $opt);
+ publish_page($pref, $opt) if $opt->{new_page};
#::logDebug("found a template name=$pref->{ui_name} store=$pstore: " . uneval($pref));
my ($overall, $comp) = page_region($pref, $opt);
@@ -2340,6 +2358,7 @@ sub editor {
my $template;
$opt->{type} ||= 'page';
+ $opt->{ui_page_template} ||= $CGI->{ui_page_template};
## If we get a ref, assume it is already parsed
if(ref $item) {
@@ -20,6 +20,7 @@
[/if]
[calc]
+ $cwd = $Session->{ui_cwd};
sub tmp_display_in_progress {
my ($type) = shift;
my $store;
@@ -136,6 +137,7 @@ <h2>Components</h2>
edit_page=content_editor
edit_form="ui_name=~RN~&ui_type=component"
]
+ [calc] $Session->{ui_cwd} = $cwd; return; [/calc]
</td>
</tr>
@@ -29,12 +29,70 @@
They can be relocated to a catalog-specific place
by copying to CATROOT/include.
[/comment]
-[if cgi ui_type eq component]
+[if cgi new]
+<form action="[area __UI_BASE__/content_editor]">
+<table width="60%">
+<tr>
+ <td style="font-weight: bolder; text-align: right">
+ [calc] return "\u$CGI->{ui_type}"; [/calc] name
+ </td>
+ <td>
+ [set page_name_click]
+ [calc]
+ $CGI->{ui_name} =~ s/^\s+//;
+ $CGI->{ui_name} =~ s/\s+$//;
+ $CGI->{ui_name} = $Tag->filter({
+ op => 'filesafe',
+ body => $CGI->{ui_name},
+ });
+ my $pat = quotemeta $Config->{HTMLsuffix};
+ #Debug("pat=$pat");
+ $pat = qr/$pat$/;
+ #Debug("pat=$pat");
+ $CGI->{ui_name} .= $Config->{HTMLsuffix}
+ unless $CGI->{ui_name} =~ $pat;
+ #Debug("page=$CGI->{ui_name}");
+ return;
+ [/calc]
+ [/set]
+ <input type=text name="ui_name" size=30>
+ <input type=hidden name="mv_action" value="back">
+ <input type=hidden name="mv_click" value="page_name_click">
+ <input type=hidden name="ui_type" value="[cgi ui_type]">
+ <input type=hidden name="ui_return_to" value="[cgi ui_return_to]">
+ </td>
+</tr>
+ [if cgi ui_type eq page]
+<tr>
+ <td style="font-weight: bolder; text-align: right">
+ Template type:
+ </td>
+ <td>
+ [display
+ name=ui_page_template
+ type=select
+ default="[page-param ui_page_template]"
+ passed="[content-info templates=1]"
+ ]
+ </td>
+</tr>
+ [/if]
+<tr>
+ <td> &nbsp; </td>
+ <td>
+ <input type=submit value="[L]Create new page[/L]">
+ </td>
+</tr>
+</table>
+</form>
+[elsif cgi ui_type eq component]
[include include/component_editor]
+[/elsif]
[elsif cgi ui_type eq template]
[include include/template_editor]
[/elsif]
[else]
+ [set page_name_click][/set]
[include include/page_editor]
[/else]
[/if]
@@ -50,7 +50,8 @@
else {
$Scratch->{content_type} = $Tag->filter('mime_type', $_);
$Scratch->{content_type} = $CGI->{content_type} || "text/plain"
- if $Scratch->{content_type} eq 'application/octet-stream';
+ if $Scratch->{content_type} eq 'application/octet-stream'
+ or $Scratch->{content_type} eq 'text/html';
}
return;
[/perl][if scratch violation]
@@ -1,4 +1,4 @@
-[content-editor name="[cgi ui_name]" type="[cgi ui_type]"]
+[content-editor name="[cgi ui_name]" type="page"]
[pages]
<script language=JavaScript>

0 comments on commit c8d4344

Please sign in to comment.