SI539 Assignment 9 - JavaScript, AJAX, and jQuery
In this assignment, you will add an AJAX chat to the private area of
your application as described in the book in Chapters 8 and 9.
You would be well-served to first build a non-AJAX chat based on ae-11-chat
as described in Chapter 8 and then adapt your program to switch to
using AJAX (ae-12-chat) as described in Chapter 9.
Make the "Chat" link appear in the public area after the user logs in
and have the chat program running at "/chat" (like the book).
In order to help you complete the assignment, the following code
walkthroughs have been provided:
You should watch them in order as most of the work is done in
ae-11-chat and then ae-12-ajax makes changes to
implement Ajax.
Since most of this assignment is pulling code from these two sample
programs into your program, you would be well-served to spend the time
to watch these screencasts before you start work.
Tasks to Do
This is a number of the tasks you will need to do - it may not be all of the tasks
but it is a good check list.
Building a non-Ajax chat
-
If you have not already done so, download a copy of the
sample code from the book at
http://www.appenginelearn.com/static/sample-appengine-apps.zip
since you will be pulling code from the sample programs.
-
Copy the chatscreen.htm from ae-11-chat into your templates folder
-
Change the Login and Logout handlers to put the userkey into session
in addition to the username (see ae-11-chat for an example)
-
Add the ChatMessage model to your index.py from ae-11-chat
-
Copy the ae-11-chat ChatHandler into your index.py and add appropriate routing code
to route "/chat" to the ChatHandler
-
Add a link in your _base.htm file to link to /chat if the user is logged in
-
Make two accounts in the developer console and see if you an get them
logged in using two browsers and chatting. Rememember that since this is
not Ajax, you will have to press refresh to see new messages typed in by the
other user.
Adding Ajax to your chat
-
Make a directory under static called "js" and copy the file static/js/jquery-1.2.6.min.js
from ae-12-ajax into your new static/js folder.
-
Look at _base.htm file in ae-12-ajax and find the code in the head section that
includes the JQuery code and put it in your _base.htm file.
-
Copy the chatscreen.htm and messagelist.htm from
ae-12-ajax into your templates folder.
-
Copy the ae-12-ajax ChatHandler and MessagesHandler into your index.py
and add routing for the /messages url to the MessagesHandler.
You are replacing the ChatHandler with the new Ajax ChatHandler.
If you come up with any missing steps - send a note to the instructor
to update this list.
Some Challenges
If you would like a bit more challenging tasks, you can optionally
add the following to the above.
-
Have your chat and messages code respond from the url /private/chat
and /private/messages respectively
-
Add a spinning gif image instead of "Loading..." while the messages
are being loaded.
-
There is a bug in the MessagesHandler in that it will show messages
to non-logged in users. You can go to /messages without being logged
in to see the behavior. Find and fix the bug.
-
While you are on the chat screen, use "view source" to grab a copy of the
HTML and see if it still validates using the HTML validator.
There is no etra credit for this - it is just if you want a
bit more challenge.
Hand In
Please hand in the following:
- A screen shot with two different browsers (i.e. Firefox and Chrome) running,
with each browser logged in as a different user. There should be several
messages from each user
displayed.
-
A screen shot showing the "/messages" fragment, properly displayed.
-
A screenshot of your log showing the many retrievals of the "/messages" URL.
-
And a ZIP file of your entire source code.
Note: Your screen shots should not be clones of the screen
shots from the book. The chat functionality
needs to be in the private area of your site be in your site.
www.appenginelearn.com