Bugzilla – Attachment 14649 Details for
Bug 4437
acq.js uses XMLHttpRequest() directly; should use jQuery
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
bug 4437 Change XMLHttpRequest calls to jQuery.ajax
bug-4437-Change-XMLHttpRequest-calls-to-jQueryajax.patch (text/plain), 7.13 KB, created by
Hugh Davenport
on 2013-01-17 04:43:22 UTC
(
hide
)
Description:
bug 4437 Change XMLHttpRequest calls to jQuery.ajax
Filename:
MIME Type:
Creator:
Hugh Davenport
Created:
2013-01-17 04:43:22 UTC
Size:
7.13 KB
patch
obsolete
>From eb59cb0f5868574f6499fe274a8daba1c4fb7d9d Mon Sep 17 00:00:00 2001 >From: Hugh Davenport <hugh@davenport.net.nz> >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 <hugh@davenport.net.nz> >--- > 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..42684df 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') { >+ ret = _("- New budget-parent is beneath budget\n"); >+// } else if (result == '2') { >+// ret = "- New budget-parent has insufficent funds\n"; >+// } else { >+// ret = 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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 4437
:
14646
|
14649
|
63756
|
152859