| YoYo! India Application Development |
We have found that Firefox verions 2.0 and Firebug version 1.3 is NOT a good combination. Firefox constantly crashed when trying to debug code. Currently we are all using Firefox 2 and FireBug 1.05 with good success.
C:\development\yyi, you have the following directory tree:
|
|
ref.html file is a wrapper html page that loads the example yoyo.
ref.html file with a text editor. (Preferably with a text error that
supports syntax validation and code completion. Look here
here for some options.)
When designing new Yoyos you need to follow the template set forth in the reference files:
Now open up the reference.html file with your text editor. In this html file you will see three sections:
dojo.require will ensure that resources are downloaded only once for the application -
thus limiting bandwidth usage and increasing start-up time. g_addOnLoad function is a global YYI function defined in the script/Util.js file.
It will ensure that the code in this section will only be executed after the thrid section has
finished loading.
This section defines and positions visual components used by the Yoyo. Many of the components are
static html. However, some components will be dynamic. The dynamic components will be modified in run-time
by the controller depending on the data it receives from server and on the actions of the user. The controller
therefore needs a handle to each dynamic component. We use the id of the visual component to find
a handle to it.
The controller will be able to install event handlers to user interaction with visual components (like running a specific function when a button is clicked). The controller will be able to populate a visual component depending on data it retrieves from the server (like populating a list with weather entries).
You will notice the _uuid_ prefix that we use in the id attribute of the elements.
The reason for this is that we might want to create more than one instance of a specific Yoyo in our application.
And to be able to distinguise between elements on different Yoyos, the DOM ids for the components in the Yoyo must be different.
The g_createContentPane method used in the wrapper page will replace the occurences of _uuid_ with a unique number
after it has loaded the html file (but before instantiating the controller).
CSS styles are read from the YYI API app.css file and from the YoYo specific reference.css file.
If your YoYo needs special image files it can be included inside the yoyo/images directory.
Ok and Cancel buttons have predefined icons that can be used by your YoYo and sourced from the
dojo/images directory.
The YoYo controller is a Javascript 'class' that must define at least the following functions
The setView(view) function is a setter that received a view object. The view object instance
(is a javascript object) contains a name-value pair. Each name identifies a graphical component and its
value is a handle to the graphical component.
The afterPropertiesSet() function is called after all the necessary setup functions have been
called on the controller. Its first task is to ensure that all the necessary parameters were properly configured.
If everything checks out ok, it calls the remaining two functions.
The _installCallbacks() function is responsible for assigning callback funcitons (event handlers)
to for events generated by graphical components. For example when the add button is clicked we want the
_addCity() function to be called on this contoller instance. We use the dojo.hitch
function to scope the callback.
The _populateView() function must initiate all the server calls needed to populate the YoYo's view.
If you look at the function in the reference.js file you will notice that it firstly, resets some
of the view component's states and then it makes a server call. More about server calls next.
It is important to make your server calls in the same way as we discuss here. Lets take a look at some code:
Firstly, take note that we wrap the server call in a try catch block. This allows us to simulate a response from the server. This gives you the ability to develop YoYo's without having to install a server at all! Once you are done with the YoYo, anyone can reference the simulated response and implement the necessary server code for the YoYo.
Secondly, lets look at an actual server call:
The ReferenceServerInterface class does not exist at development time but once you are done with the
YoYo development this class will be generated.
The addCity function on the server is called.
All but the last parameter is passed to the addCity function. Something that is not quite
obvious is the fact that we are not telling the server which user is making the call. So you may rightly wonder
how the server knows who is adding a city to his weather YoYo... The answer is that the browser session
will be associated to a specific user on the server - therefore the server knows who is making the call
by looking at the browser session id which is done when the user logs in.
The first parameter selectedCity is the city that the user selected in the combo box.
The very last parameter of the server call must be a callback function.
This is the function that will be called when the server call returns successfully.
In the example above, the _populateView function will be called.
To illustrate what happens when a function returns from a server call, lets look at another example:
You can see that this server function call will retrieve the weather information for the calling user
from the server. When the call returns it will call the _populateWeatherData function with
the weather information that it retreived. Very important is the mirrored function
call in the catch block!
In the catch block you must generate dummy weather information - in exactly the same format as the
server would return the weather information. With this generated data you must call the same callback
function. This allows you to run your YoYo without any server or server software. Please dont try to
simulate the exact server functionality, for example, when you click addCity()
you would expect the server to actually add the city to the users list of cities. But for simulation
purposes we dont want to mirror that functionality in the client side code because we dont want to
polute the client side code with unnecessary code.
yoyo directory and mail it to yyi.subs@yoyoindia.com
Place the following text (exactly) in the email subject: YoYo Submissions