Tags:
poll1Add my vote for this tag rating1Add my vote for this tag create new tag
, view all tags

RatingContrib

Rating widget for TWiki forms using "line of stars" style input field

Introduction

This module adds a line-of-stars rating bar to TWiki forms and TWiki applications.

Using the color picker in TWikiForms

This package adds a rating type to TWikiForms. The result of the rating is captured as an integer, and displayed as a line of stars. For example,

To use it in a TWiki form, use the type rating, with the optional modified +small for small stars:

Type Description Size Value
rating starrating Line-of-stars rating bar. Number of stars for rating Initial value
rating+small starrating-small Like rating, but with small stars.    

Example form definition:

| *Name*     | *Type*       | *Size* | *Values* |
| Supplier   | text         | 40     |          |
| Quality    | rating+small | 10     | 5        |
| Order Date | date         |        |          |
A topic with this form looks like this when in edit mode:

Using the Contrib in a Plugin

A typical application of this widget is its use to capture a rating under the control of a plugin, such as the the TWiki:Plugins.VotePlugin. It is straightforward to use in this role. The API to the contrib is:

TWiki::Contrib::RatingContrib::renderRating($name, $size, $small, $value, $input_attrs) -> $html

where

  • $name is the name you want to give to the input element that will get the rating value
  • $size is the total width of the rating bar, typically 5 or 10
  • $small is a boolean; if true, use small (10px) stars in place of the default (25px) stars
  • $value is the current value of the rating. This may be a floating-point value, but should be in the range 0..$size
  • $input_attrs is a hash that contains additional attributes to be assigned to the input element used to capture the rating value. Typically the only attribute callers will need to use is onchange, which should be set to a callback that will be invoked when the value in the input is changed. If you pass undef for this parameter, then the line of stars will be "read only".
The contrib will automatically look after the CSS and Javascript it needs to load to work.

For example, let's say we want to generate a conventional form that contains a line of stars prompt. We want the value of the rating bar to be submitted along with everything else in the form.

my $html =
   CGI::form({action="some url", method=>"post"},
       TWiki::Contrib::RatingContrib::renderRating('rating', 5, 0, 0, {})
      .CGI::submit("OK"));

Say instead that we want to generate an alert when a line of stars has its value changed:

$html = TWiki::Contrib::RatingContrib::renderRating('rating', 5, 0, 0,
        {onchange=>'javascript: alert("Rated")'})
Of course, when you use the onchange event, you don't need a form. This model is good if you want (for example) to update values using a REST handler.

Installation Instructions

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server where TWiki is running.

Like many other TWiki extensions, this module is shipped with a fully automatic installer script written using the BuildContrib.

  • If you have TWiki 4.2 or later, you can install from the configure interface (Go to Plugins->Find More Extensions)
  • If you have any problems, then you can still install manually from the command-line:
    1. Download one of the .zip or .tgz archives
    2. Unpack the archive in the root directory of your TWiki installation.
    3. Run the installer script ( perl <module>_installer )
    4. Run configure and enable the module, if it is a plugin.
    5. Repeat for any missing dependencies.
  • If you are still having problems, then instead of running the installer script:
    1. Make sure that the file permissions allow the webserver user to access all files.
    2. Check in any installed files that have existing ,v files in your existing install (take care not to lock the files when you check in)
    3. Manually edit LocalSite.cfg to set any configuration variables.

Contrib Info

Contrib Author(s): Crawford Currie http://c-dot.co.uk
Copyright: © 2007 C-Dot Consultants;
© 2007-2010 TWiki:TWiki.TWikiContributor
License: GPL (GNU General Public License)
Contrib Version: 19914 (2010-12-03)
Change History:  
2010-12-03: TWikibug:Item6609: Add screenshots -- TWiki:Main.PeterThoeny
2010-11-27: TWikibug:Item6609: In TWikiForms type table, automatically list the rating form field type defined in this contrib -- TWiki:Main.PeterThoeny
2010-07-27: TWikibug:Item6530 - doc fixes
2006-07-27: First version
Dependencies: None
Contrib Home: http://twiki.org/cgi-bin/view/Plugins/RatingContrib
Feedback: http://twiki.org/cgi-bin/view/Plugins/RatingContribDev
Appraisal: http://twiki.org/cgi-bin/view/Plugins/RatingContribAppraisal

Related Topics: TWikiContribs, DeveloperDocumentationCategory, AdminDocumentationCategory, TWikiPreferences

Topic attachments
I Attachment Action Size Date Who Comment
Unknown file formatmd5 RatingContrib.md5 manage 0.2 K 2010-12-03 - 09:08 PeterThoeny  
Compressed Zip archivetgz RatingContrib.tgz manage 36.0 K 2010-12-03 - 09:08 PeterThoeny  
Compressed Zip archivezip RatingContrib.zip manage 40.7 K 2010-12-03 - 09:08 PeterThoeny  
Unknown file formatEXT RatingContrib_installer manage 4.2 K 2010-12-03 - 09:08 PeterThoeny  
Topic revision: r13 - 2011-08-23 - PeterThoeny
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by PerlIdeas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.