Jul 08, 2013, 3:19 AM
[FIXED] [2.3] DesktopModules created by DirectMethods cause an error in the dynamic JavaScript
This post stems from a discussion that I've been having with Daniil in Stackoverflow in regards to creating Desktop Windows and Modules "on the fly" (http://stackoverflow.com/questions/1...t-net/17417962
Description:
When creating modules in a controller as a response to a DirectEvent the dynamically generated JS function that loads the returned module, fails if no module exists yet. However, if a "dummy" module is created first, then the module returned by the Controller loads correctly.
How to reproduce the problem:
1) Create a simple Desktop definition on a Razor view with no modules and a DirectEvent that calls a controller action when the desktop is ready.
If the code is modified by pre-defining a "dummy module" in the Razor view as follows:
I hope this helps you pinpoint the problem and fix it.
Cheers.
Description:
When creating modules in a controller as a response to a DirectEvent the dynamically generated JS function that loads the returned module, fails if no module exists yet. However, if a "dummy" module is created first, then the module returned by the Controller loads correctly.
How to reproduce the problem:
1) Create a simple Desktop definition on a Razor view with no modules and a DirectEvent that calls a controller action when the desktop is ready.
@(
X.Desktop()
.ID("MyDesktop")
.Listeners(l =>
{
l.Ready.BroadcastOnBus = "App.MyDesktop.Ready";
})
//Other config options here ...
.DirectEvents(de =>
{
de.Ready.Url = Url.Action("LoadModule");
de.Ready.ExtraParams.Add(new Parameter() { Name = "desktopId", Value = "MyDesktop" });
de.Ready.EventMask.ShowMask = true;
de.Ready.EventMask.Msg = "Loading Modules ...";
})
.Modules(
)
)
2) Create a controller action that returns a module.[DirectMethod]
public ActionResult LoadModule(string desktopId)
{
AjaxResult r = new AjaxResult();
Desktop desktop = X.GetCmp<Desktop>(desktopId);
DesktopModule module = new DesktopModule()
{
ModuleID = "Module1",
Shortcut = new DesktopShortcut() { Name = "Module 1 Shortcut" },
Window = {new Window(){Title = "My Dynamic Window"}}
};
desktop.AddModule(module);
return r;
}
When this code is run, it throws an error in the following JS function:getModule : function (name) {
var ms = this.modules;
for (var i = 0, len = ms.length; i < len; i++) {
var m = ms[i];
if (m.id == name || m.appType == name) {
return m;
}
}
}
It seems that since no modules exist yet, when the first module is being created and this function is called, the "this.modules" variable is undefined and generates the error.If the code is modified by pre-defining a "dummy module" in the Razor view as follows:
.Modules(
X.DesktopModule()
.ModuleID("DummyModule")
.Shortcut(
X.DesktopShortcut()
.Name("Dummy Module")
)
)
then the dynamically created module and window work just fine.I hope this helps you pinpoint the problem and fix it.
Cheers.
Last edited by Daniil; Jul 11, 2013 at 3:16 PM.
Reason: [FIXED] [2.3]