PDA

View Full Version : [CLOSED] Direct Event/Method Call Priority



bayoglu
Feb 07, 2013, 5:36 PM
Hello,

What is the call priority for direct event and direct method listener in case they are both configured for the same event of a component? Is there a sequence followed and former one can prevent execution of the other or they are called asynchronously?

Tkanks.

geoffrey.mcgill
Feb 07, 2013, 8:41 PM
in case they are both configured for the same event of a component?

Don't do this.

Baidaly
Feb 07, 2013, 10:07 PM
Hello,

What is the call priority for direct event and direct method listener in case they are both configured for the same event of a component? Is there a sequence followed and former one can prevent execution of the other or they are called asynchronously?

Tkanks.

Hello!

I agree with Geoffrey you shouldn't do this. Main reason it doesn't have sense because both of these mechanisms were created to communicate with a server. However, in most situations DirectMethod is called first but you can change it using Delays.

If can you provide example where you need this we can help you to find other ways to solve your problem.

bayoglu
Feb 07, 2013, 11:18 PM
Hello!

I agree with Geoffrey you shouldn't do this. Main reason it doesn't have sense because both of these mechanisms were created to communicate with a server. However, in most situations DirectMethod is called first but you can change it using Delays.

If can you provide example where you need this we can help you to find other ways to solve your problem.

I agree that it sounds weird to configure both direct event and direct method for the same event. The solution is related to my previous post here: http://forums.ext.net/showthread.php?23377-CLOSED-How-to-load-IFrame-to-parent-page

Briefly, a grid column command loads another aspx page in an iframe window. I needed to render this new window into current page or the parent page depending on a parameter. If the calling page is already a window child of a parent page, then the new aspx page is to be rendered in parent page. if the calling page is not rendered in a window, then it is safe to render the new aspx page in the calling page. Daniil adviced to call direct method of the parent page to render the new aspx page in parent page instead of calling page. To sum up, I configured both a direct event and a direct method for the command column, and I set a URL parameter. If parameter value is "1", then direct event before event handler returns false and prevents direct event call, and parent pages direct method is called by command handler listener. If parameter value is "0", direct event before handler returns true and direct event is called. In this case, command handler listener does not call parent page's direct method.

See below simplified codes for direct event before event handler and command listener handler calling parent page direct method.



//to check whether to call direct method or not
function commandHandler(command) {
if (command == "myCommand") {
var renderChildToText = App.hiddenParameter.getValue();
var renderChildTo = parseInt(renderChildToText);
if (!isNaN(renderChildTo)) {
if (renderChildTo == 1) { //call direct method of parent page
if (parent.App.direct != null) {
if (parent.App.direct.myDirectMethod != null) {
parent.App.direct.myDirectMethod();
}
}
}
}
}
}

//to prevent direct event call if hiddden parameter value equals 1
function directEventBeforeHandler() {
var renderChildToText = App.hiddenParameter.getValue();
var renderChildTo = parseInt(renderChildToText);
if (!isNaN(renderChildTo)) {
if (renderChildTo == 1) {
return false;
}
else { //render to current form
return true;
}
}
}


Do you think there is a safer way to do this? Thank you.

Baidaly
Feb 08, 2013, 1:44 AM
Why do you use DirectEvent in second page?

Can you instead of this use only JavaScript?

Something like this:

Modified Page 1 from your previous post http://forums.ext.net/showthread.php?23377-CLOSED-How-to-load-IFrame-to-parent-page :



<%@ Page Language="C#" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<script>
var openWindow = function(ctx) {
ctx.create('Ext.window.Window', {
id: 'page2',
height: 300,
hidden: false,
loader: {
renderer: 'frame',
url: 'http://ext.net'
},
renderTo: ctx.net.ResourceMgr.getRenderTarget(),
width: 300,
title: 'Page #2',
modal: true
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager2" runat="server"/>
<ext:Button ID="Button1" runat="server" Text="Show Window #2">
<Listeners>
<Click Handler="openWindow(window.parent != null ? window.parent.Ext : Ext); "></Click>
</Listeners>
</ext:Button>
</form>
</body>
</html>

bayoglu
Feb 08, 2013, 2:04 PM
Hello Baidaly, you rock!
window.parent != null ? window.parent.Ext : Ext did all the trick. Now I have only a command listener to render window to parent or current page. Thank you. Case closed.