jQuery.telligent.evolution.ui.components.moderate
UI Component which handles presentation of moderation behavior for content. Transforms the output from $core_v2_ui.Moderate()
, which is a <span class="ui-moderate"></span>
stub. The default implementation uses the evolutionModerate plugin. Overrides can be provided at the theme level to present moderation differently.
Options
Data made available to instances of the component:
contenttypeid
: (string) Content Type Id Guidcontentid
: (string) Content Id Guidinitialstate
: (boolean) Reported state, true when already reported by the accessing usersupportsabuse
: (boolean) Whether this piece of content supports being reported-
configuration
: Object of all other keys and values passed via the options dictionary to$core_v2_ui.Moderate()
, regardless of whether they have been pre-defined-
jQuery.evolutionModerate looks for the following optional configuration:
AdditionalLinks
: Array of objects with keyshref
,text
, andclassName
to present as additional actions alongside moderationAdditionalLinksUrl
: Ajax endpoint which returns a JSON array of objects with keyshref
,text
, andclassName
to present as additional actions alongside moderation, used when the set of links is non-deterministic until neededLinkClassName
: CSS class name to apply to extra links
-
jQuery.evolutionModerate looks for the following optional configuration:
Example
A barebones UI component override which would result in rendering a read-only message of 'You have reported [Content Id]' or 'You have not reported [Content Id]' for a given call to $core_v2_ui.Moderate()
.
$.telligent.evolution.ui.components.moderate = {
setup: function() {
},
add: function(elm, options) {
var message;
if(options.initialstate) {
message = 'You have reported ' + options.contentid;
} else {
message = 'You have not reported ' + options.contentid;
}
$(elm).html(message);
}
}
Default Implementation
For reference purposes or as the basis for an override:
(function($){
var reportAbuse = function(contentId, contentTypeId, complete) {
$.telligent.evolution.post({
url: $.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/abusereports.json',
data: {
ContentId: contentId,
ContentTypeId: contentTypeId
},
cache: false,
dataType: 'json',
success: function(response) {
complete(response);
}
});
};
$.telligent.evolution.ui.components.moderate = {
setup: function() { },
add: function(elm, options) {
elm = $(elm);
var moderationOptions = {
contentId: options.contentid,
contentTypeId: options.contenttypeid,
supportsAbuse: options.supportsabuse === 'true',
initialState: options.initialstate === 'true',
onReport: reportAbuse
};
if(options.configuration && options.configuration.AdditionalLinks) {
var links = JSON.parse(options.configuration.AdditionalLinks);
// don't render if no links
if(!moderationOptions.supportsAbuse && links.length === 0)
return;
// if given an explicit set of links at init-time, create a wrapper
// callback which always returns them as aditional inks
moderationOptions.onGetAdditionalLinks = function(complete) {
complete(links);
};
}
else if(options.configuration && options.configuration.AdditionalLinksUrl) {
// don't render if no links
if(!moderationOptions.supportsAbuse && options.configuration.AdditionalLinksUrl.length === 0)
return;
// otherwise, if given a url for additional links, create a wrapper
// callback which makes an ajax request to get the extra links
moderationOptions.onGetAdditionalLinks = function(complete) {
$.telligent.evolution.get({
url: options.configuration.AdditionalLinksUrl,
cache: false,
dataType: 'json',
success: function(response) {
complete(response.links || []);
}
});
};
}
// don't render if no additional links
if(!moderationOptions.supportsAbuse && !moderationOptions.onGetAdditionalLinks)
return;
if(options.configuration && options.configuration.LinkClassName) {
moderationOptions.linkClassName = options.configuration.LinkClassName;
}
elm.evolutionModerate(moderationOptions);
}
};
}(jQuery));