Skip Navigation
Details
Author: Jake Howlett
Date: Thu 6 Dec 2007

Permalink

Comments / Add

« A Great Little Star Rating Sytem | Blogs | Happy Birthday Son »

Accessible AJAX Document Rating - Demo and Download

As promised here's the demo and download of the document rating database I mentioned earlier in the week.

Have a play and let me know what you think. Try using it with CSS and JavaScript disabled. It still works! Thanks to its use of "Accessible Ajax" — whereby the link itself and the Ajax call both point to the same place.

Note that the download differs from the demo version in that it records the username of the voter, whereas the demo records the IP address - for obvious reasons.

If you look at the code you'll see that it records a list of who has voted in a field on the document itself. This was an educated choice I made based on circumstances. The client I was working for have between two and three hundred employees. In the unlikely event that all of them voted on one document it could still cope. If you don't know how many people might vote then you might want to store votes as separate documents — while keeping the overall score in the actual document — and change the agent to look-up to a view instead. Horses for courses, as always.

Comments

Richard Shergold (Thu 6 Dec 2007 05:30 AM)

Excellent Jake - really nice. Thanks for that.

benoit (Thu 6 Dec 2007 09:14 AM) website / e-mail

Hi,

wonderfull thing.

just one thing, this does not really work under opera 9.22.

When clicking a star, the ajax progress image appears, the text "casting your vote" apprears, and nothing else happens.

i'll try with ie and ff later.

Bruce Elgort (Thu 6 Dec 2007 10:05 AM) website / e-mail

Very nice Jake. Thank you for sharing it with us.

Ben (Thu 6 Dec 2007 06:00 PM)

Thanks very much. An internal client asked for exactly this functionality to be added to DominoWiki, now I can pull it out of the 'when I get time to work it all out' pile :)

Patrick Kwinten (Fri 7 Dec 2007 03:50 AM) website / e-mail

Thank you for sharing. it looks really nice.

One question I would have (read: my customer would have): Why can I not rate directly from the view? This would save me 1 extra click...

Jake Howlett (Fri 7 Dec 2007 04:54 AM)

"Why can I not rate directly from the view?"

No reason. But, then again, the main reason (and the reason I left it off of here) is that views are not user-sensitive. The view would have to assume you hadn't voted and then return an "error" if you had.

Alternatively you could use WQO to create your own "view" which could recognise whether the current user had voted or not. This is what I'd done in the original, but left it off the demo/download for the sake of not upsetting the Notes puritans.

Other reason = you can't rate something at the view level if you've not read it yet ;o)

Jake

Robert (Fri 8 Feb 2008 09:53 AM)

I have downloaded the database and put it on a server. I rate a document and see the text "Casting your vote..." but then nothing happens. What is wrong?

Jan Schulz (Sun 24 Feb 2008 02:29 PM) e-mail

Fun: I just debuged a problem with the code for about an afternoon :-/ so I spare anybody lese the fun and share:

If you domino locale is something, which spits out the decimal seperator as ',', the ajax won't work. Right now I'm fixing it with a simple replace... I wonder whether I should try umlauts in message...

Print |{success: |+Lcase(Cstr(success))+|, rating: |+ReplaceSubString(Format(article.Rating(0), "Fixed"), ",",".") +|, votes: |+Cstr(previous_ratings+1)+|, message: "|+message+|"}|

Where was the JSON writer class in LS?

Anyway: this was a great lesson in building AJAX agents (and I got a rating solution from it :-) ), so thanks!

Jan Schulz (Sun 24 Feb 2008 06:31 PM) e-mail

There are other places, where you need to replace ',' by '.', otherwise numbers like 37,6 will have strange effects, like displaying full rating-stars in the view or no at all in the documents. The affected elements: subform rating, View Documents, 4th column. I also had to change some elements as I tried to enable ratings based on loged in user (item.AddToTextList only works on textlist, not names, so the field needed to be Text and in several hidewhen formulas i needed to add @names around the RatedFrom).

Alexander Eremin (Wed 19 Mar 2008 01:34 AM)

for none english word in request, inside RateArticle agent must add this line:

Print "content-type: text/plain; charset=utf-8"

instead of:

Print "content-type: text/plain"

Add your response here:

Name *:
E-mail:
Protected from spambots!
Website:
rel="nofollow"
Remember My Details
Comment *:
HTML is not allowed!

Note: This blog entry is more than two weeks old so your comment, as an anti-spam measure, will be sent for approval.