jQuery.telligent.evolution.ui.components.vote
UI Component which handles presentation of idea vote behavior for content. Transforms the output from $telligentIdeas_v1_ideas.UpDownVoteUI(), which is a <span class="ui-vote"></span> stub. The default implementation uses the evolutionVote plugin. Overrides can be provided at the theme level to present idea votes differently.
Options
Data made available to instances of the component:
- isReadOnly: (boolean) Is the idea in ReadOnly mode, ReadOnly mode would prevent new votes from being added.
- yesVotes: (integer) The current count of up votes for the idea
- noVotes: (integer) The current count of down votes for the idea
- voteCount: (integer) The current total vote count for the idea
- score: (integer) The current score of the idea
- allowMultipleVotes: (boolean) Does this idea allow for multiple votes per user
- userVote: (integer) Number of votes the accessing user has used on this idea
- canUserUpVote: (boolean) Does accessing user have permission to vote up this idea
- canUserDownVote: (boolean) Does accessing user have permission to vote down this idea
- canViewVotes: (boolean) Does accessing user have permission to view votes on this idea
- isUserRegistered: (boolean) Is the accessing user authenicated on the site
- isUserGroupMember: (boolean) Is the accessing user a member of the group the idea belongs to
- loginUrl: (string) Login Url to use for unaunthenicated users
- voteUrl: (string) Url to for vote callbacks
Example
A barebones UI component override which would result in rendering a read-only message of 'Idea Score: {score}' for a given call to $telligentIdeas_v1_ideas.UpDownVoteUI().
$.telligent.evolution.ui.components.vote = { setup: function() { }, add: function(elm, options) { $(elm).html('Idea Score: ' + options.score);
        console.log('ReadOnly? ' + options.isReadOnly);
        console.log('YesVotes: ' + options.yesVotes);
        console.log('NoVotes: ' + options.noVotes);
        console.log('Vote Count: ' + options.voteCount);
        console.log('Score: ' + options.score);
        console.log('Allow Multiple Votes?: ' + options.allowMultipleVotes);
        console.log('Current User Vote: ' + options.userVote);
        console.log('Up Vote Permission? ' + options.canUserUpVote);
        console.log('Down Vote Permission? ' + options.canUserDownVote);
        console.log('View Votes Permission? ' + options.canViewVotes);
        console.log('User Registered? ' + options.isUserRegistered);
        console.log('Group Member? ' + options.isUserGroupMember);
        console.log('Login Url: ' + options.loginUrl);
        console.log('Vote Url: ' + options.voteUrl);
    }
}
Default Implementation
$.telligent.evolution.ui.components.vote = { setup: function () {
},
add: function (elm, options) {
    var settings = $.extend({}, {
        isReadOnly: (options.readonly === 'true'),
        yesVotes: parseInt(options.initialyesvotes),
        noVotes: parseInt(options.initialnovotes),
        voteCount: parseInt(options.initialvotes),
        score: parseInt(options.initialscore),
        allowMultipleVotes: (options.allowmultiplevotes === 'true'),
        userVote: options.initialuservotetotal,
        canUserUpVote: (options.canuserupvote === 'true'),
        canUserDownVote: (options.canuserdownvote === 'true'),
        canViewVotes: (options.canviewvotes === 'true'),
        isUserRegistered: (options.isuserregistered === 'true'),
        isUserGroupMember: (options.isusergroupmember === 'true'),
        loginUrl: options.loginurl,
        voteUrl: options.voteurl
    });
    $.telligent.evolution.messaging.subscribe('ideaVote.created', function (data) {
        handleVoteMessage(options, elm, data);
    });
    $.telligent.evolution.messaging.subscribe('ideaVote.deleted', function (data) {
        handleVoteMessage(options, elm, data);
    });
    settings.onVote = function (value, totalVotes) {
        if (!options.contentid) {
            return;
        }
        $.telligent.evolution.post({
            url: $.telligent.evolution.site.getBaseUrl() + 'api.ashx/v3/ideas/vote.json',
            data: {
                IdeaId: options.contentid,
                Value: totalVotes
            },
            success: function (response) {
                if (response && response.Vote && response.Vote.Idea) {
                    $(elm).evolutionUpDownVoting('option', {
                        yesVotes: response.Vote.Idea.YesVotes,
                        noVotes: response.Vote.Idea.NoVotes,
                        voteCount: response.Vote.Idea.TotalVotes,
                        score: response.Vote.Idea.Score,
                        userVote: response.Vote.TotalVotes
                    });
                } else {
                    $(elm).evolutionUpDownVoting('option', {
                        yesVotes: 0,
                        noVotes: 0,
                        voteCount: 0,
                        score: 0,
                        userVote: null
                    });
                }
            }
        });
    };
    settings.onDeleteVote = function () {
        if (!options.contentid) {
            return;
        }
        $.telligent.evolution.del({
            url: $.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/ideas/vote.json',
            data: {
                IdeaId: options.contentid
            },
            success: function (response) {
                $.telligent.evolution.get({
                    url: $.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/ideas/idea.json',
                    data: {
                        Id: options.contentid
                    },
                    success: function (response) {
                        if (response && response.Idea) {
                            $(elm).evolutionUpDownVoting('option', {
                                yesVotes: response.Idea.YesVotes,
                                noVotes: response.Idea.NoVotes,
                                voteCount: response.Idea.TotalVotes,
                                score: response.Idea.Score,
                                userVote: 0
                            });
                        } else {
                            $(elm).evolutionUpDownVoting('option', {
                                yesVotes: 0,
                                noVotes: 0,
                                voteCount: 0,
                                score: 0,
                                userVote: null
                            });
                        }
                    }
                });
            }
        });
    };
    if (settings.voteCount == 0 && settings.isReadOnly) {
        return;
    }
    $(elm).evolutionUpDownVoting(settings);
}
};
 
				