PDA

View Full Version : Success event on proxy in model



mgamsjager
16 May 2014, 12:09 AM
Hello,

I have this model:



Ext.define('Administration.model.contestent', {
extend: 'Ext.data.Model',
alias: 'model.contestent',
fields: [
// { name: 'id'},
{ name: 'firstName', type: 'string' },
{ name: 'middleName', type: 'string' },
{ name: 'lastName', type: 'string' },
{ name: 'startNr', type: 'string' },
{ name: 'classCategorie', type: 'string' },
{ name: 'combination', type: 'string'}


],
proxy: {
type: 'rest',
url : 'http://127.0.0.1:8086/api/candidate',
reader: {
type: 'json',
rootProperty: '',
listeners: {
exception: function( reader, response, error, eOpts ) {
debugger;
}
}
},
writer: {
type: 'json'


}

}

});



But the exception is never raised. Nor is there a failure or success event .

The work around I use is this:


stores: {
contestens: {
model: 'contestent',
autoLoad: true,
sorters: [
{ property: 'startNr', direction: 'ASC' }
],
listeners:{
load: function( reader, records, successful, eOpts ){
if (!records) Ext.Msg.alert('No data loaded','Check connection or no data has been inserted yet');
}
}
}
}

Shouldn't I have a success/failure callback when loading data?

skirtle
16 May 2014, 12:50 AM
From a quick look through the ExtJS 5 source I can't find any evidence that the reader event still fires, though it is still documented.

I suspect you'd be better off using the exception event on the proxy rather than the reader. The proxy event is more of a catch-all whereas the reader event was only intended to catch corrupt data.

mgamsjager
16 May 2014, 1:17 AM
I changed the model to this but no exception is raised.

proxy: { type: 'rest',
url : 'http://127.0.0.1:8086/api/candidate',
reader: {
type: 'json',
rootProperty: ''
},
writer: {
type: 'json'


},
listeners: {
exception: function( reader, response, error, eOpts ) {
debugger;

}
}

}

olecom
16 May 2014, 7:54 AM
Can be not v5 related but in v4 model's proxy config doen't apply to store config. Thus roll own proxy class and use it in model and/or store configurations.

for ref: https://github.com/olecom/enjsms/blob/master/app_main/proxy/CRUD.js

skirtle
17 May 2014, 2:33 AM
How does your server communicate the error? Status code?

mgamsjager
19 May 2014, 4:36 AM
How does your server communicate the error? Status code?
Timeout because the endpoint isn't running.

olecom
19 May 2014, 6:10 AM
if server is down while app is in browser and is loading a store this is what it gets in Ext.Msg UI:


TypeError: undefined is not a function
at crud_exception (eval at <anonymous> (http://localhost:3007/extjs/ext-all-nw.js:889:18), <anonymous>:23:71)
at fire (http://localhost:3007/extjs/ext-all-nw.js:16022:49)
at continueFireEvent (http://localhost:3007/extjs/ext-all-nw.js:17886:47)
at fireEventArgs (http://localhost:3007/extjs/ext-all-nw.js:17857:26)
at fireEvent (http://localhost:3007/extjs/ext-all-nw.js:17834:25)
at Ext.define.processResponse (http://localhost:3007/extjs/ext-all-nw.js:101848:16)
at null.<anonymous> (http://localhost:3007/extjs/ext-all-nw.js:102349:16)
at Object.Ext.apply.callback (http://localhost:3007/extjs/ext-all-nw.js:12089:26)
at Ext.define.onComplete (http://localhost:3007/extjs/ext-all-nw.js:48215:13)
at Ext.define.onStateChange (http://localhost:3007/extjs/ext-all-nw.js:48151:16)
in console:


GET http://localhost:3007/um/lib/chat/user?_dc=1400511262241 net::ERR_CONNECTION_REFUSED
[constructor, Object, constructor, Object]
0: constructor
1: Object
getAllResponseHeaders: function () {
getResponseHeader: function (header) {
request: Object
requestId: 16
responseText: ""
responseXML: null
status: 0
statusText: ""
__proto__: Object
2: constructor
action: "read"
addRecords: false
error: Object
exception: true
filters: Array[0]
groupers: Array[0]
limit: 25
page: 1
params: Object
request: constructor
running: false
sorters: Array[0]
start: 0
success: false
__proto__: Object
3: Object
exception: function crud_exception(proxy, res, op){
__proto__: Object
callee: function crud_exception(proxy, res, op){
length: 4
__proto__: Object