jQuery.telligent.evolution.ui.components.rate
UI Component which handles presentation of rating behavior for content. Transforms the output from $core_v2_ui.Rate(), which is a <span class="ui-rate"></span> stub. The default implementation uses the evolutionStarRating plugin. Overrides can be provided at the theme level to present ratings differently.
Options
Data made available to instances of the component:
contenttypeid: (string) Content Type Id Guidcontentid: (string) Content Id Guidratingtypeid: (string) Type Id Guidinitialvalue: (number) Current valueinitialcount: (number) Requested max count to allow
Example
A barebones UI component override which would result in rendering a read-only message of 'Current Rating: X' for a given call to $core_v2_ui.Rate().
$.telligent.evolution.ui.components.rate = {
    setup: function() {
    },
    add: function(elm, options) {
        $(elm).html('Current Rating: ' + options.initialvalue * options.initialcount);
        console.log('ContentId: ' + options.contentid);
        console.log('ContentTypeId: ' + options.contenttypeid);
        console.log('TypeId: ' + options.ratingtypeid);
        console.log('Value: ' + options.initialvalue);
        console.log('Count: ' + options.initialcount);
    }
}
Default Implementation
For reference purposes or as the basis for an override:
$.telligent.evolution.ui.components.rate = {
    setup: function() {
    },
    add: function(elm, options) {
        var settings = $.extend({}, {
            isReadOnly: (options.readonly === 'true'),
            value: parseFloat(options.initialvalue),
            ratingCount: parseFloat(options.initialcount)
        });
        settings.value = settings.value * $.fn.evolutionStarRating.defaults.maxRating;
        settings.onRate = function(value) {
            if (!options.contentid || !options.contenttypeid) {
                return;
            }
            value = value / $.fn.evolutionStarRating.defaults.maxRating;
            var data = {
                ContentId: options.contentid,
                ContentTypeId: options.contenttypeid,
                Value: value
            };
            if (options.ratingtypeid) {
                data.TypeId = options.ratingtypeid;
            }
            $.telligent.evolution.post({
                url: $.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/ratings.json',
                data: data,
                success: function(response) {
                    var data = {
                        ContentId: options.contentid
                    };
                    if (options.ratingtypeid) {
                        data.TypeId = options.ratingtypeid;
                    }
                    $.telligent.evolution.get({
                        url: $.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/rateditem.json',
                        data: data,
                        success: function(response) {
                            if (response && response.RatedItem && response.RatedItem.AverageValue) {
                                $(elm).evolutionStarRating('option', {
                                    value: response.RatedItem.AverageValue * $.fn.evolutionStarRating.defaults.maxRating,
                                    ratingCount: response.RatedItem.Count
                                });
                            } else {
                                $(elm).evolutionStarRating('option', {
                                    value: 0,
                                    ratingCount: 0
                                });
                            }
                        }
                    });
                }
            });
        };
        if (settings.ratingCount == 0 && settings.isReadOnly) {
            return;
        }
        $(elm).evolutionStarRating(settings);
    }
};