editSaveParameterOptions

This commit is contained in:
Colin Kuskie 2008-04-23 15:20:46 +00:00
parent f04e42ec55
commit 29fb2b1385

View file

@ -283,14 +283,14 @@ sub getFileUrl {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getParamData =head2 getParams
Return the parameter data from this product as a perl data structure, Return the parameter data from this product as a perl data structure,
rather than the internally stored JSON. rather than the internally stored JSON.
=cut =cut
sub getParamData { sub getParams {
my $self = shift; my $self = shift;
my $structure = JSON::from_json($self->get('parameters')); my $structure = JSON::from_json($self->get('parameters'));
return $structure; return $structure;
@ -904,11 +904,14 @@ sub www_editFeatureSave {
sub www_editParameter { sub www_editParameter {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
my $param = shift || $self->session->form->get('name') || 'new'; my $param = shift || $self->session->form->get('name') || 'new';
my $paramData = $self->getParamData; my $allParams = $self->getParams;
$param = "new" unless exists $paramData->{$param};
$param = "new" unless exists $allParams->{$param};
my $i18n = WebGUI::International->new($self->session,'Asset_Product'); my $i18n = WebGUI::International->new($self->session,'Asset_Product');
my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
$f->hidden( $f->hidden(
-name => "func", -name => "func",
-value => "editParameterSave", -value => "editParameterSave",
@ -933,48 +936,49 @@ sub www_editParameterSave {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
my $param = $self->session->form->get('name'); my $param = $self->session->form->get('name');
my $origname = $self->session->form->get('origname'); my $origname = $self->session->form->get('origname');
my $paramData = $self->getParamData; my $allParams = $self->getParams;
if (($origname ne "new") and ($origname ne $param)) { if (($origname ne "new") and ($origname ne $param)) {
##Rename existing param ##Rename existing param
my @options = @{ $paramData->{$origname} }; my @options = @{ $allParams->{$origname} };
$paramData->{$param} = \@options; $allParams->{$param} = \@options;
delete $paramData->{$origname}; delete $allParams->{$origname};
my $newSelf = $self->setParamData($paramData); my $newSelf = $self->setParamData($allParams);
return $newSelf->www_editParameter($param); return $newSelf->www_editParameter($param);
} }
elsif ($origname eq "new") { elsif ($origname eq "new") {
$paramData->{$param} = []; $allParams->{$param} = [];
my $newSelf = $self->setParamData($paramData); my $newSelf = $self->setParamData($allParams);
return $newSelf->www_editParameterOptions($param); return $newSelf->www_editParameterOptions($param);
} }
return $self->www_view();
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub www_editParameterOptions { sub www_editParameterOptions {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
my $session = $self->session; my $session = $self->session;
my $param = shift || $self->session->form->get('name'); my $param = shift || $session->form->get('name');
my $value = shift || $self->session->form->get('value') || "new"; my $value = shift || $session->form->get('value') || "new";
my $paramData = $self->getParamData; my $allParams = $self->getParams;
##You cannot add an option to a non-existant parameter. ##You cannot add an option to a non-existant parameter.
if (! exists $paramData->{$param}) { if (! exists $allParams->{$param}) {
$self->session->errorHandler->warn('Not in param data'); $session->errorHandler->warn("$param is not in param data");
return $self->www_editParameter($param); return $self->www_editParameter($param);
} }
##Convert to a byname interface ##Convert to a byname interface
my $option = {}; my $option = {};
OPTION: foreach my $subOption (@{ $paramData->{$param} }) { OPTION: foreach my $subOption (@{ $allParams->{$param} }) {
if ($subOption->{value} eq $value) { if ($subOption->{value} eq $value) {
$option = $subOption; $option = $subOption;
last OPTION; last OPTION;
} }
} }
my $i18n = WebGUI::International->new($self->session,'Asset_Product'); my $i18n = WebGUI::International->new($session,'Asset_Product');
my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); my $f = WebGUI::HTMLForm->new($session,-action=>$self->getUrl);
$f->hidden( $f->hidden(
-name => "func", -name => "func",
-value => "editParameterOptionSave", -value => "editParameterOptionSave",
@ -1020,16 +1024,43 @@ sub www_editParameterOptionsSave {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
my $param = $self->session->form->get('name'); my $form = $self->session->form;
my $value = $self->session->form->get('value'); my $param = $form->get('name');
my $origValue = $self->session->form->get('origValue'); my $value = $form->get('value');
my $origValue = $form->get('origValue');
my $paramData = $self->getParamData(); my $allParams = $self->getParams();
if (($origvalue ne "new") and ($origvalue new $value)) { if (! exists $allParams->{$param}) {
##Rename existing option $self->session->errorHandler->warn("$param is not an existing parameter");
return $self->www_editParameter($param);
} }
my $paramData = $allParams->{$param};
if (($origValue ne "new") and ($origValue ne $value)) {
##Rename existing option
my $option = {};
OPTION: foreach my $subOption (@{ $allParams->{$param} }) {
if ($subOption->{value} eq $value) {
$option = $subOption;
last OPTION;
}
}
##Warning for a non-existant option
if (! keys %{ $option } ) {
$self->session->errorHandler->warn("$value is not an existing option of $param");
return $self->www_editParameter($param, $value);
}
$option->{value} = $value;
$option->{priceModifer} = $form->get('priceModifier');
$option->{weightModifer} = $form->get('weightModifier');
}
elsif ($origValue eq "new") {
my $newOption = {};
$newOption->{value} = $value;
$newOption->{priceModifer} = $form->get('priceModifier');
$newOption->{weightModifer} = $form->get('weightModifier');
push @{ $paramData }, $newOption;
}
return $self->www_view();
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------