From 517ae9be95ea98ee80bba96daff6bfa44968c6ec Mon Sep 17 00:00:00 2001 From: Hugh Davenport Date: Thu, 17 Jan 2013 18:18:15 +1300 Subject: [PATCH] bug 4439 Change some helper files to use C4::Service Depends on bug 4437 to avoid conflicts Depends on bug 9412 for a new feature used Also fixes bug 9411 Signed-off-by: Hugh Davenport --- acqui/check_budget_total.pl | 21 +++++---------------- admin/check_budget_parent.pl | 25 ++++++------------------- admin/check_parent_total.pl | 24 +++++++----------------- koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 10 +++------- 4 files changed, 21 insertions(+), 59 deletions(-) diff --git a/acqui/check_budget_total.pl b/acqui/check_budget_total.pl index 6ee346c..fab30da 100755 --- a/acqui/check_budget_total.pl +++ b/acqui/check_budget_total.pl @@ -19,11 +19,8 @@ use strict; #use warnings; FIXME - Bug 2505 -use CGI; -use C4::Context; -use C4::Output; -use C4::Auth; use C4::Budgets; +use C4::Service; =head1 DESCRIPTION @@ -31,20 +28,12 @@ fetches the budget amount fron the DB =cut -my $input = new CGI; -my $budget_id = $input->param('budget_id'); -my $total = $input->param('total'); - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => "acqui/ajax.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - debug => 1, } ); +my ($query, $response) = C4::Service->init(); +my ($budget_id, $total) = C4::Service->require_params( 'budget_id', 'total' ); my $budget = GetBudget($budget_id); -$template->param( return => $budget->{'budget_amount'} ); +$response->param( actTotal => $budget->{'budget_amount'} ); -output_html_with_http_headers $input, $cookie, $template->output; +C4::Service->return_success( $response ); 1; diff --git a/admin/check_budget_parent.pl b/admin/check_budget_parent.pl index 8f56e2c..ddb6e4a 100755 --- a/admin/check_budget_parent.pl +++ b/admin/check_budget_parent.pl @@ -19,11 +19,8 @@ use strict; #use warnings; FIXME - Bug 2505 -use CGI; -use C4::Context; -use C4::Output; -use C4::Auth; use C4::Budgets; +use C4::Service; =head1 DESCRIPTION @@ -32,24 +29,14 @@ called by aqbudgets.pl and neworderempty.pl =cut -my $input = new CGI; - -my $budget_id = $input->param('budget_id'); -my $new_parent_id = $input->param('new_parent'); - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => "acqui/ajax.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - debug => 0, - } -); +my ($query, $response) = C4::Service->init(); +my ($budget_id, $new_parent_id) = C4::Service->require_params( 'budget_id', 'new_parent' ); my $budget = GetBudget($budget_id); my $new_parent_budget = GetBudget($new_parent_id); my $result = CheckBudgetParent( $new_parent_budget, $budget ); -$template->param( return => $result ); -output_html_with_http_headers $input, $cookie, $template->output; +$response->param( result => $result ); + +C4::Service->return_success( $response ); 1; diff --git a/admin/check_parent_total.pl b/admin/check_parent_total.pl index f0f8c9b..b8110d2 100755 --- a/admin/check_parent_total.pl +++ b/admin/check_parent_total.pl @@ -19,11 +19,9 @@ use strict; #use warnings; FIXME - Bug 2505 -use CGI; use C4::Context; -use C4::Output; -use C4::Auth; use C4::Budgets; +use C4::Service; =head1 DESCRIPTION @@ -35,22 +33,12 @@ to determine whether the new parent budget (or period) has enough unallocated fu =cut my $dbh = C4::Context->dbh; -my $input = new CGI; +my ($query, $response) = C4::Service->init(); +my ($total, $period_id) = C4::Service->require_params( 'total', 'period_id' ); +my ($budget_id, $parent_id) = C4::Service->optional_params( 'budget_id', 'parent_id' ); -my $total = $input->param('total'); -my $budget_id = $input->param('budget_id'); -my $parent_id = $input->param('parent_id'); -my $period_id = $input->param('period_id'); my $returncode; -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => "acqui/ajax.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - debug => 0, - } -); my ($period, $parent , $budget); $period = GetBudgetPeriod($period_id) if $period_id; $parent = GetBudget($parent_id) if defined $parent_id; @@ -108,5 +96,7 @@ if ( $parent_id) { } -output_html_with_http_headers $input, $cookie, $returncode; +$response->param( returncode => $returncode ); + +C4::Service->return_success( $response ); 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index 42684df..2def2a7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -728,7 +728,6 @@ for (i=1;i<=2;i++) { url: url, mimeType: 'text/xml', success: function (data, textStatus, xmlhttp) { - // rc = eval ( xmlhttp.responseText ); var retRootType = jQuery(xmlhttp.responseXML).children().first().get(0).nodeName.toLowerCase(); var hasInputs = $sort_zone.has('input').length > 0; if (hasInputs && retRootType == 'input') { @@ -754,10 +753,9 @@ function totalExceedsBudget(budgetId, total) { var ret = undefined; jQuery.ajax({ url: url, - mimeType: 'text/xml', async: false, // non-async because we need to return a value based on the result success: function(data, textStatus, xmlhttp) { - actTotal = eval ( xmlhttp.responseText ); + actTotal = data.actTotal; if ( Math.abs(actTotal) < Math.abs(total) ) { // if budget is to low :( @@ -785,10 +783,9 @@ if ( newBudgetParent ) { url += '&parent_id=' + newBudgetParent}; var ret = undefined; jQuery.ajax({ url: url, - mimeType: 'text/xml', async: false, // non-async because we need to return a value based on the result success: function(data, textStatus, xmlhttp) { - var result = eval ( xmlhttp.responseText ); + var result = data.returncode; if (result == '1') { ret = _("- Budget total exceeds parent allocation\n"); @@ -811,10 +808,9 @@ function checkBudgetParent(budgetId, newBudgetParent) { var ret = undefined; jQuery.ajax({ url: url, - mimeType: 'text/xml', async: false, // non-async because we need to return a value based on the result success: function(data, textStatus, xmlhttp) { - var result = eval ( xmlhttp.responseText ); + var result = data.result; if (result == '1') { ret = _("- New budget-parent is beneath budget\n"); -- 1.7.10.4