PDA

View Full Version : rowExpander wait for AJAX request to (not)epxand



giraffezw
7 Oct 2010, 1:29 AM
I have a grid with a rowexpander. "beforeexpand" i have to check user permission (ajax request), if the user have no permission the beforeexpand listener should return false.

because of the properties which brings an ajax request with it (async), i have no idea how I could solve the problem.

Expander have to wait the response from the server and see whether the user can expand or not

thx, for help

Condor
7 Oct 2010, 1:37 AM
1. Use a flag that defaults to false
2. If the flag is not set, do your request and return false.
3. If the flag is set, clear the flag and continue normally.
3. In the response set the flag and expand the group again.

Example (http://www.sencha.com/forum/showthread.php?56946-MessageBox.confirm-doesnt-stop-in-some-cases&p=271923#post271923) (for closing a tab, but same principle applies).

giraffezw
7 Oct 2010, 3:48 AM
I have previously tried:



,rowexpander: new Ext.grid.RowExpander({
tpl: new Ext.Template(
' <b>Vorschau:</b> {summary}<br><br>'
)
,listeners: {
beforeexpand: function(expander, rec, bodyElement, rowIndex) {
console.log('prüfen ob berechtigung vorliegt');

var grid = Ext.getCmp('foundGrid');

var window = Ext.getCmp('search-win');
window.getEl().mask('lade...', 'x-mask-loading');

var permission = false;
var conn = new Ext.data.Connection();
conn.request({
url : contextPath + "/download/checkPermission"
,params : {mergeDocs: rec.get('path')}
,method: 'POST'
,success: function ( result, request ) {
window.getEl().unmask();
permission = true;
}
,failure: function ( result, request) {
window.getEl().unmask();
permission = false;
}
});
return permission;
}
}
})


But the permission is always false. Unfortunately not quite understand what you mean :(

Condor
7 Oct 2010, 5:43 AM
No, this will never work with a local flag. I suggest you read the linked post again.

giraffezw
7 Oct 2010, 7:04 AM
ok, after read again and again... ;) it works, but only if the user click twice.

i think thats the reason why you suggest this

3. In the response set the flag and expand the group again.but in some case there are no groups. so i need something that works without groups



,listeners: {
beforeexpand: function(expander, rec, bodyElement, rowIndex) {
var grid = Ext.getCmp('foundGrid');

if (grid.allowExpand) {
delete grid.allowExpand;
return true;
} else {
var window = Ext.getCmp('search-win');
window.getEl().mask('lade...', 'x-mask-loading');

var conn = new Ext.data.Connection();
conn.request({
url : contextPath + "/download/checkPermission"
,params : {mergeDocs: rec.get('path')}
,method: 'POST'
,success: function ( result, request ) {
window.getEl().unmask();
grid.allowExpand = true;
return true;
}
,failure: function ( result, request) {
window.getEl().unmask();
return false;
}
});
}
return false;
}
}

giraffezw
7 Oct 2010, 10:37 PM
I wish you a wonderful good morning ;)

i have added a callback function to the request



,callback: function(request, success, response) {
if (success == true) {
this.toggleRow(rowIndex);
}
},scope:this


now it works. thanks for great help!

Condor
7 Oct 2010, 10:58 PM
You are almost there.

1. The success and failure methods don't need to return anything.
2. You can use your existing success handler to do the toggleRow (no need to use callback).

giraffezw
8 Oct 2010, 12:00 AM
that 's it! great =D>