PDA

View Full Version : Logic to Cancel an already made login request on the a Login Screen



mazhar.shaikh
13 May 2013, 2:57 PM
Hi ,

I have a basic login screen with a Login and Cancel button.
Currently my Cancel button resets the Username and Password fields, but doesnt cancel the request itself (if it has been made already and not yet completed).

I am looking for some lines of code to cancel/abort/destroy the request.

here is my code.
Store:

Ext.define('MasterDataManager.store.Authentication', {
extend: 'Ext.data.Store',


requires: [
'MasterDataManager.model.Authentication'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: false,
storeId: 'authentication',
model: 'MasterDataManager.model.Authentication',
proxy: {
type: 'rest',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
reader: {
type: 'json',
successProperty: 'success2'
}
}
}, cfg)]);
}
});


Cancel button controller click event:



var store = Ext.getStore('Authentication');
// TODO : Cancel the request if it has been already made
Ext.getCmp('loginForm').getForm().reset();


Thanks

mice-pace
13 May 2013, 5:08 PM
I haven't had to do this before, but i managed to hunt up a few scraps to point me in the right direction... if you add an 'beforeload' event to your store... maybe something like


function(store, operation) { store.lastOperation = operation;}

Then you can use that to get access to the request object... The request can be fed to Ext.Ajax to cancel that particular request...




Ext.Ajax.abort(Ext.getStore('authentication').lastOperation.request);



If that helps, then remember...

Before jumping on the forums, always do a quick google search, 9 times out of 10 someone has had the same problem before you had it.

I *HAVEN'T* tested this code, nor did i write it... It's an educated guess based on:
http://www.sencha.com/forum/showthread.php?50183-abort-cancel-store.load (Possibly the same problem, but outdated)
http://stackoverflow.com/questions/13251440/selectively-aborting-an-ajax-request-sent-via-extjs-direct-proxy (similar problem, but more recent)

backed up by some double checking:
http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.Ajax-method-abort
http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.Store-event-beforeload
(http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.Store-event-beforeload)
And don't forget to check docs.sencha too! (it wouldn't have helped this time, but normally browsing the function list for an object answers half my questions)

mazhar.shaikh
12 Nov 2013, 6:17 PM
following line was enough and does the job.


Ext.Ajax.abort();