Results 1 to 11 of 11
  1. zemoffm's Avatar
    Posts
    105 Posts
    Global Posts
    107 Global Posts
       #1  
    Ok, so I'm not sure what I'm doing wrong. Basically, I'm doing what I figure is fairly common practice: externalize some functions that are used in different classes into one outside class. For some reason though, I can't access that class or the methods in it from my scene assistant.

    I have a Common.jsjsjs $file$ $with$ $the$ $following$:
    Code:
    function Common() {
        
        function dispNotImpDialog() {
            Mojo.log.info("*** In dispNotImpDialog method");
            Mojo.Controller.showAlertDialog({
                onChoose : function(inValue) {},
                title : "Not Yet Implemented",
                message : "TODO: Implement this!",
                choices : [
                    { label : "Ok", value : "" }
                ]
            });  
        };
    
    };
    
    var commonClass = new Common();
    Then, I add it to the sources.json file:
    Code:
    {"source": "app/Common.jsjsjs&$quot$;}
    It is my understanding that doing this is the same as adding a <script language="javascript" src="common.jsjsjs&$quot$;&$gt$;&$lt$;/$script$&$gt$; $to$ $my$ $document$ ($I$'$m$ $assuming$ $that$'$s$ $the$ $index$.$html$ $document$).

    From my welcome-scene.jsjsjs $file$, $I$ $attached$ $a$ $Tap$ $listener$ $to$ $a$ $button$, $which$ $when$ $activated$ $then$ $I$ $want$ $to$ $call$ $this$ $method$ $in$ $the$ $Common$.$js$ $file$:
    Code:
    WelcomeAssistant.prototype.clickButton = function() {
        commonClass.dispNotImpDialog();
    };
    This doesn't work, and I can't figure out why. I get the following error message in the emulator debug:
    2011-04-12T00:08:25.025339Z [10255] qemux86 user.crit LunaSysMgr: {LunaSysMgrJS} : com.mikem.firstproject: Uncaught TypeError: Object #<a Common> has no method 'dispNotImpDialog', file:///media/cryptofs/apps/usr/palm/applications/com.mikem.firstproject/app/assistants/welcome-assistant.jsjsjs:$30$

    So it is not even finding the Class and therefore the function. I can't figure out why it can't find the function.

    I'm using SDK 1.4.5, just FYI.


    Any ideas?

    I checked out this thread (among others): http://forums.precentral.net/web-os-...e-js-file.html

    But can't figure out what's going on. Any help would be greatly appreciated. Thanks in advance. (Also, I tried the main developer.palm.com forums, but their forums are giving me PHP errors so i can't even post).
  2. #2  
    Your Common.jsjsjs $file$ $needs$ $to$ $be$ $listed$ $before$ $your$ $scene$ $assistant$ $in$ $sources$.$json$ $in$ $order$ $for$ $your$ $scene$ $assistant$ $to$ $acknowledge$ $it$.
  3. zemoffm's Avatar
    Posts
    105 Posts
    Global Posts
    107 Global Posts
       #3  
    Thanks, but I tried this, and I'm still having the same problem.
  4. zemoffm's Avatar
    Posts
    105 Posts
    Global Posts
    107 Global Posts
       #4  
    Ok I figured it out, I think.

    changed the function in the class to be declared like this:
    this.dispNotImpDialog = function() { .... }

    Which fixed the problem of not finding the method.

    But now I think there is something wrong with my alertDialog. I get the following in the log:
    Uncaught TypeError: Object #<an InstallPrototypeBuiltIn> h
    as no method 'showAlertDialog'

    Is there an issue with calling Mojo.Controller.showAlertDialog() on a class that is not the scene assistant? Is there any way to get it to the right scene? I saw one example from the stage assistant that had something like:
    this.controller.activeScene().showAlertDialog({...})

    But you can only do that from a stage, not just a plain javascript class/object. What am i missing?
  5. #5  
    Quote Originally Posted by zemoffm View Post
    Ok I figured it out, I think.

    changed the function in the class to be declared like this:
    this.dispNotImpDialog = function() { .... }

    Which fixed the problem of not finding the method.

    But now I think there is something wrong with my alertDialog. I get the following in the log:
    Uncaught TypeError: Object #<an InstallPrototypeBuiltIn> h
    as no method 'showAlertDialog'

    Is there an issue with calling Mojo.Controller.showAlertDialog() on a class that is not the scene assistant? Is there any way to get it to the right scene? I saw one example from the stage assistant that had something like:
    this.controller.activeScene().showAlertDialog({...})

    But you can only do that from a stage, not just a plain javascript class/object. What am i missing?
    I would pass in the this.controller to dispNotImpDialog.

    So:

    Code:
    function Common() {
        
        this.dispNotImpDialog = function(controller) {
            Mojo.log.info("*** In dispNotImpDialog method");
            controller.showAlertDialog({
                onChoose : function(inValue) {},
                title : "Not Yet Implemented",
                message : "TODO: Implement this!",
                choices : [
                    { label : "Ok", value : "" }
                ]
            });  
        };
    
    };
    var commonClass = new Common();
    ...
    
    commonClass.dispNotImpDialog(this.controller);
    This is what I do. (Test the code first, just to make sure that it actually runs ).
    Did you know:

    webOS ran on a Treo 800 during initial development.
  6. zemoffm's Avatar
    Posts
    105 Posts
    Global Posts
    107 Global Posts
       #6  
    Thanks for the suggestion. I went away for a while, but now I'm back, and tried it, and still nothing, although now I get a slightly different error in the logs:

    2011-05-05T00:42:12.467035Z [536] qemux86 user.crit LunaSysMgr: {LunaSysMgrJS}: com.mikem.firstproject: Uncaught TypeError: Cannot call method 'showAlertDialog' of undefined, file:///media/cryptofs/apps/usr/palm/applications/com.mikem.firstproject/app/Common.jsjsjs:$5$

    I agree what you suggested SHOULD work, but there is either something wrong with that showAlertDialog method... or this is a sign.

    I mean in theory this is a pretty small thing, and I guess I could just code around it somehow, but it makes me nervous how such a simple documented method isn't working.
  7. #7  
    There seem to be issues with calling a controller outside a scene's JavaScript file in Mojo. It is why I ditched it and just went straight JavaScript and JQuery mobile. If you know enough JavaScript, I say just ditch Mojo.

    The only tricky part is having to roll your scroller, but you can just steal my ScrollBox class for that if you want.
  8. zemoffm's Avatar
    Posts
    105 Posts
    Global Posts
    107 Global Posts
       #8  
    Thanks for the suggestion. It's definitely frustrating that something as basic as this is broken, and my JavaScript is too rusty to go that route, but I'll check out other options.
  9. #9  
    Quote Originally Posted by zemoffm View Post
    Thanks for the suggestion. It's definitely frustrating that something as basic as this is broken, and my JavaScript is too rusty to go that route, but I'll check out other options.
    Try the following:

    Code:
    function Common() {
    }
    Common.prototype.dispNotImpDialog = function() {
            Mojo.Log.info("*** In dispNotImpDialog method");
            Mojo.Controller.showAlertDialog({
                onChoose : function(inValue) {},
                title : "Not Yet Implemented",
                message : "TODO: Implement this!",
                choices : [
                    { label : "Ok", value : "" }
                ]
            });  
        };
    
    };
    
    var commonClass = new Common();
    Also note that (I'm not 100% certain) by naming it "Common" you may be overwriting a function in the built-in JavaScript engine or from Prototype.

    The two things I changed above are:

    1) Fixed Mojo.log to Mojo.Log
    2) Moved it to the prototypal system JavaScript uses and that is recommended by HP/Palm.

    If it doesn't work, integrate the suggestion of Donald into what I put together and see if the two combined work properly.
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  10. #10  
    Should your commonClass declaration be in your welcome-assistant?

    I would normally just call Common.dispNotImpDialog(), if I wanted to call a function from another jsjsjs $file$ $included$ $in$ $sources$. $Or$ $if$ $I$ $need$ $a$ $reference$ $then$ $declare$ $the$ $reference$ $in$ $the$ $welcome$-$assistant$.
    French Pre3, UK Pre2, US Veer, German gsm Pre, 680, garmin ique 3600 & still have my working palm pilot 1000 with the 1 Mb adapter

    Please remove UberCalendar and google sync behavior patches prior to system updates.
    patch Google calendar sync behavior for 2.x.x and TouchPad (Oauth2 and advanced sync requirements enabled)
    Preference guide for MetaView's UberCalendar patch
  11. zemoffm's Avatar
    Posts
    105 Posts
    Global Posts
    107 Global Posts
       #11  
    Thanks a lot guys, sorry for the long delay, I went out of town for a bit.

    Anyway I'm back, and tried the suggestions and finally got it working. I set it up like this:

    function Common() {
    };

    Common.prototype.dispNotImpDialog = function(controller) {
    Mojo.Log.info("*** In dispNotImpDialog method");
    controller.showAlertDialog({
    onChoose : function(inValue) {},
    title : "Not Yet Implemented",
    message : "TODO: Implement this!",
    choices : [
    { label : "Ok", value : "" }
    ]
    });
    };


    var commonClass = new Common();
    PS, I have no idea why its not quoting the spaces/indents so that it looks nice

    Then I called it like this:

    commonClass.dispNotImpDialog(this.controller);
    I coulda sworn I did that like a million times, but anyway, its working finally!

Posting Permissions