I use it quite often in an app I am making, so I would like to shorten it up if I can and make an extended class to handle all the callback logic in one place, I tried setting it up like this but fails when trying to load the class with:
Uncaught TypeError: Cannot read property 'isInstance' of undefined ext-all-debug.js:4136
ExtClass.registerPreprocessor.config ext-all-debug.js:4136
Ext.apply.doProcess ext-all-debug.js:4007
Manager.registerPostprocessor.uses ext-all-debug.js:6037
Ext.apply.require ext-all-debug.js:5771
Manager.registerPostprocessor.uses ext-all-debug.js:6004
Ext.apply.doProcess ext-all-debug.js:4007
Ext.apply.doProcess ext-all-debug.js:4008
Ext.apply.process ext-all-debug.js:3995
Ext.Class.ExtClass ext-all-debug.js:3911
Ext.ClassManager.create ext-all-debug.js:4676
Ext.apply.define ext-all-debug.js:5095
(anonymous function) Ajax.js:1 //My extended Ajax singleton
Here is how I try to call it
var changes = e.record.getChanges();
if (e.record.get('id'))
changes.id = e.record.get('id');
APP.ux.Ajax.request({
url: '/admin/user/save/',
params: changes,
scope: this
});
UPDATE
That makes sense, I can't believe overlooked that, but I still get the same read property 'isInstance' of undefined error above. Here is how it looks now
And here is the simple class (Updated)
Ext.define('APP.ux.Ajax', {
extend: 'Ext.data.Connection',
requires: [
'APP.ux.Msg'
],
singleton : true,
autoAbort : false,
request: function(config) {
var cfg = config;
Ext.apply(cfg, {
success: function(form, action) {
APP.ux.Msg.alert('Success', action.result.msg);
//TODO: Add more logic here
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.action.Action.CLIENT_INVALID:
APP.ux.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.action.Action.CONNECT_FAILURE:
APP.ux.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.action.Action.SERVER_INVALID:
APP.ux.Msg.alert('Failure', action.result.msg);
break;
}
}
});
this.callParent(cfg);
}
});