[interchange-cvs] interchange - heins modified dist/lib/UI/ContentEditor.pm

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Wed Jan 22 10:28:00 2003


User:      heins
Date:      2003-01-22 15:26:59 GMT
Modified:  dist/lib/UI ContentEditor.pm
Log:
* Fix a couple of bugs in template edits and saves.

	-- When first created, a template was properly written but the
	   version saved in the session store did not match it and
	   prevented page creation.

	-- If a label was not put in at creation time, could not be added
	   later.

Revision  Changes    Path
2.8       +33 -7     interchange/dist/lib/UI/ContentEditor.pm


rev 2.8, prev_rev 2.7
Index: ContentEditor.pm
===================================================================
RCS file: /var/cvs/interchange/dist/lib/UI/ContentEditor.pm,v
retrieving revision 2.7
retrieving revision 2.8
diff -u -r2.7 -r2.8
--- ContentEditor.pm	13 Sep 2002 20:46:20 -0000	2.7
+++ ContentEditor.pm	22 Jan 2003 15:26:59 -0000	2.8
@@ -2,7 +2,7 @@
 #
 # UI::ContentEditor - Interchange page/component edit
 # 
-# $Id: ContentEditor.pm,v 2.7 2002/09/13 20:46:20 mheins Exp $
+# $Id: ContentEditor.pm,v 2.8 2003/01/22 15:26:59 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -23,7 +23,7 @@
 
 package UI::ContentEditor;
 
-$VERSION = substr(q$Revision: 2.7 $, 10);
+$VERSION = substr(q$Revision: 2.8 $, 10);
 $DEBUG = 0;
 
 use POSIX qw/strftime/;
@@ -101,6 +101,16 @@
 	return undef;
 }
 
+sub delete_store {
+	my $type = shift;
+	my $name = shift;
+	die("Must have type and name for delete_store, args were: " . join(" ", @_))
+		unless $type and $name;
+	my $store = $Vend::Session->{content_edit} ||= {};
+	$store->{$type} ||= {};
+	delete $store->{$type}{$name};
+}
+
 sub save_store {
 	my $type = shift;
 	my $name = shift;
@@ -208,9 +218,11 @@
 	my @out;
 	my @comp;
 
+#::logDebug("ui_template_layout=$tref->{ui_template_layout}");
 	if(! ref $tref->{ui_template_layout}) {
 		$tref->{ui_template_layout} = [split /\s*,\s*/, $tref->{ui_template_layout}];
 	}
+#::logDebug("ui_template_layout=$tref->{ui_template_layout}");
 	$things = $tref->{ui_template_layout} || [];
 
 	for(@$things) {
@@ -355,7 +367,7 @@
 		last;
 	}
 
-	if($idx > $#$p) {
+	if($idx > $#$p and $#$p > 0) {
 		pain (	'parse_page',
 				"No content slot found in page %s",
 				$pref->{ui_page_template},
@@ -379,7 +391,7 @@
 	splice @$p, $idx, 0, $content;
 #::logDebug("page slots now=" . uneval($p));
 
-	if($idx > $#$t) {
+	if($idx > $#$t and $#$t > 0) {
 		pain (	'parse_page',
 				"No content slot found in template %s",
 				$pref->{ui_page_template},
@@ -1906,9 +1918,12 @@
 	
 	$found_something += scalar(@sets);
 
+#::logDebug("publish_page ref=" . ::uneval($ref));
+
 	# Things we want every time
 	my $layout = delete $ref->{ui_template_layout} || [];
 
+#::logDebug("layout=" . ::uneval($layout));
 	my @header;
 
 	my $slots = delete $ref->{ui_slots} || [];
@@ -1958,6 +1973,9 @@
 			$found_something++;
 			push @bods, '@_' . $var . '_@';
 		}
+		else {
+#::logDebug("bad bod: $var");
+		}
 	}
 
 	if($ref->{POSTAMBLE} =~ /\S/) {
@@ -2274,7 +2292,7 @@
 	$dest =~ s/\s+$//;
 	$dest =~ s/^\s+$//;
 	my $record = ref_content($ref, $opt)
-		or return death("publish_template", "bad news");
+		or return death("publish_page", "bad news");
 	my $text = format_page($ref);
 	$record->{page_text} = $text;
 #::logDebug("header record: " . uneval($record));
@@ -2293,6 +2311,7 @@
 	my $text = format_template($ref);
 	$record->{temp_text} = $text;
 #::logDebug("header record: " . uneval($record));
+	delete_store('template', $record->{code});
 	write_template($record);
 }
 
@@ -2503,18 +2522,25 @@
 	},
 );
 
+my %always_top = (
+	default => {
+		ui_label   => 1,
+	},
+);
+
 sub modify_top_attribute {
 	my ($ref, $opt) = @_;
 	my $vref = $opt->{values_ref} || \%CGI::values;
 
 	my $illegal = $illegal_top{$ref->{ui_type}} || $illegal_top{default};
+	my $always = $always_top{$ref->{ui_type}} || $always_top{default};
 
 	my @found;
 	for(keys %$vref) {
 #::logDebug("checking $_ ($ref->{$_} -> $vref->{$_}) for legality");
 		next if $illegal->{$_};
-		next unless defined $ref->{$_};
-#::logDebug("$_ is legal and defined in ref");
+		next unless defined $ref->{$_} or $always->{$_};
+#::logDebug("$_ is legal and defined in ref (or is always allowed)");
 		push @found, $_;
 	}