From e9d2161caf30587eda32b2edf9ae3b2a3ee3245a Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 26 Nov 2002 00:48:47 +0000 Subject: [PATCH] Templatized the Link List wobject. --- docs/gotcha.txt | 2 + docs/upgrades/upgrade_4.8.0-4.9.0.sql | 13 +++ lib/WebGUI/Wobject.pm | 18 ++-- lib/WebGUI/Wobject/LinkList.pm | 133 +++++++++++++------------- 4 files changed, 93 insertions(+), 73 deletions(-) diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 178e3e5c1..4ec864dd1 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -14,6 +14,8 @@ save you many hours of grief. the template language has changed slightly for greater flexibility. + * All Link Lists have been reset to the default template. + 4.8.0 -------------------------------------------------------------------- diff --git a/docs/upgrades/upgrade_4.8.0-4.9.0.sql b/docs/upgrades/upgrade_4.8.0-4.9.0.sql index 31d9c86fb..6cab69ec8 100644 --- a/docs/upgrades/upgrade_4.8.0-4.9.0.sql +++ b/docs/upgrades/upgrade_4.8.0-4.9.0.sql @@ -942,6 +942,19 @@ INSERT INTO template VALUES (3,'Topics','\r\n

\r\n \r\n \">\r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n - \r\n \">\" border=\"0\" alt=\"\" width=\"16\" height=\"16\" border=\"0\" align=\"middle\" />\r\n\r\n\r\n\r\n - \r\n','Item'); INSERT INTO template VALUES (2,'Item w/pop-up Links','\r\n \r\n \">\r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n - \r\n \" target=\"_blank\">\" border=\"0\" alt=\"\" width=\"16\" height=\"16\" border=\"0\" align=\"middle\" />\r\n\r\n\r\n\r\n - \r\n','Item'); +delete from international where namespace='LinkList' and internationalId=1; +delete from international where namespace='LinkList' and internationalId=2; +delete from international where namespace='LinkList' and internationalId=4; +delete from international where namespace='LinkList' and internationalId=5; +insert into international (internationalId,languageId,namespace,message,lastUpdated) values (74,1,'LinkList','Add a new link.', 1038268049); +alter table LinkList add column templateId int not null default 1; +alter table LinkList drop column indent; +alter table LinkList drop column lineSpacing; +alter table LinkList drop column bullet; +INSERT INTO template VALUES (1,'Default Link List','\r\n

\r\n
\r\n\r\n\r\n

\r\n\r\n\r\n\r\n \">

\r\n\r\n\r\n\r\n \r\n \r\n \r\n ·\r\n \r\n target=\"_blank\"\r\n \r\n >\r\n\r\n \r\n - \r\n \r\n
\r\n
\r\n','LinkList'); +INSERT INTO template VALUES (2,'Unordered List','\r\n

\r\n
\r\n\r\n\r\n

\r\n\r\n\r\n\r\n \">

\r\n\r\n\r\n

    \r\n\r\n
  • \r\n \r\n \r\n \r\n \r\n \r\n target=\"_blank\"\r\n \r\n >\r\n\r\n \r\n - \r\n \r\n
  • \r\n
    \r\n','LinkList'); +INSERT INTO template VALUES (3,'Ordered List','\r\n

    \r\n
    \r\n\r\n\r\n

    \r\n\r\n\r\n\r\n \">

    \r\n\r\n\r\n

      \r\n\r\n
    1. \r\n \r\n \r\n \r\n\r\n \r\n target=\"_blank\"\r\n \r\n >\r\n\r\n \r\n - \r\n \r\n
    2. \r\n
      \r\n
    ','LinkList'); +INSERT INTO template VALUES (4,'Descriptive','\r\n

    \r\n
    \r\n\r\n\r\n

    \r\n\r\n\r\n\r\n \">

    \r\n\r\n\r\n\r\n \r\n
    \r\n
    \r\n\r\n \r\n target=\"_blank\"\r\n \r\n >\r\n\r\n \r\n - \r\n \r\n

    \r\n\r\n','LinkList'); diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm index 44d8116ab..7465894a1 100644 --- a/lib/WebGUI/Wobject.pm +++ b/lib/WebGUI/Wobject.pm @@ -607,7 +607,7 @@ sub purge { sub reorderCollateral { my ($sth, $i, $id, $setName, $setValue); - $i = 0; + $i = 1; $setName = $_[3] || "wobjectId"; $setValue = $_[4] || $_[0]->get($setName); $sth = WebGUI::SQL->read("select $_[2] from $_[1] where $setName=".quote($setValue)." order by sequenceNumber"); @@ -755,10 +755,11 @@ sub setCollateral { $dbkeys = ""; $dbvalues = ""; unless ($useSequence eq "0") { - - ($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from $table - where $setName=".quote($setValue)); - $properties->{sequenceNumber} = $seq+1; + unless (exists $properties->{sequenceNumber}) { + ($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from $table + where $setName=".quote($setValue)); + $properties->{sequenceNumber} = $seq+1; + } } unless ($useWobjectId eq "0") { $properties->{wobjectId} = $_[0]->get("wobjectId"); @@ -776,13 +777,16 @@ sub setCollateral { } else { $sql = "update $table set "; foreach $key (keys %{$properties}) { - $sql .= ',' if ($counter++ > 0); - $sql .= $key."=".quote($properties->{$key}); + unless ($key eq "sequenceNumber") { + $sql .= ',' if ($counter++ > 0); + $sql .= $key."=".quote($properties->{$key}); + } } $sql .= " where $keyName='".$properties->{$keyName}."'"; WebGUI::ErrorHandler::audit("edited ".$table." ".$properties->{$keyName}); } WebGUI::SQL->write($sql); + $_[0]->reorderCollateral($table,$keyName,$setName,$setValue) if ($properties->{sequenceNumber} < 1); return $properties->{$keyName}; } diff --git a/lib/WebGUI/Wobject/LinkList.pm b/lib/WebGUI/Wobject/LinkList.pm index 411f71dba..723465ad7 100644 --- a/lib/WebGUI/Wobject/LinkList.pm +++ b/lib/WebGUI/Wobject/LinkList.pm @@ -29,19 +29,18 @@ our $name = WebGUI::International::get(6,$namespace); #------------------------------------------------------------------- sub duplicate { - my ($w, $sth, @row, $newLinkId); + my ($w, $sth, $row); $w = $_[0]->SUPER::duplicate($_[1]); $w = WebGUI::Wobject::LinkList->new({wobjectId=>$w,namespace=>$namespace}); $w->set({ - indent=>$_[0]->get("indent"), - bullet=>$_[0]->get("bullet"), - lineSpacing=>$_[0]->get("lineSpacing") + templateId=>$_[0]->get("templateId") }); - $sth = WebGUI::SQL->read("select * from LinkList_link where wobjectId=".$_[0]->get("wobjectId")); - while (@row = $sth->array) { - $newLinkId = getNextId("LinkList_linkId"); - WebGUI::SQL->write("insert into LinkList_link values (".$w->get("wobjectId").", $newLinkId, " - .quote($row[2]).", ".quote($row[3]).", ".quote($row[4]).", '$row[5]', '$row[6]')"); + $sth = WebGUI::SQL->read("select * from LinkList_link where wobjectId=".$_[0]->get("wobjectId") + ." order by sequenceNumber"); + while ($row = $sth->hashRef) { + $row->{LinkList_linkId} = "new"; + $row->{wobjectId} = $w->get("wobjectId"); + $_[0]->setCollateral("LinkList_link","LinkList_linkId",$row); } $sth->finish; } @@ -54,7 +53,7 @@ sub purge { #------------------------------------------------------------------- sub set { - $_[0]->SUPER::set($_[1],[qw(indent bullet lineSpacing)]); + $_[0]->SUPER::set($_[1],[qw(templateId)]); } #------------------------------------------------------------------- @@ -85,10 +84,21 @@ sub www_edit { $output = helpIcon(1,$namespace); $output .= '

    '.WebGUI::International::get(10,$namespace).'

    '; $f = WebGUI::HTMLForm->new; - $f->integer("indent",WebGUI::International::get(1,$namespace),$indent); - $f->integer("lineSpacing",WebGUI::International::get(2,$namespace),$lineSpacing); - $f->text("bullet",WebGUI::International::get(4,$namespace),$bullet); - $f->yesNo("proceed",WebGUI::International::get(5,$namespace),$proceed); + $f->template( + -name=>"templateId", + -value=>$_[0]->get("templateId"), + -namespace=>$namespace, + -afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId") + ); + if ($_[0]->get("wobjectId") eq "new") { + $f->whatNext( + -options=>{ + addLink=>WebGUI::International::get(74,$namespace), + backToPage=>WebGUI::International::get(745) + }, + -value=>"addLink" + ); + } $output .= $_[0]->SUPER::www_edit($f->printRowsOnly); return $output; } @@ -97,11 +107,10 @@ sub www_edit { sub www_editSave { return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage()); $_[0]->SUPER::www_editSave({ - indent=>$session{form}{indent}, - bullet=>$session{form}{bullet}, - lineSpacing=>$session{form}{lineSpacing} + templateId=>$session{form}{templateId} }); - if ($session{form}{proceed}) { + if ($session{form}{proceed} eq "addLink") { + $session{form}{lid} = "new"; $_[0]->www_editLink(); } else { return ""; @@ -111,26 +120,33 @@ sub www_editSave { #------------------------------------------------------------------- sub www_editLink { return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage()); - my ($output, %link, $f, $linkId, $newWindow); - tie %link, 'Tie::CPHash'; - $linkId = $session{form}{lid} || "new"; - %link = WebGUI::SQL->quickHash("select * from LinkList_link where LinkList_linkId='$session{form}{lid}'"); - if ($linkId eq "new") { + my ($output, $link, $f, $linkId, $newWindow); + $link = $_[0]->getCollateral("LinkList_link", "LinkList_linkId",$session{form}{lid}); + if ($link->{LinkList_linkId} eq "new") { $newWindow = 1; } else { - $newWindow = $link{newWindow}; + $newWindow = $link->{newWindow}; } $output = helpIcon(2,$namespace); $output .= '

    '.WebGUI::International::get(12,$namespace).'

    '; $f = WebGUI::HTMLForm->new; $f->hidden("wid",$_[0]->get("wobjectId")); - $f->hidden("lid",$linkId); + $f->hidden("lid",$link->{LinkList_linkId}); $f->hidden("func","editLinkSave"); - $f->text("name",WebGUI::International::get(99),$link{name}); - $f->url("url",WebGUI::International::get(8,$namespace),$link{url}); + $f->text("name",WebGUI::International::get(99),$link->{name}); + $f->url("url",WebGUI::International::get(8,$namespace),$link->{url}); $f->yesNo("newWindow",WebGUI::International::get(3,$namespace),$newWindow); - $f->textarea("description",WebGUI::International::get(85),$link{description}); - $f->yesNo("proceed",WebGUI::International::get(5,$namespace)); + $f->textarea("description",WebGUI::International::get(85),$link->{description}); + if ($link->{LinkList_linkId} eq "new") { + $f->hidden("sequenceNumber",-1); + $f->whatNext( + -options=>{ + addLink=>WebGUI::International::get(74,$namespace), + backToPage=>WebGUI::International::get(745) + }, + -value=>"addLink" + ); + } $f->submit; $output .= $f->print; return $output; @@ -144,9 +160,10 @@ sub www_editLinkSave { description => $session{form}{description}, newWindow => $session{form}{newWindow}, url => $session{form}{url}, - name => $session{form}{name} + name => $session{form}{name}, + sequenceNumber=>$session{form}{sequenceNumber} }); - if ($session{form}{proceed}) { + if ($session{form}{proceed} eq "addLink") { $session{form}{lid} = "new"; return $_[0]->www_editLink(); } else { @@ -170,43 +187,27 @@ sub www_moveLinkUp { #------------------------------------------------------------------- sub www_view { - my ($i, $indent, $lineSpacing, %link, $output, $sth); - tie %link,'Tie::CPHash'; - $output = $_[0]->displayTitle; - $output .= $_[0]->description; - if ($session{var}{adminOn}) { - $output .= '

    '.WebGUI::International::get(13,$namespace).'

    '; - } - for ($i=0;$i<$_[0]->get("indent");$i++) { - $indent .= " "; - } - for ($i=0;$i<$_[0]->get("lineSpacing");$i++) { - $lineSpacing .= "
    "; - } - $sth = WebGUI::SQL->read("select * from LinkList_link where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber"); - while (%link = $sth->hash) { - if ($session{var}{adminOn}) { - $output .= deleteIcon('func=deleteLink&wid='.$_[0]->get("wobjectId").'&lid='.$link{LinkList_linkId}) - .editIcon('func=editLink&wid='.$_[0]->get("wobjectId").'&lid='.$link{LinkList_linkId}) - .moveUpIcon('func=moveLinkUp&wid='.$_[0]->get("wobjectId").'&lid='.$link{LinkList_linkId}) - .moveDownIcon('func=moveLinkDown&wid='.$_[0]->get("wobjectId").'&lid='.$link{LinkList_linkId}) - .' '; - } else { - $output .= $indent.$_[0]->get("bullet"); - } - $output .= ''; - if ($link{description} ne "") { - $output .= ' - '.$link{description}; - } - $output .= $lineSpacing; + my (%var, @linkloop, $controls, $link, $sth); + $var{"addlink.url"} = WebGUI::URL::page('func=editLink&lid=new&wid='.$_[0]->get("wobjectId")); + $var{"addlink.label"} = WebGUI::International::get(13,$namespace); + $sth = WebGUI::SQL->read("select * from LinkList_link where wobjectId=".$_[0]->get("wobjectId")." + order by sequenceNumber"); + while ($link = $sth->hashRef) { + $controls = deleteIcon('func=deleteLink&wid='.$_[0]->get("wobjectId").'&lid='.$link->{LinkList_linkId}) + .editIcon('func=editLink&wid='.$_[0]->get("wobjectId").'&lid='.$link->{LinkList_linkId}) + .moveUpIcon('func=moveLinkUp&wid='.$_[0]->get("wobjectId").'&lid='.$link->{LinkList_linkId}) + .moveDownIcon('func=moveLinkDown&wid='.$_[0]->get("wobjectId").'&lid='.$link->{LinkList_linkId}); + push(@linkloop, { + "link.url"=>$link->{url}, + "link.controls"=>$controls, + "link.newWindow"=>$link->{newWindow}, + "link.name"=>$link->{name}, + "link.description"=>$link->{description} + }); } $sth->finish; - return $_[0]->processMacros($output); + $var{link_loop} = \@linkloop; + return $_[0]->processMacros($_[0]->processTemplate($_[0]->get("templateId"),\%var)); }