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.
Print This Post
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.
Print This Post
Video of Douglas Crockford's talk at MIT still pending, meanwhile enjoy him here from Google http://hex.io/1i6f plus some follow-along slides.
Print This Post
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.
Print This Post
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"
}
]
Print This Post
Douglas Crockford , author of "Javascript: The Good Parts" from O'Reilly Media - is speaking TODAY (Friday) at MIT at 12:45 in room G449 of the Patil/ Kiva Seminar Room in the Stata center (building closest to Vassar Street.) - this is the same building we met for the Sept 8th meeting. I have his book, and can vouch for it's excellence!
So, if you can get out for ONE HOUR come and listen in!
Cost: none
TIME:Refreshments: 12:45
Talk: 1: 00 PM to 2pm
Print This Post
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");
}
Print This Post
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.
Print This Post
Our very first WebOSBoston meeting was a great success, with 9 persons attending. It was a nice, loosely structured informal meeting that was VERY productive. Thank you ALL who attended, we had a great discussion. After this, Eric Marthinsen of Agile Commerce came and spoke about recent development findings and hurdles and general programming practices. We looked at using the emulator, Ruby, scoping of functions and 'this' within a function, playing audio sounds from within a game, custom style sheet elements, log levels and much more. We were glad to have him come!!
BE SURE to join our mailing list to be notified of upcoming meetings , and in the event of last minute room changes you'll be in the know. Thank you for MIT for donating unused meeting space, and all who helped in planning and signs, etc.
Print This Post
WebOS seminar with Eric M. this afternoon (4:30pm-7pm) new room: Stata (Dreyfoos) building. 32-D451 at MIT.
32 Vassar St Cambridge, MA - go in the funny-looking angles buidling, then 4th floor in elevators.
There's a floorplan of the Building 32's Dreyfoos tower, fourth floor, at
http://www.csail.mit.edu/resources/maps/4D/D451.gif, with 32-D451
highlighted.
Directions to the building are on-line at http://www.csail.mit.edu/node/95
If you unwisely wish to drive to campus (instead of taking the very
convenient subway - the Red Line Kendall Square stop is very very close to
here), parking can usually be found (at meters) on Vassar Street, on Main
Street, on Ames Street, and on Mass Ave.
Print This Post