]> git.imager.perl.org - bse.git/commitdiff
allow metadata to be defined for new products
authorTony Cook <tony@develop-help.com>
Fri, 27 Mar 2015 04:49:42 +0000 (15:49 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 9 May 2015 04:09:30 +0000 (14:09 +1000)
MANIFEST
site/cgi-bin/modules/BSE/DummyProduct.pm [new file with mode: 0644]
site/cgi-bin/modules/BSE/Edit/Article.pm
site/cgi-bin/modules/BSE/Edit/Product.pm
site/cgi-bin/modules/BSE/Request/Base.pm
site/templates/admin/edit_1.tmpl
site/templates/admin/edit_product.tmpl
site/templates/admin/include/edit_metadata.tmpl [new file with mode: 0644]

index 91193934575ba6e71cb248f47656d9ea96842a4f..8e9c9fab0e22fa7dbfc245d626e5c95dc22ce745 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -83,6 +83,7 @@ site/cgi-bin/modules/BSE/CustomBase.pm
 site/cgi-bin/modules/BSE/DB.pm
 site/cgi-bin/modules/BSE/DB/Mysql.pm
 site/cgi-bin/modules/BSE/DummyArticle.pm
 site/cgi-bin/modules/BSE/DB.pm
 site/cgi-bin/modules/BSE/DB/Mysql.pm
 site/cgi-bin/modules/BSE/DummyArticle.pm
+site/cgi-bin/modules/BSE/DummyProduct.pm
 site/cgi-bin/modules/BSE/Dynamic/Article.pm
 site/cgi-bin/modules/BSE/Dynamic/Catalog.pm
 site/cgi-bin/modules/BSE/Dynamic/Product.pm
 site/cgi-bin/modules/BSE/Dynamic/Article.pm
 site/cgi-bin/modules/BSE/Dynamic/Catalog.pm
 site/cgi-bin/modules/BSE/Dynamic/Product.pm
@@ -606,6 +607,7 @@ site/templates/admin/include/article_menu.tmpl
 site/templates/admin/include/auditentry.tmpl
 site/templates/admin/include/audithead.tmpl
 site/templates/admin/include/edit_common.tmpl
 site/templates/admin/include/auditentry.tmpl
 site/templates/admin/include/audithead.tmpl
 site/templates/admin/include/edit_common.tmpl
+site/templates/admin/include/edit_metadata.tmpl
 site/templates/admin/include/message.tmpl
 site/templates/admin/include/oauditlog.tmpl
 site/templates/admin/include/order_list_filter.tmpl
 site/templates/admin/include/message.tmpl
 site/templates/admin/include/oauditlog.tmpl
 site/templates/admin/include/order_list_filter.tmpl
diff --git a/site/cgi-bin/modules/BSE/DummyProduct.pm b/site/cgi-bin/modules/BSE/DummyProduct.pm
new file mode 100644 (file)
index 0000000..3b174ce
--- /dev/null
@@ -0,0 +1,21 @@
+package BSE::DummyProduct;
+use strict;
+use BSE::DummyArticle;
+our @ISA = qw(BSE::DummyArticle);
+use BSE::TB::Products;
+
+our $VERSION = "1.000";
+
+{
+  my %fields;
+  @fields{BSE::TB::Product->columns} = ();
+  delete @fields{BSE::TB::Article->columns};
+  for my $name (keys %fields) {
+    eval "sub $name { \$_[0]{$name} }";
+  }
+}
+
+
+sub prices {}
+
+1;
index 3fcc4ab50950f77d837a2f2b01a8ca77a7b79389..754412da4359cbd18dae798ae84720043c97047f 100644 (file)
@@ -16,7 +16,7 @@ use List::Util qw(first);
 use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
 use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
 
 use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
 use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
 
-our $VERSION = "1.053";
+our $VERSION = "1.054";
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -1293,6 +1293,8 @@ sub low_edit_tags {
   # only return the fields that are defined
   $request->set_variable(custom => $custom);
   $request->set_variable(errors => $errors || {});
   # only return the fields that are defined
   $request->set_variable(custom => $custom);
   $request->set_variable(errors => $errors || {});
+  my $article_type = $cfg->entry('level names', $article->{level}, 'Article');
+  $request->set_variable(article_type => $article_type);
 
   return
     (
 
   return
     (
@@ -1300,7 +1302,7 @@ sub low_edit_tags {
      article => sub { tag_article($article, $cfg, $_[0]) },
      old => [ \&tag_old, $article, $cgi ],
      default => [ \&tag_default, $self, $request, $article ],
      article => sub { tag_article($article, $cfg, $_[0]) },
      old => [ \&tag_old, $article, $cgi ],
      default => [ \&tag_default, $self, $request, $article ],
-     articleType => [ \&tag_art_type, $article->{level}, $cfg ],
+     articleType => escape_html($article_type),
      parentType => [ \&tag_art_type, $article->{level}-1, $cfg ],
      ifNew => [ \&tag_if_new, $article ],
      list => [ \&tag_list, $self, $article, $articles, $cgi, $request ],
      parentType => [ \&tag_art_type, $article->{level}-1, $cfg ],
      ifNew => [ \&tag_if_new, $article ],
      list => [ \&tag_list, $self, $article, $articles, $cgi, $request ],
@@ -1557,8 +1559,14 @@ sub _dummy_article {
     return;
   }
 
     return;
   }
 
+  return $self->_make_dummy_article(\%article);
+}
+
+sub _make_dummy_article {
+  my ($self, $article) = @_;
+
   require BSE::DummyArticle;
   require BSE::DummyArticle;
-  return bless \%article, "BSE::DummyArticle";
+  return bless $article, "BSE::DummyArticle";
 }
 
 sub add_form {
 }
 
 sub add_form {
index 2deead0f167d1b2bb73f762c7bc7f2c17bc28bd0..80978069e7abff4e374f8cb8d4dfc194a66a9937 100644 (file)
@@ -10,7 +10,7 @@ use BSE::CfgInfo 'product_options';
 use BSE::Util::Tags qw(tag_hash tag_article);
 use constant PRODUCT_CUSTOM_FIELDS_CFG => "product custom fields";
 
 use BSE::Util::Tags qw(tag_hash tag_article);
 use constant PRODUCT_CUSTOM_FIELDS_CFG => "product custom fields";
 
-our $VERSION = "1.015";
+our $VERSION = "1.016";
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -35,6 +35,13 @@ my %money_fields =
 
 sub generator { 'BSE::Generate::Product' }
 
 
 sub generator { 'BSE::Generate::Product' }
 
+sub _make_dummy_article {
+  my ($self, $article) = @_;
+
+  require BSE::DummyProduct;
+  return bless $article, "BSE::DummyProduct";
+}
+
 sub base_template_dirs {
   return ( "products" );
 }
 sub base_template_dirs {
   return ( "products" );
 }
@@ -292,6 +299,7 @@ sub low_edit_tags {
   my @tiers;
   my $price_tier;
   my %prices;
   my @tiers;
   my $price_tier;
   my %prices;
+  $req->set_variable(product => $article);
   return 
     (
      product => [ \&tag_article, $article, $cfg ],
   return 
     (
      product => [ \&tag_article, $article, $cfg ],
index 131c56cb2591f7bad314c2a37397eaf8dbb3576e..1fafbbf30f92d34b9cc721999ee0e74fafb6f23a 100644 (file)
@@ -5,7 +5,7 @@ use BSE::Cfg;
 use BSE::Util::HTML;
 use Carp qw(cluck confess);
 
 use BSE::Util::HTML;
 use Carp qw(cluck confess);
 
-our $VERSION = "1.031";
+our $VERSION = "1.032";
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -1802,8 +1802,9 @@ sub cgi_fields {
       ($value) = $cgi->param($name);
       require DevHelp::Date;
       my $msg;
       ($value) = $cgi->param($name);
       require DevHelp::Date;
       my $msg;
-      my ($year, $month, $day) = DevHelp::Date::dh_parse_date($value, \$msg);
-      $value = sprintf("%04d-%02d-%02d", $year, $month, $day);
+      if (my ($year, $month, $day) = DevHelp::Date::dh_parse_date($value, \$msg)) {
+       $value = sprintf("%04d-%02d-%02d", $year, $month, $day);
+      }
     }
     elsif ($field->{type} && $field->{type} eq "time" && !$opts{api}) {
       ($value) = $cgi->param($name);
     }
     elsif ($field->{type} && $field->{type} eq "time" && !$opts{api}) {
       ($value) = $cgi->param($name);
index 1511eeec1ae5b01d68157f9a04332afc6276488c..cf45b51dd3e14a3f73b8d06cc7c778d26098e225 100644 (file)
@@ -1,3 +1,4 @@
+
 <:wrap admin/base.tmpl title=>[cond [ifNew] [cat "New " [articleType]] [cat "Edit " [articleType] ": " [article title]]], js => "admin_edit.js":>
 <h1><:ifNew:>New<:or:>Edit<:eif:> <:articleType:></h1>
 <:if Message:> 
 <:wrap admin/base.tmpl title=>[cond [ifNew] [cat "New " [articleType]] [cat "Edit " [articleType] ": " [article title]]], js => "admin_edit.js":>
 <h1><:ifNew:>New<:or:>Edit<:eif:> <:articleType:></h1>
 <:if Message:> 
           </tr>
           <:or Article:><:eif Article:> 
         </table>
           </tr>
           <:or Article:><:eif Article:> 
         </table>
-<:.set metas = [ article.metafields ] -:>
-<:  .if metas.size -:>
-<fieldset>
-  <legend>Article Metadata</legend>
-<input type="hidden" name="_save_meta" value="1">
-<:  .for m in metas -:>
-<:#= bse.dumper(m) |raw :>
-<:    .set name = "meta_" _ m.name -:>
-<:    .set mdata = article.meta_by_name(m.name) -:>
-<:    .if m.type eq 'image' -:>
-<:      .set def = article.meta_by_name(m.display_name) -:>
-<:      .set def = def ? def.value_text : "" -:>
-<:    .else -:>
-<:      .set def = mdata ? mdata.value_text : "" -:>
-<:    .end if -:>
-<:    .if m.ro -:>
-<:      .call "inlinefieldro", name: name, field: m.field,
-               options: { default: def } -:>
-<:    .else -:>
-<:      .call "inlinefield", name: name, field: m.field, 
-                options: { delete: 1, default: def } -:>
-<:    .end if :>
-<:  .end for -:>
-</fieldset>
-<:  .end if -:>
+<:.call "admin/include/edit_metadata.tmpl", tr: 0 :>
 
   <p><: ifNew :>
     <input type="submit" name="save" value="Add New <: articleType:>" />
 
   <p><: ifNew :>
     <input type="submit" name="save" value="Add New <: articleType:>" />
index 058933e898d051250f0dc6f5e9eec5dca91a0d86..5f05dad6674482fe2edf629c2a7f8c5d7dfba2d4 100644 (file)
@@ -1,7 +1,9 @@
+<:.set article_type = "Product" -:>
 <:wrap admin/base.tmpl title => [cond [ifNew] "Add Product" "Edit Product"], menuitem=>"edit", showtitle=>"1", js => "admin_edit.js" :>
 <:ifMessage:>
 <p><b><:message:></b></p>
 <:or:><:eif:> 
 <:wrap admin/base.tmpl title => [cond [ifNew] "Add Product" "Edit Product"], menuitem=>"edit", showtitle=>"1", js => "admin_edit.js" :>
 <:ifMessage:>
 <p><b><:message:></b></p>
 <:or:><:eif:> 
+<:.set oldf = @{name, def: cgi.param(name).defined ? cgi.param(name) : def} -:>
 <:include admin/product_menu.tmpl:>
 <:ifNew:><:or:><:if Or [iadminuser_count] [iadmingroup_count]:>
       <form action="/cgi-bin/admin/adminusers.pl">
 <:include admin/product_menu.tmpl:>
 <:ifNew:><:or:><:if Or [iadminuser_count] [iadmingroup_count]:>
       <form action="/cgi-bin/admin/adminusers.pl">
           <tr> 
             <th><:cfg "product fields" retailPrice "Retail price":>:</th>
             <td>$ 
           <tr> 
             <th><:cfg "product fields" retailPrice "Retail price":>:</th>
             <td>$ 
-              <:ifFieldPerm retailPrice:><input type="text" name="retailPrice" value="<:old retailPrice money default retailPrice:>" size="7" />
+              <:ifFieldPerm retailPrice:><input type="text" name="retailPrice" value="<:= oldf("retailPrice", bse.number("money", product.retailPrice)) :>" size="7" />
               (0.00)<:or:><:money product retailPrice:><:eif:> </td>
             <td class="help"><:help product retail:> <:error_img retailPrice:></td>
           </tr>
               (0.00)<:or:><:money product retailPrice:><:eif:> </td>
             <td class="help"><:help product retail:> <:error_img retailPrice:></td>
           </tr>
           </tr>
   <tr><td colspan="3">*These fields cannot be modified once this product has been
       included in an order.</td></tr>
           </tr>
   <tr><td colspan="3">*These fields cannot be modified once this product has been
       included in an order.</td></tr>
+<:.call "admin/include/edit_metadata.tmpl", tr: 1:>
   <:if UserCan edit_save:article:>
   <tr>
     <td colspan="3" class="buttons"><:ifNew:><input type="submit" name="save" value="Add Product" /><:or:><input type="submit" name="save" value="Update Product" /><:eif:>
   </td></tr><:or UserCan:><:eif UserCan:>
         </table>
 </form>
   <:if UserCan edit_save:article:>
   <tr>
     <td colspan="3" class="buttons"><:ifNew:><input type="submit" name="save" value="Add Product" /><:or:><input type="submit" name="save" value="Update Product" /><:eif:>
   </td></tr><:or UserCan:><:eif UserCan:>
         </table>
 </form>
+
diff --git a/site/templates/admin/include/edit_metadata.tmpl b/site/templates/admin/include/edit_metadata.tmpl
new file mode 100644 (file)
index 0000000..fb4d78f
--- /dev/null
@@ -0,0 +1,32 @@
+<:.set metas = [ article.metafields ] -:>
+<:  .if metas.size -:>
+<:.if tr:>
+<tr><td colspan="3">
+<:.end if :>
+<fieldset>
+  <legend><:= article_type |html :> Metadata</legend>
+<input type="hidden" name="_save_meta" value="1">
+<:  .for m in metas -:>
+<:#= bse.dumper(m) |raw :>
+<:    .set name = "meta_" _ m.name -:>
+<:    .set mdata = article.meta_by_name(m.name) -:>
+<:    .if m.type eq 'image' -:>
+<:      .set def = article.meta_by_name(m.display_name) -:>
+<:      .set def = def ? def.value_text : "" -:>
+<:    .else -:>
+<:      .set def = mdata ? mdata.value_text : "" -:>
+<:    .end if -:>
+<:    .if m.ro -:>
+<:      .call "inlinefieldro", name: name, field: m.field,
+               options: { default: def } -:>
+<:    .else -:>
+<:      .call "inlinefield", name: name, field: m.field, 
+                options: { delete: 1, default: def } -:>
+<:    .end if :>
+<:  .end for -:>
+</fieldset>
+<:.if tr:>
+</td></tr>
+<:.end if :>
+<:  .end if -:>
+