Adding controls to Community comments from Agents
Someone asked if it was possible to add checkboxes at the bottom of Community comment editor so moderators could mark a Community Post as "Answered" or "Closed for comments" at the same time they posted a reply. Like this:
This can be done by using JavaScript to add the chekboxes and make API calls to update the post.
Quick note before starting: This is customization that is not supported by Zendesk, and you might need a web developer to help you if you have issues.
Go to your Help Center's Edit Theme page and add this code at the top of the JS page:
//Community "Answered" and "Closed" checkboxes
$(document).ready(function () {
// Replace SUBDOMAIN for account subdomain. For example: var subdomain = 'support';
var subdomain = 'SUBDOMAIN';
var windowURL = window.location.href;
if (windowURL.indexOf('posts') > 0) {
(function () {
var $commentFormControls = $('.comment-form-controls');
var $officialCommentLabel = $('#community_comment_official');
if ($officialCommentLabel.length > 0) {
$commentFormControls.prepend($('<input class="community_moderator_tool" type="checkbox" name="community_comment[answered]" id="community_comment_answered">\n <label class="community_moderator_tool" for="community_comment_answered" id="community_comment_answered_label" style="margin-right: 15px;">Answered</label>\n <input class="community_moderator_tool" type="checkbox" name="community_comment[closed]" id="community_comment_closed">\n <label class="community_moderator_tool" for="community_comment_closed" id="community_comment_closed_label" style="margin-right: 15px;">Closed for comments</label>'));
}
var $commentSubmitButton = $('input[type=submit]');
var postSplit = windowURL.split('/posts/');
var secondHalf = postSplit[1];
var postID = secondHalf.substring(0, 9);
var communityJSON = 'https://' + subdomain + '.zendesk.com/api/v2/community/posts/' + postID + '.json';
$commentSubmitButton.click(function makeCalls() {
var $checkedAnswered = $('#community_comment_answered').is(':checked');
var $checkedClosed = $('#community_comment_closed').is(':checked');
if ($checkedAnswered == true) {
$.ajax({
type: 'PUT',
url: communityJSON,
contentType: 'application/json',
data: '{"post": {"status": "answered"}}'
});
}
if ($checkedClosed == true) {
$.ajax({
type: 'PUT',
url: communityJSON,
contentType: 'application/json',
data: '{"post": {"closed": "true"}}'
});
}
});
})();
}
});
Remember to change SUBDOMAIN to your actual subdomain. For example:
var subdomain = "support";
Save and publish the changes, and that's it. Here is what it will look like:
See the full code and result picture here.
Please sign in to leave a comment.
0 Comments