From 30a3b3523e1dfe527df68ba77fc7da78a34a3ac3 Mon Sep 17 00:00:00 2001 From: Hugh Davenport Date: Thu, 17 Jan 2013 16:11:30 +1300 Subject: [PATCH] bug 4437 Change XMLHttpRequest calls to jQuery.ajax The acq.js file used a few calls to XMLHttpRequest, which have been changed to use jQuery.ajax instead Signed-off-by: Hugh Davenport --- koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 150 +++++++++++------------------ 1 file changed, 58 insertions(+), 92 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index 0c3ce91..2d73023 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -721,33 +721,23 @@ function fetchSortDropbox(f) { for (i=1;i<=2;i++) { - var sort_zone = document.getElementById('sort'+i+'_zone'); + var $sort_zone = jQuery('#sort'+i+'_zone'); var url = '../acqui/fetch_sort_dropbox.pl?sort='+i+'&budget_id='+budgetId; - var xmlhttp = null; - xmlhttp = new XMLHttpRequest(); - if ( typeof xmlhttp.overrideMimeType != 'undefined') { - xmlhttp.overrideMimeType('text/xml'); - } - - xmlhttp.open('GET', url, false); - xmlhttp.send(null); - - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - // stupid JS... - } else { - // wait for the call to complete + jQuery.ajax({ + 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') { + // when sort is already an input, do not override to preseve value + return; + } + $sort_zone.html(xmlhttp.responseText); } - }; - // rc = eval ( xmlhttp.responseText ); - var retRootType = xmlhttp.responseXML.firstChild.nodeName; - var existingInputs = sort_zone.getElementsByTagName('input'); - if (existingInputs.length > 0 && retRootType == 'input') { - // when sort is already an input, do not override to preseve value - return; - } - sort_zone.innerHTML = xmlhttp.responseText; + }); } } @@ -760,29 +750,24 @@ for (i=1;i<=2;i++) { //USED BY NEWORDEREMPTY.PL function totalExceedsBudget(budgetId, total) { - var xmlhttp = null; - xmlhttp = new XMLHttpRequest(); - if ( typeof xmlhttp.overrideMimeType != 'undefined') { - xmlhttp.overrideMimeType('text/xml'); - } - var url = '../acqui/check_budget_total.pl?budget_id=' + budgetId + "&total=" + total; - xmlhttp.open('GET', url, false); - xmlhttp.send(null); - - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - + 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 ); if ( Math.abs(actTotal) < Math.abs(total) ) { // if budget is to low :( - return true ; + ret = true ; } else { - return false; + ret = false; } } - } + }); + return ret; } @@ -790,42 +775,31 @@ function totalExceedsBudget(budgetId, total) { function budgetExceedsParent(budgetTotal, budgetId, newBudgetParent, periodID) { - var xmlhttp = null; - xmlhttp = new XMLHttpRequest(); - if ( typeof xmlhttp.overrideMimeType != 'undefined') { - xmlhttp.overrideMimeType('text/xml'); - } - // make the call... yawn // var url = '../admin/check_parent_total.pl?budget_id=' + budgetId + '&parent_id=' + newBudgetParent + "&total=" + budgetTotal + "&period_id="+ periodID ; var url = '../admin/check_parent_total.pl?total=' + budgetTotal + "&period_id="+ periodID ; - if (budgetId ) { url += '&budget_id=' + budgetId }; if ( newBudgetParent ) { url += '&parent_id=' + newBudgetParent}; - - - xmlhttp.open('GET', url, false); - xmlhttp.send(null); - - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - // stupid JS... - } else { - // wait for the call to complete + 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 ); + + if (result == '1') { + ret = _("- Budget total exceeds parent allocation\n"); + } else if (result == '2') { + ret = _("- Budget total exceeds period allocation\n"); + } else { + ret = false; + } } - }; - - var result = eval ( xmlhttp.responseText ); - - if (result == '1') { - return _("- Budget total exceeds parent allocation\n"); - } else if (result == '2') { - return _("- Budget total exceeds period allocation\n"); - } else { - return false; - } + }); + return ret; } @@ -833,33 +807,25 @@ if ( newBudgetParent ) { url += '&parent_id=' + newBudgetParent}; //USED BY AQBUDGETS.TMPL function checkBudgetParent(budgetId, newBudgetParent) { - var xmlhttp = null; - xmlhttp = new XMLHttpRequest(); - if ( typeof xmlhttp.overrideMimeType != 'undefined') { - xmlhttp.overrideMimeType('text/xml'); - } - var url = '../admin/check_budget_parent.pl?budget_id=' + budgetId + '&new_parent=' + newBudgetParent; - xmlhttp.open('GET', url, false); - xmlhttp.send(null); - - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - // do something with the results - } else { - // wait for the call to complete + 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 ); + + if (result == '1') { + return _("- New budget-parent is beneath budget\n"); +// } else if (result == '2') { +// return "- New budget-parent has insufficent funds\n"; +// } else { +// return false; + } } - }; - - var result = eval ( xmlhttp.responseText ); - - if (result == '1') { - return _("- New budget-parent is beneath budget\n"); -// } else if (result == '2') { -// return "- New budget-parent has insufficent funds\n"; -// } else { -// return false; - } + }); + return ret; } -- 1.7.10.4