webOS Nation Forums > webOS apps and software > webOS development > Application Menu w/AppAssistant?
1 2 
Member: Laxidasical
at: 04:43 AM 11/17/2009
When you setup an application menu widget in a scene and your handleCommand function is in your app-assistant.js rather than your stage-assistant.js, do you have to instantiate it with something like...

[code]
appController = Mojo.Controller.getAppController();
appController.setupWidget(Mojo.Menu.appMenu, MoJack.menuAttributes, MoJack.menuModel);
[/code]

...rather than...

[code]this.controller.setupWidget(Mojo.Menu.appMenu, MoJack.menuAttributes, MoJack.menuModel);[/code]

I ask because I haven't been able to get my app menu working again since I added an app assistant. I'm instantiating using the second way listed above. Here is the code in my app controller...

In my app assistant's setup function...
[code]
MoJack.menuAttributes = {omitDefaultItems: true};

MoJack.menuModel =
{
visible: true,
items:
[
Mojo.Menu.editItem,
{label: 'About MoJack...', command: 'do-aboutMoJack'}
]
};
[/code]

app assistant's handleCommend function...
[code]
AppAssistant.prototype.handleCommand = function(event)
{
var cardStageController = this.controller.getStageController('stage');

if (cardStageController && event.type == Mojo.Event.command)
{
var currentScene = cardStageController.activeScene();

switch(event.command)
{
case 'do-aboutMoJack':

currentScene.showAlertDialog
({
onChoose: function(value) {},
title: 'MoJack - V1.0.0',
message: 'Copyright 2009, MoJack LLC',
choices: [{label: 'OK', value: ''}]
});

break;
}
}
}
[/code]
Reply
Member: Laxidasical
at: 07:07 AM 11/18/2009
bump
Reply
Member: SirataXero
at: 08:51 PM 11/18/2009
Why do you have you assistant and model instantiated as "MoJack.model" I didn't know you could do it that way. I assumed you always had to use "this.model". Maybe try it with the "this" prefix? Also, try making them globals? I don't personally know, tbh, but I usually just set them as "this.menuModel" unless I want to call the model to change it later, at which point i'll just set it to a global as "menuModel".

Maybe that'll help?
Reply
Member: SirataXero
at: 09:08 PM 11/18/2009
actually, on re-checking your post, you might want to double check your handleCommand function. I think you have a few extra things in there. Try looking up my original tutorial on here (for an example, you could technicially use any of the apps). But, in my example, on the second scene, I have a basic menu item and its handleCommand. I'm sorry I don't exactly remember what it is since my computer is down... For now. : /
Reply
Member: Laxidasical
at: 01:52 AM 11/19/2009
I have a namespace called "MoJack" that is in my app-assistant.js setup function as well. This way I can declare MoJack.menuAttributes and MoJack.menuModel once and call them from any scene...makes changes to the menu easy since I don't have to do it in every scene. I had this same setup when this code with in stage-assistant.js and it worked great. Plus, I'm using several other variables & functions in the same namespace from different scenes with no problem. I did a quick test to make sure, I was able to grab data from both objects.

I agree, I believe the issue is somewhere in the handleCommand function since that was the only thing I changed since moving it from the stage assistant. The changes were required, because the app assistant needs to know which stage and scene to act on. I was following this example at Palm's Dev site. I've followed there example to the letter, then tried about a dozen other things. Nothing works!!!

One other thing I should mention...
The problem is that my menu doesn't display at all. I've tried removing any and every piece of code in my app that relates to menus (attributes, models, instantiations, handleCommand function)...nothing. Then I tried adding the Palm basic menu...nothing. It's almost like menus are completely disabled in my app! And yes, "visible" was set to "true" every time.

At this point, ANY ideas are more than welcome!!!
Reply
Member: SirataXero
at: 09:35 AM 11/19/2009
Hmmm... In THAT case do you have other widgets that aren't working? The ONLY time I've seen even default Palm Menus not work is when a widget is improperly implemented. Try removing anything that has to do with menus and just run the scene with a button widget, or some really simple widget (if you don't have any others already). If no other widgets are coming up, you may have a problem elsewhere...
Reply
Member: Laxidasical
at: 01:56 PM 11/19/2009
Some scenes have 1 widget while others have as many as 14. Everything in my app works except for the menus. I'm having a weird issue where the database gets deleted when I do updates via the SDK, but I don't think that's related to this problem.

Right now everything related to menus is gone. If I understand correctly, the basic Palm menu should display, correct?
Reply
Member: SirataXero
at: 02:54 PM 11/19/2009
wow, that's really odd. All the widgets work except for the menus?

Yeah, I would expect if you remove all customized menus from your scene, they should revert back to the defaults. Make sure you're not omitting the default menus somewhere higher up in your program. As in your stage assistant. Make sure that's COMPLETELY clear of all menu-related code. And then see if the basic default menus show up. Maybe?
Reply
Member: Laxidasical
at: 03:06 PM 11/19/2009
This is my COMPLETE stage-assistant.js file...

[code]
function StageAssistant() {}
[/code]

All of the code that was in there is now in my app-assistant.js file, as done in the example in the Palm webOS O'Reilly book. As a matter of fact, at the end of the book where he shows all of the code from every file, he doesn't include the stage-assistant.js file even though it's listed as being in the directory structure and in his sources.json file.

This leads me to a question...
In my app-assistant.js file, I'm using createStageWithCallback() to call the stage and push the main scene. For the attributes, I have...

[code]
var stageArguments = {name: 'stage', lightweight: true};
[/code]

Since the name of the stage is 'stage', it defaults to stage-controller.js, right???
Reply
Member: SirataXero
at: 03:17 PM 11/19/2009
In all honesty, I've never worked with the stage assistant. I always just use it to pick the first scene that gets launched. Theoretically that makes sense, the stage assistant being called 'stage' but that may have deeper implications, I'm not exactly sure what though. : /

Sorry!

A stage asistant can't have its own scene, could it? If it can, you could write something on it, make it NOT be lightweight and run it to see if this piece of code (calling it by the name "stage") actually works or not... : /
Reply
Member: Laxidasical
at: 03:27 PM 11/19/2009
From all my reading, the app assistant does have it's own stage/scene, but it's not accessible. This is why you have to use "noWindow: true" in appinfo.json when you have an app assistant. Also, "lightweight" is the only option supported right now. Supposedly that may change in the future.

I didn't know about the "noWindow: true" requirement when I first added the app assistant, and each time I launched my app, two cards would appear. One that had my app, and another (from the app assistant I guessing) that was completely blank.

So now I'm moving all menu related stuff back to the stage assistant to see if I can get it working there. Wish me luck! By the way, you get your laptop back up and running?
Reply
Member: SirataXero
at: 03:53 PM 11/19/2009
Alright well, good luck! Hopefully you can revert back to your old style and may be find a way to work around it.

No. : /. I don't have my laptop up and running yet, still. I'm waiting on a CD, which for some stupid reason, I do not have with me. Hopefully in a day or two i'll get access to the CD and be back up on my programming feet.

Idea: if it was working fine in the app assistant before, why did you move it to stage assistant? Was it just to have a custom/different menu in each stage? If you're going to need the same menu in most if not all of your scenes and just want to change a few, why don't you leave the universal one (in app assistant) and put up a custom one in the one scene you need to modify yet?
Reply
Member: SirataXero
at: 03:57 PM 11/19/2009
Bah! I don't have my reference codes with me, but when you instantiate the menu, did you try "this.sceneController..." I think MAYBE that sounds familiar... Either that, or I'm pulling random stuff out of the air now. >.<
Reply
Member: Laxidasical
at: 04:05 PM 11/19/2009
It was the exact opposite. It was working fine in the stage assistant before. I had to add an app assistant because my app requires multiple stages. Then it broke. All of the examples I've come across have their menus setup (attributes, models, handleCommand) in the app assistant if they have one.

I REALLY miss having a well documented easy to search with great code examples website as a resource (like php.net). ;-/

Anyway, no luck moving it back to the stage assistant, and I think I understand why. The handleCommand function has to be in the appController since commands could be coming from multiple stages. Not sure it that is 100% correct, but it makes logical sense to me.

I'm gonna work on something different for an hour or two and come back to this...any other suggestions would be great though!
Reply
Developer: egaudet
at: 04:43 PM 11/19/2009
unless you declared var menuModel, it looks like you want to be passing MoJack.menuModel and MoJack.menuAttributes to the setupWidget() call.
Reply
Member: Laxidasical
at: 05:18 PM 11/19/2009
Originally Posted by emoney_33:
unless you declared var menuModel, it looks like you want to be passing MoJack.menuModel and MoJack.menuAttributes to the setupWidget() call.
They are declared in app-assistant.js:

In setup function...
[CODE]
MoJack = {}; // CUSTOM NAMESPACE

// ... MORE CODE THAT SETS NAMESPACE VARIABLES ...
[/CODE]

In handleLaunch function (under section that handles stage launch)...
[CODE]MoJack.menuAttributes = {omitDefaultItems: true};

MoJack.menuModel =
{
visible: true,
items:
[
Mojo.Menu.editItem,
{label: 'About MoJack...', command: 'do-aboutMoJack'}
]
};[/CODE]

I've already checked to make sure that I can pull data from MoJack.menuAttributes and MoJack.menuModel in my scenes via a popup that displays their data. For good measure, I moved them from the app assistant to the scene directly before I instantiated the model as a test...still didn't work. :-(
Reply
Developer: egaudet
at: 05:27 PM 11/19/2009
Originally Posted by Laxidasical:
They are declared in app-assistant.js:

In setup function...
[CODE]
MoJack = {}; // CUSTOM NAMESPACE

// ... MORE CODE THAT SETS NAMESPACE VARIABLES ...
[/CODE]

In handleLaunch function (under section that handles stage launch)...
[CODE]MoJack.menuAttributes = {omitDefaultItems: true};

MoJack.menuModel =
{
visible: true,
items:
[
Mojo.Menu.editItem,
{label: 'About MoJack...', command: 'do-aboutMoJack'}
]
};[/CODE]

I've already checked to make sure that I can pull data from MoJack.menuAttributes and MoJack.menuModel in my scenes via a popup that displays their data. For good measure, I moved them from the app assistant to the scene directly before I instantiated the model as a test...still didn't work. :-(

I was speaking about the this.controller.setupWidget(). In your first post you have this.controller.setupWidget(..., menuModel, ...) rather than (..., MoJack.menuModel, ...)
Reply
Developer: egaudet
at: 05:29 PM 11/19/2009
Also I believe you should be doing

var MoJack = {}
Reply
Member: Laxidasical
at: 05:59 PM 11/19/2009
I was using that as an example for a general instantiation question. I see how it can be confusing though, so I changed it!

I don't believe using var would matter. As a matter of fact, on pages 46/47 of the O'Reilly book the author uses the following in his stage controller...

[CODE]// News namespace
News = {};[/CODE]

He later did the same thing when he moved the stage controller code to the app controller. However, I tried your suggestion anyway! *grin* No such luck...
Reply
Member: Laxidasical
at: 06:01 PM 11/19/2009
I forgot to mention...
Using var for the namespace actually locked my app up when I tried to launch it, so it's probably something that shouldn't be done at all (at least for global namespaces).
Reply
1 2 
webOS Nation Forums > webOS apps and software > webOS development > Application Menu w/AppAssistant?