<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>rate UI Component</title><link>https://community.telligent.com/community/11/w/api-documentation/67188/rate-ui-component</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>rate UI Component</title><link>https://community.telligent.com/community/11/w/api-documentation/67188/rate-ui-component</link><pubDate>Tue, 19 Nov 2019 20:28:37 GMT</pubDate><guid isPermaLink="false">88838e6b-cb1e-4998-92f3-9f37f10e8505</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/api-documentation/67188/rate-ui-component#comments</comments><description>Current Revision posted to API Documentation by Ben Tiedt on 11/19/2019 20:28:37&lt;br /&gt;
&lt;hr class="generated-documentation-start" style="border-width:0;" /&gt;&lt;h3&gt;&lt;a id="jQuery_telligent_evolution_ui_components_rate" name="jQuery_telligent_evolution_ui_components_rate"&gt;&lt;/a&gt;jQuery.telligent.evolution.ui.components.rate&lt;/h3&gt;
&lt;p&gt;[[ui JavaScript API Module|UI Component]] which handles presentation of rating behavior for content. Transforms the output from &lt;code&gt;$core_v2_ui.Rate()&lt;/code&gt;, which is a &lt;code&gt;&amp;lt;span class=&amp;quot;ui-rate&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;/code&gt; stub. The default implementation uses the [[evolutionStarRating jQuery Plugin|evolutionStarRating plugin]]. [[ui JavaScript API Module|Overrides can be provided]] at the theme level to present ratings differently.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Options" name="Options"&gt;&lt;/a&gt;Options&lt;/h3&gt;
&lt;p&gt;Data made available to instances of the component:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;contenttypeid&lt;/code&gt;: (string) Content Type Id Guid&lt;/li&gt;
&lt;li&gt;&lt;code&gt;contentid&lt;/code&gt;: (string) Content Id Guid&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ratingtypeid&lt;/code&gt;: (string) Type Id Guid&lt;/li&gt;
&lt;li&gt;&lt;code&gt;initialvalue&lt;/code&gt;: (number) Current value&lt;/li&gt;
&lt;li&gt;&lt;code&gt;initialcount&lt;/code&gt;: (number) Requested max count to allow&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;&lt;a id="Example" name="Example"&gt;&lt;/a&gt;Example&lt;/h3&gt;
&lt;p&gt;A barebones UI component override which would result in rendering a read-only message of &amp;#39;Current Rating: X&amp;#39; for a given call to &lt;code&gt;$core_v2_ui.Rate()&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$.telligent.evolution.ui.components.rate = {
    setup: function() {
    },
    add: function(elm, options) {
        $(elm).html(&amp;#39;Current Rating: &amp;#39; + options.initialvalue * options.initialcount);

        console.log(&amp;#39;ContentId: &amp;#39; + options.contentid);
        console.log(&amp;#39;ContentTypeId: &amp;#39; + options.contenttypeid);
        console.log(&amp;#39;TypeId: &amp;#39; + options.ratingtypeid);
        console.log(&amp;#39;Value: &amp;#39; + options.initialvalue);
        console.log(&amp;#39;Count: &amp;#39; + options.initialcount);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;&lt;a id="Default_Implementation" name="Default_Implementation"&gt;&lt;/a&gt;Default Implementation&lt;/h3&gt;
&lt;p&gt;For reference purposes or as the basis for an override:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$.telligent.evolution.ui.components.rate = {
    setup: function() {

    },
    add: function(elm, options) {
        var settings = $.extend({}, {
            isReadOnly: (options.readonly === &amp;#39;true&amp;#39;),
            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() + &amp;#39;api.ashx/v2/ratings.json&amp;#39;,
                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() + &amp;#39;api.ashx/v2/rateditem.json&amp;#39;,
                        data: data,
                        success: function(response) {
                            if (response &amp;amp;&amp;amp; response.RatedItem &amp;amp;&amp;amp; response.RatedItem.AverageValue) {
                                $(elm).evolutionStarRating(&amp;#39;option&amp;#39;, {
                                    value: response.RatedItem.AverageValue * $.fn.evolutionStarRating.defaults.maxRating,
                                    ratingCount: response.RatedItem.Count
                                });
                            } else {
                                $(elm).evolutionStarRating(&amp;#39;option&amp;#39;, {
                                    value: 0,
                                    ratingCount: 0
                                });
                            }
                        }
                    });
                }
            });
        };

        if (settings.ratingCount == 0 &amp;amp;&amp;amp; settings.isReadOnly) {
            return;
        }

        $(elm).evolutionStarRating(settings);
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;hr class="generated-documentation-end" style="border-width:0;" /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>