allow setting default for option on creation
authorTony Cook <tony@develop-help.com>
Thu, 16 Apr 2020 23:58:15 +0000 (09:58 +1000)
committerTony Cook <tony@develop-help.com>
Thu, 16 Apr 2020 23:58:15 +0000 (09:58 +1000)
site/cgi-bin/modules/BSE/Edit/Product.pm
site/htdocs/css/admin.css
site/templates/admin/edit_prodopts.tmpl

index 4a67f698f09cbeb81137e1a4c62f42d6b1feb12b..e947ddf47617b628db6a128052511cc07de0f924 100644 (file)
@@ -769,6 +769,7 @@ sub req_add_option {
 
   my $order = time;
   my @values;
+  my %value_keys;
   for my $value_key (sort grep /^value/, keys %option_fields) {
     my ($value) = $cgi->param($value_key);
     if (defined $value && $value =~ /\S/) {
@@ -779,9 +780,15 @@ sub req_add_option {
         display_order => $order,
        );
       push @values, $entry;
+      $value_keys{$value_key} = $entry;
       ++$order;
     }
   }
+  my $def = $cgi->param("default");
+  if ($def && $value_keys{$def}) {
+    $option->set_default_value($value_keys{$def}->id);
+    $option->save;
+  }
 
   $req->is_ajax
     and return $req->json_content
index c27ecd52ea735f989fb0bb7a98fa39c7c7ecd681..389f6930be1d71e7563464407688cce25e867a77 100644 (file)
@@ -62,8 +62,14 @@ input.inline { width: 90%; }
   padding-left: 2px;
 }
 
+.prodoptvalues {
+  display: table;
+  width: 100%;
+}
+
 .prodopt .valueentry {
   width: 100%;
+  display: table-row;
   /*padding: 4px 20px 4px 20px;*/
   padding: 4px 0px;
   background-color: #ccc;
@@ -71,7 +77,8 @@ input.inline { width: 90%; }
   clear: both;
 }
 
-#productoptions .valueentry span {
+.valueentry span {
+  display: table-cell;
   padding: 0 3px;
   margin: 0 20px;
 }
index f150284b430e6e2772ca18bb54e28f56551f737f..1534935bea21720cda1947dea1aa8b21f9a45eef 100644 (file)
 </div>
 <:.end if:>
 <:.if request.user_can("bse_edit_prodopt_add", article) :>
+<:.define addform_value_entry:>
+<div class="valueentry<:= index mod 2 == 0 ? "" : " odd":>"><span><input type="text" name="value<:= index :>" value="<:= cgi.param("value" _ index) :>" maxlength="255" class="editor_field" title="Enter some values here" /></span><span><input type="radio" name="default" value="value<:= index :>"></span><span><:.call "error_img", field: "value" _ index:></span></div>
+<:.end define:>
+<:.define addform_value_head:>
+<div class="valueentry"><span>Values</span><span>Default</span></div>
+<:.end define:>
+<:include admin/edit_prodopt_custom.tmpl optional:>
 <div id="addoptionform" class="prodopt">
 <form action="<:script:>" method="post">
 <:csrfp admin_add_option hidden:>
 <input type="hidden" name="id" value="<:= article.id:>" />
 <div class="prodoptmenu">Option: <input type="text" name="name" value="<:= cgi.param("name") :>" maxlength="255" class="editor_field" title="Enter the name of your new option here" /><:.call "error_img", field: "name":><input type="submit" name="a_add_option" value="Add New Option" class="editor_ok_button" /></div>
 <div class="prodoptvalues">
-<div class="valueentry"><input type="text" name="value1" value="<:= cgi.param("value1") :>" maxlength="255" class="editor_field" title="Enter some values here" /><:.call "error_img", field: "value1":></div>
-<div class="valueentry odd"><input type="text" name="value2" value="<:= cgi.param("value2") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value2":></div>
-<div class="valueentry"><input type="text" name="value3" value="<:= cgi.param("value3") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value3" :></div>
-<div class="valueentry odd"><input type="text" name="value4" value="<:= cgi.param("value4") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value4":></div>
-<div class="valueentry"><input type="text" name="value5" value="<:= cgi.param("value5") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value5":></div>
+<:.call "addform_value_head":>
+<:.for index in [ 1 .. 5 ] :>
+<:.call "addform_value_entry" :>
+<:.end for:>
 </div>
 </form>
 </div>