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 ideanoVotes
: (integer) The current count of down votes for the ideavoteCount
: (integer) The current total vote count for the ideascore
: (integer) The current score of the ideaallowMultipleVotes
: (boolean) Does this idea allow for multiple votes per useruserVote
: (integer) Number of votes the accessing user has used on this ideacanUserUpVote
: (boolean) Does accessing user have permission to vote up this ideacanUserDownVote
: (boolean) Does accessing user have permission to vote down this ideacanViewVotes
: (boolean) Does accessing user have permission to view votes on this ideaisUserRegistered
: (boolean) Is the accessing user authenicated on the siteisUserGroupMember
: (boolean) Is the accessing user a member of the group the idea belongs tologinUrl
: (string) Login Url to use for unaunthenicated usersvoteUrl
: (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);
}
};