logo

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.

Comments

    • avatar
    • Richard Shergold
    • Thu 6 Dec 2007 05:30 AM

    Excellent Jake - really nice. Thanks for that.

    • avatar
    • benoit
    • Thu 6 Dec 2007 09:14 AM

    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.

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

    • avatar
    • 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 :)

  2. 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...

    • avatar
    • 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

    • avatar
    • 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?

  3. 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!

  4. 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).

    • avatar
    • 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"

    • avatar
    • Kris
    • Thu 2 Oct 2008 12:11 PM

    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!!

    • avatar
    • Jake Howlett
    • Thu 2 Oct 2008 12:22 PM

    "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?

    • avatar
    • christain
    • Mon 30 Mar 2009 11:43 AM

    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 :(

    • avatar
    • Suchitra Swain
    • Thu 29 Sep 2011 04:17 AM

    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 "."

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Thu 6 Dec 2007

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content