Tuesday, December 21, 2010

MODx 2 Resource Create/Update Cancel redirect

If you need to create your own resource grid,
you may find it difficult to control the resource create / update redirect on after save or when cancel button is clicked.
One way to do this is to add your own startupclientscript like this:
----------------------
setCancelButton();

function setCancelButton() {
if (!Ext.getCmp("modx-action-buttons")) {
setTimeout("setCancelButton()", 1000);
return;
}
Ext.getCmp("modx-action-buttons").actions.cancel = 90;//your action number
for(var c=0; c Ext.getCmp("modx-action-buttons").items.items.length; c++) {
if (Ext.getCmp("modx-action-buttons").items.items[c].process == "cancel") {
Ext.getCmp("modx-action-buttons").items.items[c].handler = cancelHandler;
}
}
}

var cancelHandler = function (btn,e) {
var fp = Ext.getCmp(this.config.formpanel);
if (fp && fp.isDirty()) {
Ext.Msg.confirm(_('warning'),_('resource_cancel_dirty_confirm'),function(e) {
if (e == 'yes') {
MODx.releaseLock(MODx.request.id);
MODx.sleep(400);
location.href = '?a=90'; //your url or action here
}
},this);
} else {
MODx.releaseLock(MODx.request.id);
location.href = '?a=90'; //your url or action here
}
}


No comments: