Accessible AJAX Document Rating - Demo and Download
As promised here's the demo and download (updated: please download the latest version of DEXT from tha sandox instead) 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.
Excellent Jake - really nice. Thanks for that.
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.
Very nice Jake. Thank you for sharing it with us.
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 :)
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...
"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
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?
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!
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).
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"
I added the code and also see the text "Casting your vote..." but then nothing happens. I tried Jan's fix but the script would not save. Any ideas? Thanks!!
"Nothing happens"
Help me help you Kris. I need more clues. Have you looked at the server console? Are there any JavaScript errors? Are there are any documents saved in the database?
i have the same problem.
Document is saved and i see "Casting your vote...".
I can't see any error at the server console!
Demo version is ok but download :(
Hi,
I also faced the "Casting your vote..." problem. As suggested by Jan, replace the "," from the return value of Format(article.Rating(0), "Fixed"). You need to replace the value "," with "."