PDA

View Full Version : [1.1.1][WORKAROUND] aborting an updateManager load is not stopping with prototype



tirams
29 Nov 2007, 6:37 PM
I have an element that I got the updateManager for and called the update method on it. It loads the url and updates the content fine but if I want to abort the update it doesn't work. I called the elements updatemanager abort() method but it still continues to loading the url. Tracing thru firebug there is seems to be no transaction id, so the abort doesn't do anything. I'm using 1.1.1 with prototype adapter. Is there a workaround or am I using it incorrectly?

thanks for any help

tryanDLS
30 Nov 2007, 8:40 AM
It's possibly a bug with the prototype adapter. Can you replicate the same behavior with the base adapter?

tirams
30 Nov 2007, 1:33 PM
I tested with ext base vs prototype and it works with ext but not with prototype.

test code I used below, the abort is called but you can see the load still continues in firebug. I used a long running page on my server to try it.




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>test abort with prototype</title>
<link rel="stylesheet" href="/assets/styles/ext-all.css" type="text/css" media="all" />
<script type="text/javascript" src="/assets/javascripts/prototype.js" id="prototypejs"></script>
<script type="text/javascript" src="/assets/javascripts/ext-prototype-adapter.js" id="ext-prototype-adapterjs"></script>
<script type="text/javascript" src="/assets/javascripts/ext-all.js"></script>
<script type="text/javascript">

Ext.onReady(function(){
Ext.get('mb1').on('click', function(e){
test_refresh();
});

Ext.get('mb2').on('click', function(e){
clear_refresh();
});

Ext.get('mb3').on('click', function(e){
abort_refresh();
});
});


function clear_refresh(){
var div = Ext.get('mydiv');
if (div){
div.dom.innerHTML = "";
}
}


function abort_refresh(){
var div = Ext.get('mydiv');
if (div){
var mgr = div.getUpdateManager();
mgr.abort();
div.dom.innerHTML = "abort called";
}
}


function refreshed(){
Ext.Msg.alert('Status', 'Div was loaded');
}

function test_refresh(){
// reload the other arrays section
//assets/help/home.html

var bn = Ext.get('mydiv');
if (bn){
var mgr = bn.getUpdateManager();
mgr.showLoadIndicator = true;
mgr.abort();
mgr.update({
url: location.protocol + "//"+ location.host + "/arrays/28636079/view.tpl",
callback: refreshed,
scope: this,
discardUrl: true,
nocache: false,
timeout : 130,
scripts: true
});
}

}


</script>
</head>
<body>
<p>
<b>Load element</b><br />
<button id="mb1">update</button> <button id="mb3">abort</button>
</p>

<p>
<b>Clear element</b><br />
<button id="mb2">clear</button>
</p>

<div id=mydiv >
To be filled in,...
</div>
</body>
</html>

tryanDLS
30 Nov 2007, 2:35 PM
Moving this to bugs. Can you add some more details regarding platforms/browsers, etc per this. http://extjs.com/forum/showthread.php?t=13985

Thanks

tirams
30 Nov 2007, 2:48 PM
# Ext version + build no.? Ext JS Library 1.1.1
# prototype adapter 1.1.1 / Prototype JavaScript framework, version 1.5.0
# Windows XP
# Firefox 2.0.0.10 and IE 6
# code snippet - see above (http://extjs.com/forum/showthread.php?p=93641#post93641) code to reproduce it.
# FireBug - no error but shows request still active not aborted

hendricd
30 Nov 2007, 3:05 PM
Prototype 1.50 does not expose a simple transaction handle for each request (other than the Request object itself). Nor, does it provide an abort interface in its XHR abstraction.

And, the Ext prototype adaptor bridge does not return the new Ajax.Request object used by prototype. If it did,the best you could attempt:




protoAjaxObj.transport.abort();

tirams
30 Nov 2007, 3:12 PM
Yes I see that the "new Ajax.Request()" transports not being stored as the transaction object. Can this protoAjaxObj.transport.abort() fix be added to the 1.1.1 adaptor? Or is there a workaround I can use to extend the adaptor to address the issue.

Thanks for any help.

tirams
30 Nov 2007, 4:34 PM
Thanks!

needed changes :


missing ) after condition
if(this.isCallInProgress(transId)){n\

The createSuccess and createFailure functions referred to in the request function needed definition, as they are private to the bridge code.

isCallInProgress : function(transId){



In case anyone else needs to override this or if it won't be fixed in ext1x or 2x. Here's is the modified version of hendricd's code I used. I tested with prototype 1.5.0 and it successfully performs the abort.


Ext.apply( Ext.lib.Ajax ,{
createSuccess :function(cb){
return cb.success ? function(xhr){
cb.success.call(cb.scope||window, {
responseText: xhr.responseText,
responseXML : xhr.responseXML,
argument: cb.argument
});
} : Ext.emptyFn;
},
createFailure : function(cb){
return cb.failure ? function(xhr){
cb.failure.call(cb.scope||window, {
responseText: xhr.responseText,
responseXML : xhr.responseXML,
argument: cb.argument
});
} : Ext.emptyFn;
},

request : function(method, uri, cb, data, options){
var o = {
method: method,
parameters: data || '',
timeout: cb.timeout,
onSuccess: this.createSuccess(cb),
onFailure: this.createFailure(cb)
};

if(options){
if(options.headers){
o.requestHeaders = options.headers;
}
if(options.xmlData){
method = 'POST';
o.contentType = 'text/xml';
o.postBody = options.xmlData;
delete o.parameters;
}
if(options.jsonData){
method = 'POST';
o.contentType = 'text/javascript';
o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
delete o.parameters;
}
}
return new Ajax.Request(uri, o);
},
abort : function(transId){
if(this.isCallInProgress(transId)){
transId.transport.abort(); //this may throw on certain browers/readystates
}
},
isCallInProgress : function(transId){
return (transId && transId.transport && !transid._complete===true ) || false;
}
});


I have used abort successfully before with prototype 1.5.0 transport which is a XMLHttpRequest that defines abort.

hendricd
30 Nov 2007, 7:46 PM
as they are private to the bridge code.Right on , I missed the privates and can't type worth a sometimes. ;)