Sigma Php Ajax framework, Ajax Components, GUI Builder
May 24, 2012, 10:28:37 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: I am trying to figure out how to synchronously invoke a submodule  (Read 1567 times)
unger
Jr. Member
**
Posts: 14


View Profile
« on: March 27, 2011, 02:43:45 PM »

I have a submodule called module1.js that contains an App.Module with a single dialog in it. I am trying to figure out how to invoke this submodule to display the dialog synchronously as part of the calling app (index.js). I want to allow code in the module to complete before returning to the calling code in index.js. Is there any way to do this.
Logged
linb
Administrator
Hero Member
*****
Posts: 435


View Profile
« Reply #1 on: March 27, 2011, 07:50:35 PM »

Ensure module1.js in memory.

var m = new App.Module();
m.xxx
Logged
unger
Jr. Member
**
Posts: 14


View Profile
« Reply #2 on: March 29, 2011, 05:47:31 PM »

How do i ensure the module is in memory? And then how do I get the module to display its dialog.
« Last Edit: March 29, 2011, 06:47:25 PM by unger » Logged
linb
Administrator
Hero Member
*****
Posts: 435


View Profile
« Reply #3 on: March 30, 2011, 01:17:52 AM »

In html file:


In your index.js file:

Logged
unger
Jr. Member
**
Posts: 14


View Profile
« Reply #4 on: March 31, 2011, 12:25:20 AM »

This was added to index.html

<script type="text/javascript" src="/App/js/DialogA.js"></script>

This is the code I put in the index.js

        _ctl_button3_onclick : function (profile, e, src, value) {
            var ns = this, uictrl = profile.boxing();
             var m = new App.DialogA();
            m.ctl_dialog12.show();             
        }

Using firebug i determined that something is in error ... the message is

App.DialogA is not a constructor
[Break on this error] var m = new App.DialogA();

Logged
linb
Administrator
Hero Member
*****
Posts: 435


View Profile
« Reply #5 on: March 31, 2011, 07:30:58 AM »

Are you able to check the "App.Dialog" in the memory already, before you call "new App.Dialog()"?
Logged
unger
Jr. Member
**
Posts: 14


View Profile
« Reply #6 on: March 31, 2011, 10:12:58 AM »

I corrected the include added to index.html to point to the proper directory.


    <body>
        <div id='loading'><img src="../../../runtime/loading.gif" alt="Loading..." /></div>
        <script type="text/javascript" src="../../../runtime/jsLinb/js/linb-all.js"></script>
        <script type="text/javascript" src="../../../runtime/jsLinb/js/adv-all.js"></script>
        <script type="text/javascript" src="App/js/index.js"></script>
        <script type="text/javascript">
            linb.Com.load('App', function(){linb('loading').remove();});
        </script>
<style>#linbar a, ....
</body>


When I attempt to run this, i get a console error


Firebug's log limit has been reached. 0 entries not shown.      Preferences   
h is not a constructor
[Break on this error] var undefined,_=window._=function(){re...dingLeft"))||0)}l.cssSize(n,true)}}});


However if i modify debug.html as below:


    <body>
        <div id='loading'><img src="../../../runtime/loading.gif" alt="Loading..." /></div>
        <script type="text/javascript" src="../../../runtime/jsLinb/js/linb-debug.js"></script>
        <script type="text/javascript" src="../../../runtime/jsLinb/js/adv-debug.js"></script>
        <script type="text/javascript" src="App/js/index.js"></script>
        <script type="text/javascript">
            linb.Com.load('App', function(){linb('loading').remove();});
        </script>
         <script type="text/javascript" src="App/js/DialogA.js"></script>
<style>#linbar a, ....

</body>


It works....

I can run with a copy of debug.html as a replacement for index.html... but why does this happen
Logged
linb
Administrator
Hero Member
*****
Posts: 435


View Profile
« Reply #7 on: March 31, 2011, 06:39:47 PM »

The KEY is --

<script type="text/javascript" src="App/js/DialogA.js"></script>

not index.html or debug.html
Logged
sedrok (jslinb.ru)
Sr. Member
****
Posts: 57


View Profile
« Reply #8 on: April 09, 2011, 06:33:48 AM »

DialogA.js

should start from:

Class('App.DialogA', 'linb.Com',{
...
...
.

?
Logged
sedrok (jslinb.ru)
Sr. Member
****
Posts: 57


View Profile
« Reply #9 on: April 12, 2011, 07:48:17 AM »

Can you give full source of this example, please
Logged
khagans
Full Member
***
Posts: 20


View Profile
« Reply #10 on: April 15, 2011, 02:24:09 PM »

sedrok1,

Here's an example of how I handle the situation that you are describing. 

1)  Create  "conf.js" file to define all of the classes that you want to load at runtime.

CONF = {ComFactoryProfile:
           {
               module1:{
                   cls: 'App.Module1'
               },
               module2:{
                   cls: 'App.Module2'
               }
             }
}

2)  In your "index.html" file you will load all of your foundation classes and com factory configuration:

        <script type="text/javascript" src="../../../runtime/jsLinb/js/linb-all.js"></script>
        <script type="text/javascript" src="../../../runtime/jsLinb/js/adv-all.js"></script>
        <script type="text/javascript" src="./App/js/conf.js"></script>
        <script type="text/javascript" src="./App/js/index.js"></script>
        <script type="text/javascript">
           linb.Com.load('App', function(){
               linb('loading').remove();
           },'en');
        </script>

3)  In your "index.js" you will define your com factory, and launch the dialog box (sub-module):

          _com_onready : function (com, threadid) {
                linb.UI.setTheme('vista');
                linb.ComFactory.setProfile(CONF.ComFactoryProfile);
                SPA = this;

                linb.ComFactory.newCom('module1',
                   function(){
                     //Here is the code you want to execute when the module1 class is loaded...

                         //The first thing you need is an event hook in your dialog box module...
                         //Remember that "this" is module1 now...
                         this.setEvent("onFinish",function(response){
                                   //What do you want to do here (SPA [index.js]) when the event is
                                   //fired in module 1
                                   SPA.module1_is_done(response);
                          });
                     this.dialog.show();   //Here we tell your dialog box to show on top as a modal dialog
                   }

            },
           
            module1_is_done : function(values){


                         //Do a bunch of stuff here...
                         //and "values" are the response object passed to the "onFinish" event
                         //handler

            }
             

4)  Finally, in your module1 class ("App.Module1") you need to fire the event "onFinish"

              //Do a bunch of stuff with your dialog box,
              //when finished, fire the event and close the dialog...

              _buttonok_onclick : function (profile, e, src, value){

                    var dialog_box_value = "Stuff to go back to calling module";

                    this.fireEvent("onFinish",[{"stuff":dialog_box_value}]);
                    this.dialog.destroy();


              }
             
I hope this helps.  If it's too confusing, drop me an e-mail and I'll send you some sample code from one of my applications.  It might be easier to understand it if you can see a working copy.

Good luck!

-Ken  (ken [at] kghagans [dot] com)
Logged
erlinda
Newbie
*
Posts: 1


View Profile WWW
« Reply #11 on: May 20, 2011, 02:15:41 AM »

I want to allow code in the module to complete before returning to the calling code in index.js. Is there any way to do this. Shocked
Logged

khagans
Full Member
***
Posts: 20


View Profile
« Reply #12 on: May 27, 2011, 04:44:07 AM »

How about an observable thread?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!