1 2var CommentsView = function () { }; 3 4CommentsView.prototype = function () { 5 6 var CommentsService = new BCMSCommentsService(); 7 8 function _drawCommentsList(comments) { 9 10 var commentList = ''; 11 12 comments.forEach(function (comment) { 13 commentList += '<div class="comment" id="comment-' + comment.CommentId + '" data-comment-id="' + comment.CommentId + '"><div class="comment-body"><div class="comment-body-img">' 14 + '<a href="/user/details/' + comment.CommentSubmittedBy + '"><img src="' + comment.AvatarImageUrl + '" alt="' + comment.CommentSubmittedBy + '" class="img-responsive"/></a></div>' 15 + '<div class="comment-header">'; 16 17 if (comment.CommentUrl.trim().length != 0) { 18 commentList += '<a href="' + comment.CommentUrl + '">' + comment.CommentSubmittedBy + '</a>'; 19 } 20 else { 21 commentList += '<span class="comment-author"><a href="/user/details/' + comment.CommentSubmittedBy + '">' + comment.CommentSubmittedBy + '</a></span>'; 22 } 23 24 commentList += ' - ' + comment.CommentDate + ' '; 25 26 if (comment.DrawEditLink == true) { 27 commentList += '<a href="/comment/edit/' + comment.CommentId + '">edit</a> - ' 28 + '<a href="#" class="unpublish-comment-link" title="unpublish comment" data-comment-id="' + comment.CommentId + '">unpublish</a> - ' 29 + '<a href="#" class="delete-comment-link" title="delete comment" data-comment-id="' + comment.CommentId + '">delete</a> - ' 30 + '<a href="#" class="spam-comment-link" title="flag as spam" data-comment-id="' + comment.CommentId + '">flag as spam</a>'; 31 } 32 commentList += '</div><div class="comment-body-content">' + comment.CommentBody + '</div></div></div>'; 33 }); 34 35 $('#comments-list').html(commentList); 36 37 // wire up link handlers if needed 38 if (comments.length > 0 && comments[0].DrawEditLink == true) { 39 40 $('#comments-list-container').find('a.delete-comment-link').click(function (event) { 41 event.preventDefault(); 42 _deleteComment(event.target.getAttribute('data-comment-id')); 43 }); 44 45 $('#comments-list-container').find('a.spam-comment-link').click(function (event) { 46 event.preventDefault(); 47 _reportSpam(event.target.getAttribute('data-comment-id')); 48 }); 49 50 $('#comments-list-container').find('a.unpublish-comment-link').click(function (event) { 51 event.preventDefault(); 52 _unpublishComment(event.target.getAttribute('data-comment-id')); 53 }); 54 } 55 56 // update the comment-counts-header with the number of loaded comments 57 var label = ' comment' + (comments.length == 1 ? '' : 's'); 58 $('#comment-counts-header').text(comments.length + label); 59 } 60 61 function _reloadComments() { 62 63 var dfd = $.Deferred(); 64 65 // display a spinner: 66 $('#comments-spinner').show(); 67 68 var contentId = $('#comments-list-container').attr('data-content-id'); 69 if (contentId == undefined || contentId == 0) { 70 dfd.resolve(); 71 return; 72 } 73 74 CommentsService.getApprovedComments(contentId, 75 function (comments) { 76 // success 77 78 // stop the spinner 79 $('#comments-spinner').hide(); 80 81 _drawCommentsList(comments); 82 83 // resolve the promise now: 84 dfd.resolve(); 85 }, 86 function () { 87 // stop the spinner 88 $('#comments-spinner').hide(); 89 90 // failure - eat it 91 dfd.resolve(); 92 }); 93 94 return dfd; 95 } 96 97 function _deleteComment(id) { 98 CommentsService.deleteComment( 99 id, 100 function (result) { 101 // success 102 _reloadComments().then(function () { 103 _showCommentMessage(true, "Comment deleted."); 104 }) 105 }, 106 function (result, errortext, errorThrown) { 107 // failure: 108 _reloadComments().then(function () { 109 _showCommentMessage(false, "Sorry there was an error deleting the comment."); 110 }) 111 }); 112 } 113 114 function _reportSpam(id) { 115 CommentsService.flagSpam( 116 id, 117 function (result) { 118 // success 119 _reloadComments().then(function () { 120 _showCommentMessage(true, "Comment flagged as spam and unapproved."); 121 }); 122 }, 123 function (result, errortext, errorThrown) { 124 // failure: 125 _reloadComments().then(function () { 126 _showCommentMessage(false, "Sorry, there was an error flagging the comment as spam."); 127 }) 128 }); 129 } 130 131 function _reportHam(id) { 132 CommentsService.flagNotSpam( 133 id, 134 function (result) { 135 // success 136 _reloadComments().then(function () { 137 _showCommentMessage(true, "Comment unflagged as spam."); 138 }); 139 }, 140 function (result, errortext, errorThrown) { 141 // failure: 142 _reloadComments().then(function () { 143 _showCommentMessage(false, "Sorry, there was an error unflagging the comment as spam."); 144 }) 145 }); 146 } 147 148 function _unpublishComment(id) { 149 CommentsService.unapproveComment( 150 id, 151 function (result) { 152 // success 153 _reloadComments().then(function () { 154 _showCommentMessage(true, "Comment unpublished."); 155 }); 156 }, 157 function (result, errortext, errorThrown) { 158 // failure: 159 _reloadComments().then(function () { 160 _showCommentMessage(false, "Sorry, there was an error unpublishing the comment."); 161 }) 162 }); 163 } 164 165 function _postComment() { 166 var author = $('#CommentSubmittedBy').val(); 167 var email = $('#CommentEMail').val(); 168 var website = $('#CommentUrl').val(); 169 var body = $('#CommentBody').val(); 170 var targetId = $('#TargetId').val(); 171 var targetType = $('#TargetContentType').val(); 172 173 CommentsService.postComment(author, email, website, body, targetId, targetType, 174 function (result) { 175 // success 176 $('#CommentBody').val(''); 177 178 _reloadComments(targetId); 179 if (result.CommentState != undefined && result.CommentState == "pending") { 180 _showCommentMessage(true, result.Message); 181 } 182 }, 183 function (result, errortext, errorThrown) { 184 // failure: 185 _showCommentMessage(false, result.Message); 186 }); 187 } 188 189 function _showCommentMessage(isSuccess, msg) { 190 191 $('#CommentSubmittedBy').removeClass('input-validation-error'); 192 $('#CommentEMail').removeClass('input-validation-error'); 193 $('#CommentUrl').removeClass('input-validation-error'); 194 $('#CommentBody').removeClass('input-validation-error'); 195 196 if (isSuccess == false) { 197 $('#resultMessageBox').removeClass(); 198 $('#resultMessageBox').addClass('bg-warning'); 199 $('#resultMessageBox').html(msg); 200 $('#resultMessageBox').fadeIn(500); 201 } 202 else { 203 $('#resultMessageBox').html(msg); 204 $('#resultMessageBox').removeClass().addClass('bg-success'); 205 $('#resultMessageBox').fadeIn(500).delay(10000).slideUp(1000); 206 } 207 } 208 209 return { 210 deleteComment: _deleteComment, 211 drawCommentsList: _drawCommentsList, 212 postComment: _postComment, 213 reloadComments: _reloadComments, 214 reportHam: _reportHam, 215 reportSpam: _reportSpam, 216 unpublishComment: _unpublishComment 217 }; 218 219}(); 220 221var commentsView = new CommentsView(); 222 223$(document).ready( 224 225 function () { 226 227 $("#resultMessageBox").hide(); 228 229 // wire up save comment button handler: 230 var btnSaveComment = $('#saveCommment').first(); 231 if (btnSaveComment != undefined) { 232 $('#saveComment').click(function (event) { 233 event.preventDefault(); 234 commentsView.postComment(); 235 }); 236 } 237 238 // load the comments page: 239 commentsView.reloadComments(); 240 } 241);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.