move catalog module into bse module dir
authorAdrian Oldham <adriann@visualthought.com.au>
Sat, 30 Aug 2014 01:55:36 +0000 (11:55 +1000)
committerAdrian Oldham <adriann@visualthought.com.au>
Mon, 1 Sep 2014 10:14:25 +0000 (20:14 +1000)
18 files changed:
MANIFEST
schema/article.txt
site/cgi-bin/modules/BSE/API.pm
site/cgi-bin/modules/BSE/Edit/Article.pm
site/cgi-bin/modules/BSE/Edit/Catalog.pm
site/cgi-bin/modules/BSE/Edit/Product.pm
site/cgi-bin/modules/BSE/Generate/Article.pm
site/cgi-bin/modules/BSE/Generate/Catalog.pm [new file with mode: 0644]
site/cgi-bin/modules/BSE/Importer/Target/Product.pm
site/cgi-bin/modules/BSE/ProductImportXLS.pm
site/cgi-bin/modules/BSE/TB/SiteCommon.pm
site/cgi-bin/modules/BSE/UI/AdminShop.pm
site/cgi-bin/modules/Generate/Catalog.pm [deleted file]
site/docs/.gitignore
site/docs/makedocs
site/util/initial.pl
t/050-local/040-catalog.t
t/050-local/050-dyncat.t

index 2727047..7d43d38 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -344,7 +344,7 @@ site/cgi-bin/modules/DevHelp/Tags/Iterate.pm
 site/cgi-bin/modules/DevHelp/Validate.pm
 site/cgi-bin/modules/Generate.pm
 site/cgi-bin/modules/BSE/Generate/Article.pm
-site/cgi-bin/modules/Generate/Catalog.pm
+site/cgi-bin/modules/BSE/Generate/Catalog.pm
 site/cgi-bin/modules/BSE/Generate/Product.pm
 site/cgi-bin/modules/Generate/Subscription.pm
 site/cgi-bin/modules/OtherParent.pm
index d97aa87..34ec4a7 100755 (executable)
@@ -1,7 +1,7 @@
 1,-1,100,"My site's title","","¸","",0,0,"tr",2001-01-01 00:00:00,2099-01-01 00:00:00,"","index.tmpl","/index.html","/cgi-bin/admin/admin.pl?id=1",10000,1000,"BSE::Generate::Article",1,0,2000-11-27 00:00:00
 2,1,100,"[index subsection]","","¸","",0,0,"tr",2001-01-01 00:00:00,2099-01-01 00:00:00,"","index2.tmpl","","/cgi-bin/admin/admin.pl?id=1",10000,1000,"BSE::Generate::Article",2,2,2000-11-27 00:00:00
 3,-1,10000,"The Shop","","You can buy things here","",0,0,"tr",2001-01-01 00:00:00,2099-01-01 00:00:00,"shop","shop_sect.tmpl","/shop/index.html","/cgi-bin/admin/admin.pl?id=3",1000,1000,"BSE::Generate::Article",1,1,2001-08-27 00:00:00
-4,3,10000,"[shop subsection]",""," ","",0,0,"tr",2001-01-01 00:00:00,2099-01-01 00:00:00,"","catalog.tmpl","","/cgi-bin/admin/shopadmin.pl",1000,1000,"Generate::Catalog",2,2,2001-08-29 13:05:00
+4,3,10000,"[shop subsection]",""," ","",0,0,"tr",2001-01-01 00:00:00,2099-01-01 00:00:00,"","catalog.tmpl","","/cgi-bin/admin/shopadmin.pl",1000,1000,"BSE::Generate::Catalog",2,2,2001-08-29 13:05:00
 5,1,10000,"[sidebar subsection]","","¸","",0,0,"tr",2001-01-01 00:00:00,2099-01-01 00:00:00,"","common/sidebar_section.tmpl","","/cgi-bin/admin/admin.pl?id=5",1000,1000,"BSE::Generate::Article",2,0,2000-11-27 00:00:00
 6,2,10001,"[formatting guide]","","anchor[basic] b[Sample basic formatting:]
 indent[link[/a/1.html|regular link text]
index 0f17700..ce71599 100644 (file)
@@ -102,7 +102,7 @@ my %catalog_defaults =
   (
    template => 'catalog.tmpl',
    parentid => 3,
-   generator => 'Generate::Catalog',
+   generator => 'BSE::Generate::Catalog',
   );
 
 sub _set_dynamic {
index 61fe724..1e13ba3 100644 (file)
@@ -249,7 +249,7 @@ sub should_be_catalog {
 
   return $article->{parentid} && $parent &&
     ($article->{parentid} == $shopid || 
-     $parent->{generator} eq 'Generate::Catalog');
+     $parent->{generator} eq 'BSE::Generate::Catalog');
 }
 
 sub possible_parents {
index 79de43c..304c944 100644 (file)
@@ -42,7 +42,7 @@ sub edit_template {
                             "admin/edit_$base");
 }
 
-sub generator { "Generate::Catalog" }
+sub generator { "BSE::Generate::Catalog" }
 
 sub validate_parent {
   my ($self, $data, $articles, $parent, $rmsg) = @_;
@@ -50,7 +50,7 @@ sub validate_parent {
   my $shopid = $self->{cfg}->entryErr('articles', 'shop');
   unless ($parent && 
          ($parent->{id} == $shopid 
-          || $parent->{generator} eq 'Generate::Catalog')) {
+          || $parent->{generator} eq 'BSE::Generate::Catalog')) {
     $$rmsg = "Catalogs must be in the shop";
     return;
   }
@@ -75,7 +75,7 @@ sub possible_parents {
       $labels{$id} = $title;
       push @work, map [ $_->{id}, $title.' / '.$_->{title} ],
        sort { $b->{displayOrder} <=> $a->{displayOrder} }
-         grep $_->{generator} eq 'Generate::Catalog', 
+         grep $_->{generator} eq 'BSE::Generate::Catalog', 
            $articles->getBy(parentid=>$id);
     }
   }
index 1ffeccb..de91045 100644 (file)
@@ -366,7 +366,7 @@ sub validate_parent {
 
   my $shopid = $self->{cfg}->entryErr('articles', 'shop');
   unless ($parent && 
-         $parent->{generator} eq 'Generate::Catalog') {
+         $parent->{generator} eq 'BSE::Generate::Catalog') {
     $$rmsg = "Products must be in a catalog (not $parent->{generator})";
     return;
   }
@@ -479,10 +479,10 @@ sub possible_parents {
     $labels{$id} = $title;
     push @work, map [ $_->{id}, $title.' / '.$_->{title} ],
     sort { $b->{displayOrder} <=> $a->{displayOrder} }
-      grep $_->{generator} eq 'Generate::Catalog', 
+      grep $_->{generator} eq 'BSE::Generate::Catalog', 
       $articles->getBy(parentid=>$id);
   }
-  unless ($shop->{generator} eq 'Generate::Catalog') {
+  unless ($shop->{generator} eq 'BSE::Generate::Catalog') {
     shift @values;
     delete $labels{$shopid};
   }
index acb3df4..be07f71 100644 (file)
@@ -1232,7 +1232,7 @@ See the summary tag.
 =item generator
 
 The class used to generate the article.  Should be one of
-BSE::Generate::Article, Generate::Catalog or BSE::Generate::Product.
+BSE::Generate::Article, BSE::Generate::Catalog or BSE::Generate::Product.
 
 =item level
 
diff --git a/site/cgi-bin/modules/BSE/Generate/Catalog.pm b/site/cgi-bin/modules/BSE/Generate/Catalog.pm
new file mode 100644 (file)
index 0000000..68a2f10
--- /dev/null
@@ -0,0 +1,344 @@
+package BSE::Generate::Catalog;
+
+our $VERSION = "1.004";
+
+use strict;
+use Generate;
+use Products;
+use base 'BSE::Generate::Article';
+use BSE::Template;
+use Constants qw($CGI_URI $ADMIN_URI);
+use BSE::Regen qw(generate_button);
+use OtherParents;
+use DevHelp::HTML;
+use BSE::Arrows;
+use BSE::Util::Iterate;
+use BSE::CfgInfo qw(cfg_dist_image_uri);
+
+sub _default_admin {
+  my ($self, $article, $embedded) = @_;
+
+  my $req = $self->{request};
+  my $html = <<HTML;
+<table>
+<tr>
+<td><form action="$CGI_URI/admin/add.pl">
+<input type=submit value="Edit Catalog">
+<input type=hidden name=id value="$article->{id}">
+</form></td>
+<td><form action="$ADMIN_URI">
+<input type=submit value="Admin menu">
+</form></td>
+HTML
+  if ($req->user_can('edit_add_child', $article)) {
+    $html .= <<HTML;
+<td><form action="$CGI_URI/admin/add.pl">
+<input type=hidden name="parentid" value="$article->{id}">
+<input type=hidden name="type" value="Product">
+<input type=submit value="Add product"></form></td>
+<td><form action="$CGI_URI/admin/add.pl">
+<input type=hidden name="parentid" value="$article->{id}">
+<input type=hidden name="type" value="Catalog">
+<input type=submit value="Add Sub-catalog"></form></td>
+HTML
+  }
+  $html .= <<HTML;
+<td><form action="$CGI_URI/admin/shopadmin.pl">
+<input type=hidden name="product_list" value=1>
+<input type=submit value="Full product list"></form></td>
+HTML
+  if (generate_button()
+      && $req->user_can(regen_article=>$article)) {
+    $html .= <<HTML;
+<td><form action="$CGI_URI/admin/generate.pl">
+<input type=hidden name=id value="$article->{id}">
+<input type=submit value="Regenerate">
+</form></td>
+HTML
+  }
+  $html .= <<HTML;
+<td><form action="$CGI_URI/admin/admin.pl" target="_blank">
+<input type=submit value="Display">
+<input type=hidden name=id value="$article->{id}">
+<input type=hidden name=admin value="0"></form></td>
+</tr></table>
+HTML
+  return $html;
+}
+
+sub tag_moveallcat {
+  my ($self, $allcats, $rindex, $article, $arg, $acts, $funcname, $templater) = @_;
+
+  return '' unless $self->{admin};
+  return '' unless $self->{request};
+  return '' 
+    unless $self->{request}->user_can(edit_reorder_children => $article);
+  return '' unless @$allcats > 1;
+
+  my ($img_prefix, $urladd) = 
+    DevHelp::Tags->get_parms($arg, $acts, $templater);
+  $img_prefix = '' unless defined $img_prefix;
+  $urladd = '' unless defined $urladd;
+  
+  my $can_move_up = $$rindex > 0;
+  my $can_move_down = $$rindex < $#$allcats;
+  return '' unless $can_move_up || $can_move_down;
+  my $myid = $allcats->[$$rindex]{id};
+  my $top = $self->{top} || $article;
+  my $refreshto = "$CGI_URI/admin/admin.pl?id=$top->{id}$urladd";
+  my $down_url = "";
+  if ($can_move_down) {
+    my $nextid = $allcats->[$$rindex+1]{id};
+    $down_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$nextid";
+  }
+  my $up_url = "";
+  if ($can_move_up) {
+    my $previd = $allcats->[$$rindex-1]{id};
+    $up_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$previd";
+  }
+  return make_arrows($self->{cfg}, $down_url, $up_url, $refreshto, $img_prefix);
+}
+
+sub tag_ifAnyProductOptions {
+  my ($self, $lookup, $arg) = @_;
+
+  $arg ||= "product";
+
+  my $entry = $lookup->{$arg}
+    or die "** No such product $arg **";
+  my ($rindex, $rdata) = @$entry;
+  $$rindex >= 0 && $$rindex < @$rdata
+    or die "** not in an iterator for $arg **";
+  my @options = $rdata->[$$rindex]->option_descs($self->{cfg});
+
+  return scalar(@options);
+}
+
+sub baseActs {
+  my ($self, $articles, $acts, $article, $embedded) = @_;
+
+  my $products = Products->new;
+  my @products = sort { $b->{displayOrder} <=> $a->{displayOrder} }
+    grep $_->{listed} && $_->{parentid} == $article->{id}, $products->all;
+  my $product_index = -1;
+  my @subcats = sort { $b->{displayOrder} <=> $a->{displayOrder} }
+    grep $_->{listed} && UNIVERSAL::isa($_->{generator}, 'BSE::Generate::Catalog'),
+    $articles->getBy(parentid => $article->{id});
+  my $other_parents = OtherParents->new;
+  my ($year, $month, $day) = (localtime)[5,4,3];
+  my $today = sprintf("%04d-%02d-%02d 00:00:00ZZZ", $year+1900, $month+1, $day);
+  my @stepprods = $article->visible_stepkids;
+  my $stepprod_index;
+  my @allkids = $article->all_visible_kids;
+  # make sure we have all of the inheritance info
+  my %generate = map { $_->{generator} => 1 } @allkids;
+  for my $gen (keys %generate) {
+    (my $file = $gen . ".pm") =~ s!::!/!g;
+    require $file;
+  }
+  my @allprods = grep UNIVERSAL::isa($_->{generator}, 'BSE::Generate::Product'), 
+    @allkids;
+  for (@allprods) {
+    unless ($_->isa('Product')) {
+      $_ = Products->getByPkey($_->{id});
+    }
+  }
+  my @allcats = grep UNIVERSAL::isa($_->{generator}, 'BSE::Generate::Catalog'), 
+    @allkids;
+
+  # for article ifUnderThreshold handler
+  $self->{kids}{$article->{id}}{allprods} = \@allprods;
+  $self->{kids}{$article->{id}}{allcats} = \@allcats;
+
+  my $allprod_index;
+  my $catalog_index = -1;
+  my $allcat_index;
+  my %named_product_iterators =
+    (
+     product => [ \$product_index, \@products ],
+     allprod => [ \$allprod_index, \@allprods ],
+    );
+  my $it = BSE::Util::Iterate->new;
+  my $cfg = $self->{cfg};
+  my $art_it = BSE::Util::Iterate::Article->new(cfg => $cfg);
+  my $image_uri = cfg_dist_image_uri();
+  my %work =
+    (
+     $self->SUPER::baseActs($articles, $acts, $article, $embedded),
+     #article => sub { escape_html($article->{$_[0]}) },
+     $art_it->make_iterator(undef, 'product', 'products', \@products, 
+                       \$product_index),
+     admin => [ tag_admin => $self, $article, 'catalog', $embedded ],
+     # for rearranging order in admin mode
+     moveDown=>
+     sub {
+       if ($self->{admin} && $product_index < $#products) {
+        my $html = <<HTML;
+ <a href="$CGI_URI/admin/move.pl?id=$products[$product_index]{id}&amp;d=down"><img src="$image_uri/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom" /></a>
+HTML
+        chop $html;
+        return $html;
+       }
+       else {
+        return '';
+       }
+     },
+     moveUp=>
+     sub {
+       if ($self->{admin} && $product_index > 0) {
+        my $html = <<HTML;
+ <a href="$CGI_URI/admin/move.pl?id=$products[$product_index]{id}&amp;d=up"><img src="$image_uri/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom" /></a>
+HTML
+        chop $html;
+        return $html;
+       }
+       else {
+        return '';
+       }
+     },
+     $art_it->make_iterator(undef, 'allprod', 'allprods', \@allprods, 
+                       \$allprod_index),
+     moveallprod =>
+     sub {
+       my ($arg, $acts, $funcname, $templater) = @_;
+
+       return '' unless $self->{admin};
+       return '' unless $self->{request};
+       return '' 
+        unless $self->{request}->user_can(edit_reorder_children => $article);
+       return '' unless @allprods > 1;
+
+       my ($img_prefix, $urladd) = 
+        DevHelp::Tags->get_parms($arg, $acts, $templater);
+       $img_prefix = '' unless defined $img_prefix;
+       $urladd = '' unless defined $urladd;
+
+       my $can_move_up = $allprod_index > 0;
+       my $can_move_down = $allprod_index < $#allprods;
+       return '' unless $can_move_up || $can_move_down;
+       my $blank = qq(<img src="$image_uri/trans_pixel.gif" width="17" height="13" border="0" align="absbotton" alt="" />);
+       my $myid = $allprods[$allprod_index]{id};
+       my $top = $self->{top} || $article;
+       my $refreshto = "$CGI_URI/admin/admin.pl?id=$top->{id}$urladd";
+       my $down_url = "";
+       if ($can_move_down) {
+        my $nextid = $allprods[$allprod_index+1]{id};
+        $down_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$nextid";
+       }
+       my $up_url = "";
+       if ($can_move_up) {
+        my $previd = $allprods[$allprod_index-1]{id};
+        $up_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$previd";
+       }
+       
+       return make_arrows($self->{cfg}, $down_url, $up_url, $refreshto, $img_prefix);
+     },
+     ifAnyProds => scalar(@allprods),
+     $art_it->make_iterator(undef, 'stepprod', 'stepprods', \@stepprods,
+                       \$stepprod_index),
+     ifStepProds => sub { @stepprods },
+     $art_it->make_iterator(undef, 'catalog', 'catalogs', \@subcats, 
+                       \$catalog_index),
+     ifSubcats => sub { @subcats },
+     $art_it->make_iterator(undef, 'allcat', 'allcats', \@allcats, \$allcat_index),
+     moveallcat => 
+     [ \&tag_moveallcat, $self, \@allcats, \$allcat_index, $article ],
+     ifAnyProductOptions =>
+     [ tag_ifAnyProductOptions => $self, \%named_product_iterators ],
+    );
+  my $oldurl = $work{url};
+  my $urlbase = $self->{cfg}->entryVar('site', 'url');
+  $work{url} =
+    sub {
+      my $value = $oldurl->(@_);
+      return $value if $value =~ /^<:/; # handle "can't do it"
+      unless ($value =~ /^\w+:/) {
+        # put in the base site url
+        $value = $urlbase . $value;
+      }
+      return $value;
+    };
+
+  return %work;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+  BSE::Generate::Catalog - page generator class for catalog pages
+
+=head1 DESCRIPTION
+
+  This class is used to generate catalog pages for BSE.  It derives
+  from L<BSE::Generate::Article>, and inherits it's tags.
+
+=head1 TAGS
+
+=over 4
+
+=item iterator ... products
+
+Iterates over the products within this catalog.
+
+=item product I<field>
+
+The given attribute of the product.
+
+=item ifProducts
+
+Conditional tag, true if there are any normal child products.
+
+=item iterator ... allprods
+
+Iterates over the products and step products of this catalog, setting
+the allprod tag for each item.
+
+=item allprod I<field>
+
+The given attribute of the product.
+
+=item ifAnyProds
+
+Conditional tag, true if there are any normal or step products.
+
+=item iterator ... stepprods
+
+Iterates over any step products of this catalog, setting the
+I<stepprod> tag to the current step product.  Does not iterate over
+normal child products.
+
+=item stepprod I<field>
+
+The given attribute of the current step product.
+
+=item ifStepProds
+
+Conditional tag, true if there are any step products.
+
+=item iterator ... catalogs
+
+Iterates over any sub-catalogs.
+
+=item catalog I<field>
+
+The given field of the current catalog.
+
+=item ifSubcats
+
+Conditional tag, true if there are any subcatalogs.
+
+=item admin
+
+Generates administrative tools (in admin mode).
+
+=back
+
+=head1 BUGS
+
+Still contains some code from before we derived from
+BSE::Generate::Article, so there is some obsolete code still present.
+
+=cut
index 6a2c4dd..b930a4a 100644 (file)
@@ -182,7 +182,7 @@ Returns catalogs that are a child of the specified article.
 sub children_of {
   my ($self, $parent) = @_;
 
-  return grep $_->{generator} eq 'Generate::Catalog',
+  return grep $_->{generator} eq 'BSE::Generate::Catalog',
     Articles->children($parent);
 }
 
index 6dec69b..aeb4f93 100644 (file)
@@ -242,7 +242,7 @@ sub _find_cat {
   @cats
     or return $parent;
   unless ($cache->{$parent}) {
-    my @kids = grep $_->{generator} eq 'Generate::Catalog', 
+    my @kids = grep $_->{generator} eq 'BSE::Generate::Catalog', 
       Articles->children($parent);
     $cache->{$parent} = \@kids;
   }
index 9cdbcd7..94d4f93 100644 (file)
@@ -54,7 +54,7 @@ sub visible_stepkids {
   use BSE::Util::SQL qw/now_sqldate/;
   my $today = now_sqldate();
 
-  if ($self->{generator} eq 'Generate::Catalog') {
+  if ($self->{generator} eq 'BSE::Generate::Catalog') {
     require 'Products.pm';
 
     return Products->getSpecial('visibleStep', $self->{id}, $today);
@@ -116,7 +116,7 @@ sub all_visible_product_tags {
 sub all_visible_catalogs {
   my ($self) = @_;
 
-  return grep $_->{generator} eq "Generate::Catalog", $self->all_visible_kids;
+  return grep $_->{generator} eq "BSE::Generate::Catalog", $self->all_visible_kids;
 }
 
 sub visible_kids {
index 0258c8a..b9e81ed 100644 (file)
@@ -101,7 +101,7 @@ sub embedded_catalog {
   my $list_index = -1;
   my $subcat_index = -1;
   my @subcats = sort { $b->{displayOrder} <=> $a->{displayOrder} } 
-    grep $_->{generator} eq 'Generate::Catalog', 
+    grep $_->{generator} eq 'BSE::Generate::Catalog', 
     Articles->children($catalog->{id});
 
   my $image_uri = cfg_dist_image_uri();
@@ -208,7 +208,7 @@ sub req_product_list {
   my $shopid = $req->cfg->entryErr('articles', 'shop');
   my $shop = Articles->getByPkey($shopid);
   my @catalogs = sort { $b->{displayOrder} <=> $a->{displayOrder} }
-    grep $_->{generator} eq 'Generate::Catalog', Articles->children($shopid);
+    grep $_->{generator} eq 'BSE::Generate::Catalog', Articles->children($shopid);
   my $catalog_index = -1;
   $message = $req->message($message);
   if (defined $cgi->param('showstepkids')) {
@@ -330,7 +330,7 @@ sub product_form {
 
     push(@catalogs, { id=>$parent, display=>$title }) if $title;
     my @kids = sort { $b->{displayOrder} <=> $a->{displayOrder} } 
-      grep $_->{generator} eq 'Generate::Catalog',
+      grep $_->{generator} eq 'BSE::Generate::Catalog',
       Articles->children($parent);
     $title .= ' / ' if $title;
     unshift(@work, map [ $_->{id}, $title.$_->{title} ], @kids);
diff --git a/site/cgi-bin/modules/Generate/Catalog.pm b/site/cgi-bin/modules/Generate/Catalog.pm
deleted file mode 100644 (file)
index 15ae4bd..0000000
+++ /dev/null
@@ -1,344 +0,0 @@
-package Generate::Catalog;
-
-our $VERSION = "1.004";
-
-use strict;
-use Generate;
-use Products;
-use base 'BSE::Generate::Article';
-use BSE::Template;
-use Constants qw($CGI_URI $ADMIN_URI);
-use BSE::Regen qw(generate_button);
-use OtherParents;
-use DevHelp::HTML;
-use BSE::Arrows;
-use BSE::Util::Iterate;
-use BSE::CfgInfo qw(cfg_dist_image_uri);
-
-sub _default_admin {
-  my ($self, $article, $embedded) = @_;
-
-  my $req = $self->{request};
-  my $html = <<HTML;
-<table>
-<tr>
-<td><form action="$CGI_URI/admin/add.pl">
-<input type=submit value="Edit Catalog">
-<input type=hidden name=id value="$article->{id}">
-</form></td>
-<td><form action="$ADMIN_URI">
-<input type=submit value="Admin menu">
-</form></td>
-HTML
-  if ($req->user_can('edit_add_child', $article)) {
-    $html .= <<HTML;
-<td><form action="$CGI_URI/admin/add.pl">
-<input type=hidden name="parentid" value="$article->{id}">
-<input type=hidden name="type" value="Product">
-<input type=submit value="Add product"></form></td>
-<td><form action="$CGI_URI/admin/add.pl">
-<input type=hidden name="parentid" value="$article->{id}">
-<input type=hidden name="type" value="Catalog">
-<input type=submit value="Add Sub-catalog"></form></td>
-HTML
-  }
-  $html .= <<HTML;
-<td><form action="$CGI_URI/admin/shopadmin.pl">
-<input type=hidden name="product_list" value=1>
-<input type=submit value="Full product list"></form></td>
-HTML
-  if (generate_button()
-      && $req->user_can(regen_article=>$article)) {
-    $html .= <<HTML;
-<td><form action="$CGI_URI/admin/generate.pl">
-<input type=hidden name=id value="$article->{id}">
-<input type=submit value="Regenerate">
-</form></td>
-HTML
-  }
-  $html .= <<HTML;
-<td><form action="$CGI_URI/admin/admin.pl" target="_blank">
-<input type=submit value="Display">
-<input type=hidden name=id value="$article->{id}">
-<input type=hidden name=admin value="0"></form></td>
-</tr></table>
-HTML
-  return $html;
-}
-
-sub tag_moveallcat {
-  my ($self, $allcats, $rindex, $article, $arg, $acts, $funcname, $templater) = @_;
-
-  return '' unless $self->{admin};
-  return '' unless $self->{request};
-  return '' 
-    unless $self->{request}->user_can(edit_reorder_children => $article);
-  return '' unless @$allcats > 1;
-
-  my ($img_prefix, $urladd) = 
-    DevHelp::Tags->get_parms($arg, $acts, $templater);
-  $img_prefix = '' unless defined $img_prefix;
-  $urladd = '' unless defined $urladd;
-  
-  my $can_move_up = $$rindex > 0;
-  my $can_move_down = $$rindex < $#$allcats;
-  return '' unless $can_move_up || $can_move_down;
-  my $myid = $allcats->[$$rindex]{id};
-  my $top = $self->{top} || $article;
-  my $refreshto = "$CGI_URI/admin/admin.pl?id=$top->{id}$urladd";
-  my $down_url = "";
-  if ($can_move_down) {
-    my $nextid = $allcats->[$$rindex+1]{id};
-    $down_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$nextid";
-  }
-  my $up_url = "";
-  if ($can_move_up) {
-    my $previd = $allcats->[$$rindex-1]{id};
-    $up_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$previd";
-  }
-  return make_arrows($self->{cfg}, $down_url, $up_url, $refreshto, $img_prefix);
-}
-
-sub tag_ifAnyProductOptions {
-  my ($self, $lookup, $arg) = @_;
-
-  $arg ||= "product";
-
-  my $entry = $lookup->{$arg}
-    or die "** No such product $arg **";
-  my ($rindex, $rdata) = @$entry;
-  $$rindex >= 0 && $$rindex < @$rdata
-    or die "** not in an iterator for $arg **";
-  my @options = $rdata->[$$rindex]->option_descs($self->{cfg});
-
-  return scalar(@options);
-}
-
-sub baseActs {
-  my ($self, $articles, $acts, $article, $embedded) = @_;
-
-  my $products = Products->new;
-  my @products = sort { $b->{displayOrder} <=> $a->{displayOrder} }
-    grep $_->{listed} && $_->{parentid} == $article->{id}, $products->all;
-  my $product_index = -1;
-  my @subcats = sort { $b->{displayOrder} <=> $a->{displayOrder} }
-    grep $_->{listed} && UNIVERSAL::isa($_->{generator}, 'Generate::Catalog'),
-    $articles->getBy(parentid => $article->{id});
-  my $other_parents = OtherParents->new;
-  my ($year, $month, $day) = (localtime)[5,4,3];
-  my $today = sprintf("%04d-%02d-%02d 00:00:00ZZZ", $year+1900, $month+1, $day);
-  my @stepprods = $article->visible_stepkids;
-  my $stepprod_index;
-  my @allkids = $article->all_visible_kids;
-  # make sure we have all of the inheritance info
-  my %generate = map { $_->{generator} => 1 } @allkids;
-  for my $gen (keys %generate) {
-    (my $file = $gen . ".pm") =~ s!::!/!g;
-    require $file;
-  }
-  my @allprods = grep UNIVERSAL::isa($_->{generator}, 'BSE::Generate::Product'), 
-    @allkids;
-  for (@allprods) {
-    unless ($_->isa('Product')) {
-      $_ = Products->getByPkey($_->{id});
-    }
-  }
-  my @allcats = grep UNIVERSAL::isa($_->{generator}, 'Generate::Catalog'), 
-    @allkids;
-
-  # for article ifUnderThreshold handler
-  $self->{kids}{$article->{id}}{allprods} = \@allprods;
-  $self->{kids}{$article->{id}}{allcats} = \@allcats;
-
-  my $allprod_index;
-  my $catalog_index = -1;
-  my $allcat_index;
-  my %named_product_iterators =
-    (
-     product => [ \$product_index, \@products ],
-     allprod => [ \$allprod_index, \@allprods ],
-    );
-  my $it = BSE::Util::Iterate->new;
-  my $cfg = $self->{cfg};
-  my $art_it = BSE::Util::Iterate::Article->new(cfg => $cfg);
-  my $image_uri = cfg_dist_image_uri();
-  my %work =
-    (
-     $self->SUPER::baseActs($articles, $acts, $article, $embedded),
-     #article => sub { escape_html($article->{$_[0]}) },
-     $art_it->make_iterator(undef, 'product', 'products', \@products, 
-                       \$product_index),
-     admin => [ tag_admin => $self, $article, 'catalog', $embedded ],
-     # for rearranging order in admin mode
-     moveDown=>
-     sub {
-       if ($self->{admin} && $product_index < $#products) {
-        my $html = <<HTML;
- <a href="$CGI_URI/admin/move.pl?id=$products[$product_index]{id}&amp;d=down"><img src="$image_uri/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom" /></a>
-HTML
-        chop $html;
-        return $html;
-       }
-       else {
-        return '';
-       }
-     },
-     moveUp=>
-     sub {
-       if ($self->{admin} && $product_index > 0) {
-        my $html = <<HTML;
- <a href="$CGI_URI/admin/move.pl?id=$products[$product_index]{id}&amp;d=up"><img src="$image_uri/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom" /></a>
-HTML
-        chop $html;
-        return $html;
-       }
-       else {
-        return '';
-       }
-     },
-     $art_it->make_iterator(undef, 'allprod', 'allprods', \@allprods, 
-                       \$allprod_index),
-     moveallprod =>
-     sub {
-       my ($arg, $acts, $funcname, $templater) = @_;
-
-       return '' unless $self->{admin};
-       return '' unless $self->{request};
-       return '' 
-        unless $self->{request}->user_can(edit_reorder_children => $article);
-       return '' unless @allprods > 1;
-
-       my ($img_prefix, $urladd) = 
-        DevHelp::Tags->get_parms($arg, $acts, $templater);
-       $img_prefix = '' unless defined $img_prefix;
-       $urladd = '' unless defined $urladd;
-
-       my $can_move_up = $allprod_index > 0;
-       my $can_move_down = $allprod_index < $#allprods;
-       return '' unless $can_move_up || $can_move_down;
-       my $blank = qq(<img src="$image_uri/trans_pixel.gif" width="17" height="13" border="0" align="absbotton" alt="" />);
-       my $myid = $allprods[$allprod_index]{id};
-       my $top = $self->{top} || $article;
-       my $refreshto = "$CGI_URI/admin/admin.pl?id=$top->{id}$urladd";
-       my $down_url = "";
-       if ($can_move_down) {
-        my $nextid = $allprods[$allprod_index+1]{id};
-        $down_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$nextid";
-       }
-       my $up_url = "";
-       if ($can_move_up) {
-        my $previd = $allprods[$allprod_index-1]{id};
-        $up_url = "$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$myid&other=$previd";
-       }
-       
-       return make_arrows($self->{cfg}, $down_url, $up_url, $refreshto, $img_prefix);
-     },
-     ifAnyProds => scalar(@allprods),
-     $art_it->make_iterator(undef, 'stepprod', 'stepprods', \@stepprods,
-                       \$stepprod_index),
-     ifStepProds => sub { @stepprods },
-     $art_it->make_iterator(undef, 'catalog', 'catalogs', \@subcats, 
-                       \$catalog_index),
-     ifSubcats => sub { @subcats },
-     $art_it->make_iterator(undef, 'allcat', 'allcats', \@allcats, \$allcat_index),
-     moveallcat => 
-     [ \&tag_moveallcat, $self, \@allcats, \$allcat_index, $article ],
-     ifAnyProductOptions =>
-     [ tag_ifAnyProductOptions => $self, \%named_product_iterators ],
-    );
-  my $oldurl = $work{url};
-  my $urlbase = $self->{cfg}->entryVar('site', 'url');
-  $work{url} =
-    sub {
-      my $value = $oldurl->(@_);
-      return $value if $value =~ /^<:/; # handle "can't do it"
-      unless ($value =~ /^\w+:/) {
-        # put in the base site url
-        $value = $urlbase . $value;
-      }
-      return $value;
-    };
-
-  return %work;
-}
-
-1;
-
-__END__
-
-=head1 NAME
-
-  Generate::Catalog - page generator class for catalog pages
-
-=head1 DESCRIPTION
-
-  This class is used to generate catalog pages for BSE.  It derives
-  from L<BSE::Generate::Article>, and inherits it's tags.
-
-=head1 TAGS
-
-=over 4
-
-=item iterator ... products
-
-Iterates over the products within this catalog.
-
-=item product I<field>
-
-The given attribute of the product.
-
-=item ifProducts
-
-Conditional tag, true if there are any normal child products.
-
-=item iterator ... allprods
-
-Iterates over the products and step products of this catalog, setting
-the allprod tag for each item.
-
-=item allprod I<field>
-
-The given attribute of the product.
-
-=item ifAnyProds
-
-Conditional tag, true if there are any normal or step products.
-
-=item iterator ... stepprods
-
-Iterates over any step products of this catalog, setting the
-I<stepprod> tag to the current step product.  Does not iterate over
-normal child products.
-
-=item stepprod I<field>
-
-The given attribute of the current step product.
-
-=item ifStepProds
-
-Conditional tag, true if there are any step products.
-
-=item iterator ... catalogs
-
-Iterates over any sub-catalogs.
-
-=item catalog I<field>
-
-The given field of the current catalog.
-
-=item ifSubcats
-
-Conditional tag, true if there are any subcatalogs.
-
-=item admin
-
-Generates administrative tools (in admin mode).
-
-=back
-
-=head1 BUGS
-
-Still contains some code from before we derived from
-BSE::Generate::Article, so there is some obsolete code still present.
-
-=cut
index c5a419c..b294b17 100644 (file)
@@ -5,7 +5,7 @@
 /BSE::Variables.html
 /Generate.html
 /BSE::Generate::Article.html
-/Generate::Catalog.html
+/BSE::Generate::Catalog.html
 /BSE::Generate::Product.html
 /Squirrel::Template.html
 /Squirrel::Template::Expr.html
index 15eef59..ffcada1 100644 (file)
@@ -15,7 +15,7 @@ my @targets =
    'bugs.html',
    'templates.html',
    'Generate.html',
-   'Generate::Catalog.html',
+   'BSE::Generate::Catalog.html',
    'BSE::Generate::Article.html',
    'BSE::Generate::Product.html',
    'Squirrel::Template.html',
index 2435c81..896ec1c 100644 (file)
@@ -154,7 +154,7 @@ my @prebuilt =
     admin=>$CGI_URI.'/admin/shopadmin.pl',
     threshold=>1000, # ignored
     summaryLength=>1000, #ignored
-    generator=>'Generate::Catalog',
+    generator=>'BSE::Generate::Catalog',
     thumbImage=>'',
     thumbWidth=>0,
     thumbHeight=>0,
index fe99692..6e68ade 100644 (file)
@@ -26,7 +26,7 @@ my $parent = bse_make_catalog
   );
 
 ok($parent, "made a catalog");
-is($parent->{generator}, "Generate::Catalog", "check generator");
+is($parent->{generator}, "BSE::Generate::Catalog", "check generator");
 
 my $parent2 = bse_make_catalog
   (
index 49d0a35..9d3d7eb 100644 (file)
@@ -49,7 +49,7 @@ my $parent = bse_make_catalog
   );
 
 ok($parent, "made a catalog");
-is($parent->{generator}, "Generate::Catalog", "check generator");
+is($parent->{generator}, "BSE::Generate::Catalog", "check generator");
 
 sleep 1;
 my $parent2 = bse_make_catalog