- api: Form Controls and Workflow Activities may now include web based helper
subroutines directly in their files. See WebGUI::Operation::FormHelpers::www_formHelper and WebGUI::Operation::Workflow::www_activityHelper for details.
This commit is contained in:
parent
ce12dca15d
commit
0d145e6d91
9 changed files with 692 additions and 108 deletions
|
|
@ -716,7 +716,7 @@ sub www_editCommerceSettings {
|
|||
$tabform->getTab('salesTax')->raw('<tr><td colspan="2">');
|
||||
$session->style->setScript($session->url->extras('/js/at/AjaxRequest.js'), {type=>"text/javascript"});
|
||||
$session->style->setScript($session->url->extras('/operations/salesTaxAjax.js'), {type=>"text/javascript"});
|
||||
my $stateForm = WebGUI::Operation::FormHelpers::www_salesTaxTable($session);
|
||||
my $stateForm = www_salesTaxTable($session);
|
||||
$tabform->getTab('salesTax')->raw('<div id="salesTaxFormDiv">'.$stateForm.'</div>');
|
||||
$tabform->getTab('salesTax')->raw('</td></tr>');
|
||||
# Check which payment plugins will compile, and load them.
|
||||
|
|
@ -995,6 +995,111 @@ sub www_listTransactions {
|
|||
return _submenu($session,$output, 'list transactions')
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_salesTaxTable ( $session )
|
||||
|
||||
Create the AJAX form for displaying, adding and deleting sales tax information.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_salesTaxTable {
|
||||
my $session = shift;
|
||||
|
||||
my $returnTableOnly = 0;
|
||||
|
||||
if ($session->form->process('addDelete') eq 'add') {
|
||||
my $state = $session->form->process('addStateId', 'selectBox');
|
||||
my $taxRate = $session->form->process('taxRate', 'float');
|
||||
my $commerceSalesTaxId = $session->id->generate();
|
||||
if ( $state and $taxRate ) {
|
||||
$session->db->write('insert into commerceSalesTax (commerceSalesTaxId,regionIdentifier,salesTax) VALUES (?,?,?)', [$commerceSalesTaxId, $state, $taxRate]);
|
||||
}
|
||||
$returnTableOnly = 1;
|
||||
}
|
||||
elsif ($session->form->process('addDelete') eq 'delete') {
|
||||
my $commerceSalesTaxId = $session->form->process('entryId');
|
||||
$session->db->write('delete from commerceSalesTax where commerceSalesTaxId=?',[$commerceSalesTaxId]);
|
||||
$returnTableOnly = 1;
|
||||
}
|
||||
|
||||
my $existingData = $session->db->buildArrayRefOfHashRefs('select * from commerceSalesTax order by regionIdentifier');
|
||||
|
||||
##To build the form, we need two pieces
|
||||
|
||||
##1: The table contains all information from the database
|
||||
my @existingStates = map { $_->{regionIdentifier} } @{ $existingData };
|
||||
my %existingStates = map { $_ => 1 } @existingStates;
|
||||
|
||||
##2: The list contains all states except for those in the table;
|
||||
my $stateObj = Locale::US->new();
|
||||
my @stateNames = $stateObj->all_state_names;
|
||||
my @newStates = sort grep {! exists $existingStates{$_} } @stateNames;
|
||||
|
||||
my %orderedStates;
|
||||
tie %orderedStates, 'Tie::IxHash';
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
%orderedStates = map { $_ => $_ } 'Select State', @newStates;
|
||||
$orderedStates{'Select State'} = $i18n->get('Select State');
|
||||
|
||||
my $statesField = WebGUI::Form::selectBox($session,
|
||||
-name => 'stateChooser',
|
||||
-options => \%orderedStates,
|
||||
-default => 'Select State',
|
||||
);
|
||||
|
||||
my $taxField = WebGUI::Form::float($session,
|
||||
-name => 'taxRate',
|
||||
-value => '',
|
||||
-size => 6,
|
||||
);
|
||||
my $addButton = WebGUI::Form::button($session,
|
||||
-name=>"addTaxInfo",
|
||||
-value=>"Add Tax Information",
|
||||
-extras=>q!align="right" onclick="addState()"!,
|
||||
);
|
||||
|
||||
##build the table to display all existing sales tax
|
||||
|
||||
my $tableRows = '';
|
||||
my $deleteIcon = $session->config->get('extrasURL').'/toolbar/bullet/delete.gif';
|
||||
foreach my $sRow ( @{$existingData} ) {
|
||||
$tableRows .= sprintf <<EOTR, $deleteIcon, $sRow->{commerceSalesTaxId}, $sRow->{regionIdentifier}, $sRow->{salesTax};
|
||||
<tr>
|
||||
<td class="cell"><img style="cursor:pointer;" src="%s" onclick="deleteState(event,'%s')"></td>
|
||||
<td class="cell"><span>%s</span></td>
|
||||
<td class="cell"><span>%6.4f%%</span></td>
|
||||
</tr>
|
||||
EOTR
|
||||
}
|
||||
my $stateForm = sprintf <<EOSF, $taxField, $statesField, $addButton;
|
||||
<table id="salesTaxEntryTable">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="cell">%s %% tax for</td>
|
||||
<td class="cell">%s</td>
|
||||
<td class="cell">%s</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
EOSF
|
||||
|
||||
my $stateTable = sprintf <<EOST, $tableRows;
|
||||
<table id="salesTaxDataTable" border="1" cellpadding="3">
|
||||
<tbody>
|
||||
%s
|
||||
</tbody>
|
||||
</table>
|
||||
EOST
|
||||
$stateTable = '' unless $tableRows;
|
||||
return $stateForm.$stateTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_selectPaymentGateway ( $session )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue