﻿var commentClassName = 'comentario';

function loadCommentIconList() {
    loadCommentIconListInContext('');
}

function loadCommentIconListInContext(pSelectorContext) {
    var commentRequestArray = new Array();

    if (pSelectorContext && pSelectorContext != '') {
        pSelectorContext = pSelectorContext + ' ';
    }

    var commentIconList = $(pSelectorContext + '.' + commentClassName);

    commentIconList.each(function (e) {
        var contentId = $(this).attr('contentId');
        var contentTypeId = $(this).attr('contentTypeId');
        var systemId = $(this).attr('systemId');

        commentRequestArray.push({ "ContentId": contentId, "ContentTypeId": contentTypeId, "SystemId": systemId });
    });

    if (commentIconList.length > 0) {
        callServerMethodByPost('/Service/Comment/CommentService.svc/GetCommentIconList/' + LoggedUserId, commentRequestArray, loadCommentIconListResponse, commentIconList);
    }
}

function loadCommentIconListResponse(pResponse, pCommentIconList) {
    for (var x = 0; x < pResponse.length; x++) {
        var commentIcon = pCommentIconList.filter('[contentId="' + pResponse[x].ContentId + '"][contentTypeId="' + pResponse[x].ContentTypeId + '"][systemId="' + pResponse[x].SystemId + '"]');

        commentIcon.html('(' + pResponse[x].Total + ')');
    }
}

