In this tutorial we are going to cover using the Depot as a data source for a list. We will be expanding on the code written in the previous parts of this tutorial listed below.
Part 1: Mojo Lists
Part 2: Mojo Lists: Using a Cookie as a Data Source
Part 3: Mojo Lists: Restructuring our Code
If you were able to follow along with using the cookie as a data source this is going to be relatively easy for you to integrate into the existing code.
In Part 2 of this series we created the ability to use a cookie for a lists data source. In this part we are going to cleanup our code a bit and try to restructure things so that it is easier to expand on our set of code.
After looking at the code I saw that we created the WBCookie model object that was not very abstract. We wish to keep things somewhat abstract so that the application is not concerned too much about where the data is coming from. We are going to be creating a few files that will be in our lib/ directory and I will explain why we are using them and what they do as we continue through the tutorial.
The first thing I want you to do is open up your sources.json file and add 3 lines at the top. We will want to include the files that we will be creating so that Mojo will know where to find them. Open your file and make it look like the following. Note that I only added the first three lines to this file.
Just a friendly reminder that we are holding a meeting tonight at the Boston Public Library. You can get directions from this post and read more about the meeting on this post. We encourage you to bring your laptops and your enthusiasm. The meeting will start at 7PM and go until 9PM. There may be a social hour after the meeting at a local pub as well.
In Part 1 of this tutorial we created the base for our application. It consisted of a static list that was displayed when the application was launched.
At the end of Part 1 you were able to build the application and tap on any of the items which would push another scene. In Part 2 of this tutorial we are going to focus on using a cookie as a data source for our list. We will build a list that will display a list based on a cookie's contents.
When you tap on a list item you will be taken to another scene where you will be able to change the title for the list item and it will be retained in a cookie. I did find an issue with cookies on the emulator and device. There is a known bug that cookies will retain on the emulator and device even after the application is removed. To learn more about this issue and cookies I suggest you read the Working with Cookies tutorial.
We will be continuing with the code that we created in Part 1 so open that application up. We will first be creating a model object that we will use to interact with the Mojo cookie stuff. In your application create the folder /app/lib/ and then create a new file named WBCookie.js and put it in your newly created lib folder. Now you will also have to update your sources.json so that Mojo will know where to find this file. Be sure that your sources.json file looks like the code below.
[
{ "source": "app\/lib\/WBCookie.js" },
{"source": "app\/assistants\/stage-assistant.js"},
{
"source": "app\/assistants\/main-assistant.js",
"scenes": "main"
},
{
"source": "app\/assistants\/cookie-assistant.js",
"scenes": "cookie"
},
{
"source": "app\/assistants\/depot-assistant.js",
"scenes": "depot"
},
{
"source": "app\/assistants\/sqlite-assistant.js",
"scenes": "sqlite"
}
]
At the request of a reader this next tutorial will cover Mojo Lists however it will get quite long so I have decided to break it into smaller parts.
Part 1 (This section) will deal with setting up a static list.
Part 2 will show how to use a cookie as a data source.
Part 3 will be some restructuring of the code
Part 4 will show how to use the depot as a data source.
Part 5 will show how to use an Sqlite database as the source.
Source Code will be posted for download after the series is complete.
On our main scene we are going to show a static list of items. This means that we are going to use an array of elements which will never change over the lifetime of the application. The list item data will be specified by us and not fetched from any data source. The main list will give you options to choose from such as using a Cookie, Depot or Sqlite for the data source. When you tap on one of these options another scene will be displayed that will actually load another list. The data that populates these lists will come from the data source that you specified. This should give you the ability to write your own lists using any data source that you see fit.
The very first thing that you need to do is create a new WebOS application and add a new scene to it called main. Now that we have the main scene created we need to alter our stage-controller.js so that it actually pushes the main-scene on startup. Open the file and make the code look like this.
function StageAssistant() {
}
StageAssistant.prototype.setup = function() {
Mojo.Controller.stageController.pushScene("main");
}
It's not a big secret that gDial pro has been around for a while in the home brew community. What is a bit surprising and actually pleasing is that Palm has allowed it into the App Catalog. I have used the application and like just about everything there is except for the fact that it opens your phones main dialer to actually make the call. I doubt that there is currently any other way for the developer to place the call but I do hope that Palm opens the SDK to allow for this. It would be so nice to be able to just dial your number and have it dial straight in the gDial Pro application.
If you have never used gDial Pro then you need to head over to Google Voice and sign-up for an account. It is still in beta so you will need to wait for the invite from Google. When I registered a month back I only had to wait a few days to be invited but I have heard from others that they had to wait about a week. The only other thing I dislike about the interface is the colors the developer choose to use. It's pretty much all gray-scale, here's to hoping they allow for themes in the future so we can get past the grim look of the user interface as it is by default.
Yesterday my boss was out for the day and while he was out he was trying to be responsive to e-mails that he received. When he would reply to an e-mail it would tell him there was a problem sending the e-mail and put it in his out box.
Today he realized that he did not have his account authentication settings set properly in his phone. He set them all as they should be and went to his out box. He would hit the refresh button and it would continue to give him the error that it was unable to send the emails. This time it started complaining about the password being incorrect. He checked the mail server and used Wire Shark to watch the TCP activity. When his email application on the phone would say that authentication failed there was actually no communication with the mail server.
it seems that if you build up 5-6 messages in your out box you cannot hit refresh to send all of the messages. You have to individually tap on each message in your outbox and hit send in order to get it to sent the message.
Let's hope that Palm fixes this issue in their mail application. While you are at it Palm, can we get a way to delete more than one email message at a time???
I just got finished setting up a mailing list for our group. To subscribe head over to the mailing list page. This list should be used for asking questions related to Palm WebOS Development only.
I want to note that you can join this mailing list even if you are not local to the Boston area. This list was setup to help the community. If you have a question feel free to subscribe to the list and ask all of the other members.
Over the last few days I have been working with the Cookie as a method for storage on the Palm Pre. I looked in the WebOS Book and there was a nice cookie class that could be used. This will not be a complete walk-through like the last tutorials have been. This will show you how to create a cookie object and how to interact with it so that you can store your application preferences. You can store any type of data you would like in a cookie. It does not seem to be like the Depot where you can *only* store objects.
At the time of writing I have found an issue with using cookies so be sure to read the second to last paragraph.
Below is the class that was taken from the WebOS Book which we will be using for our Cookie object.
When we first started the WebOS Boston user group we did not know that Michael Prenez-Isbell had also started to organize a group. We are going to be holding a combined user group meeting on September 28th at the Boston Public Library. The meeting will be held from 7pm - 9pm and will be held in the Mezzanine Conference Room. You can find out more about Michael's meeting by visiting the MeetUp page.
Tim has kindly posted the directions to the Boston Public Library and explains how to find the room.
The speaker at the meeting will be...
ERIC MARTHINSEN of Agile Commerce who happens to be local to the Boston area! Eric and his team created FLIGHTVIEW, an airplane flight status tracker downloadable from the App Catalog! Eric will be giving us an overview of his experience creating the App and getting it into the App Catalog; a demo of FlightView; and a discussion of the challenges facing a JavaScript webpage developer transitioning to webOS and Mojo.
http://www.flightview.com
Here is a Mojo Discussion featuring Eric.