use BSE::CfgInfo 'product_options';
use BSE::Util::Tags qw(tag_hash);
-our $VERSION = "1.006";
+our $VERSION = "1.007";
=head1 NAME
my $order = time;
my @values;
for my $value_key (sort grep /^value/, keys %option_fields) {
- print STDERR "fetching $value_key\n";
my ($value) = $cgi->param($value_key);
if (defined $value && $value =~ /\S/) {
my $entry = BSE::TB::ProductOptionValues->make
my %errors;
my $option = $self->_get_option($req, $article, \%errors);
keys %errors
- and return $self->_service_error($req, $article, $articles, undef, \%errors);
+ and return $self->_service_error($req, $article, $articles, undef, \%errors, 'FIELD', "req_edit_option");
$req->validate(fields => \%option_name,
errors => \%errors);
my @values = $option->values;
grep $_->{id} == $default_value, @values
or $errors{default_value} = "Unknown value selected as default";
}
+
+ $DB::single = 1;
+ my @new_values;
+ my $index = 1;
+ while ($index < 10 && defined $cgi->param("newvalue$index")) {
+ my $field = "newvalue$index";
+ my $value = $cgi->param($field);
+ $req->validate(fields => { $field => \%option_value },
+ errors => \%errors);
+ push @new_values, $value;
+
+ ++$index;
+ }
+
keys %errors
- and return $self->_service_error($req, $article, $articles, undef, \%errors);
+ and return $self->_service_error($req, $article, $articles, undef, \%errors, "FIELD", "req_edit_option");
my $name = $cgi->param("name");
defined $name
$value->save;
}
}
+ my $order = @values ? $values[-1]->display_order : time;
+ for my $value (@new_values) {
+ BSE::TB::ProductOptionValues->make
+ (
+ product_option_id => $option->id,
+ value => $value,
+ display_order => ++$order,
+ );
+ }
$req->is_ajax
and return $req->json_content
values => [ map $_->data_only, @values ],
);
- return $self->refresh($article, $req->cgi, undef, "Option saved");
+ return $self->refresh($article, $req->cgi, undef,
+ "Option '" . $option->name . "' saved");
}
=item a_delconf_option
--- /dev/null
+document.observe("dom:loaded", function() {
+ var td = $("product_option_values");
+ var add_link = new Element("a", { href: "#" });
+ add_link.update("Add new value");
+ td.appendChild(add_link);
+ var index = parseInt($("newvaluecount").value);
+ add_link.observe("click", function(ev) {
+ ev.stop();
+
+ ++index;
+
+ var div = new Element("div");
+ var name = "newvalue" + index;
+ var label = new Element("label", { for: name });
+ label.update("Value:");
+ div.appendChild(label);
+ var input = new Element("input", { type: "text", name: name, id: name });
+ div.appendChild(input);
+ td.insertBefore(div, add_link);
+ $("newvaluecount").value = index;
+ });
+});
\ No newline at end of file
-<:wrap admin/base.tmpl title => "Edit Product Option", menuitem=>"none", showtitle=>"1" :>
+<:wrap admin/base.tmpl title => "Edit Product Option", menuitem=>"none", showtitle=>"1", js => "admin_editprodopt.js" :>
<:include admin/product_menu.tmpl:>
<form action="<:script:>" method="post">
<input type="hidden" name="id" value="<:article id:>" />
<input type="hidden" name="option_id" value="<:option id:>" />
<input type="hidden" name="_t" value="prodopts" />
+<input type="hidden" name="newvaluecount" id="newvaluecount" value="<:ifCgi newvaluecount:><:cgi newvaluecount:><:or:>0<:eif:>" />
<:csrfp admin_save_option hidden:>
<input type="hidden" name="save_enabled" value="1" />
<table class="editform editformsmall">
</tr>
<tr>
<th>Values:</th>
-<td>
+<td id="product_option_values">
<table class="editform">
<tr>
<td colspan="2"></td>
</tr>
<:iterator end dboptionvalues:>
</table>
+<:if Cgi newvaluecount:>
+<:iterator begin repeats [cgi newvaluecount]:>
+<div><label for="newvalue<:repeat value:>">Value:</label>
+<input type="text" name="newvalue<:repeat value:>" value="<:cgi [cat newvalue [repeat value]]:>" /><:error_img [cat newvalue [repeat value]]:></div>
+<:iterator end repeats:>
+<:or Cgi:><:eif Cgi:>
</td>
<td class="help"></td>
</tr>