[FIXED] [2.3] DesktopModules created by DirectMethods cause an error in the dynamic JavaScript

  1. #1

    [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.
    @(
     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]
  2. #2
    Thanks for the report, it will be fixed in the next public release
    Vladimir Shcheglov
    Sr. Developer

Similar Threads

  1. Replies: 1
    Last Post: Apr 25, 2013, 6:02 AM
  2. [CLOSED] Dynamic UserControls with DirectMethods
    By JulianPreece in forum 2.x Premium Help
    Replies: 3
    Last Post: Sep 13, 2012, 9:50 AM
  3. Call DirectMethods from Javascript
    By ginsar in forum 1.x Help
    Replies: 4
    Last Post: Jun 08, 2011, 11:59 AM
  4. [CLOSED] JavaScript error in dynamic user control
    By schellappa in forum 1.x Premium Help
    Replies: 7
    Last Post: Dec 21, 2010, 4:01 PM
  5. [CLOSED] Javascript Error loading dynamic usercontrol 1.0
    By SymSure in forum 1.x Premium Help
    Replies: 3
    Last Post: Apr 01, 2010, 3:05 AM

Tags for this Thread

Posting Permissions