Wednesday, 24 October 2018

Viima JQuery Comments - GetUsers(Pinged users) displaying incorrectly

References

Description

I have a view with a list of "articles" with a "read more" button on each "article" in the list. When I click on the read more button a modal opens up with a partial view with the jquery comments in it. However, when I search for the pinged users (using the @ sign), the list of users don't show by the textarea, but instead higher up in the modal (far from the textarea).

Below is an image, then below that is my code. You will see at the bottom of the image I have put the '@' sign and the list of users is displayed on the top, it should be by the textarea. It also seems that when I click on the articles lower in the list, the higher the list of users display when I push the '@' sign:

enter image description here

Jquery Code

$.ajax({
    type: 'get',
    url: '@Url.Action("ShowArticleDetails", "ILearn")',
    contentType: 'application/json; charset=utf-8',
    dataType: 'html',
    data: { "id": id },
    success: function (result) {
        $("#target-show-details").html(result);
        $('#loadingPanelShowDetails').hide();

        var saveComment = function (data) {
            $(data.pings).each(function (index, id) {
                var user = usersArray.filter(function (user) { return user.id == id })[0];
                alert(user.fullname);
                data.content = data.content.replace('@@' + id, '@@' + user.fullname);
            });

            return data;
        }
        $('#articlecomments-container').comments({
            profilePictureURL: 'https://viima-app.s3.amazonaws.com/media/public/defaults/user-icon.png',
            currentUserId: 1,
            roundProfilePictures: true,
            textareaRows: 1,
            enableAttachments: true,
            enableHashtags: true,
            enablePinging: true,
            getUsers: function (success, error) {
                $.ajax({
                    type: 'get',
                    traditional: true,
                    url: '@Url.Action("GetPinnedUsers", "ILearn")',
                    success: function (usersArray) {
                        success(usersArray)
                    },
                    error: error
                });
            },
            getComments: function (success, error) {
                $.ajax({
                    type: 'get',
                    traditional: true,
                    data: { "id": id },
                    url: '@Url.Action("GetArticleComments", "ILearn")',
                    success: function (commentsArray) {
                        success(saveComment(commentsArray))
                    },
                    error: error
                });
            },
            postComment: function (data, success, error) {
                $.ajax({
                    type: 'post',
                    dataType: "json",
                    url: '@Url.Action("PostArticleComment", "ILearn")',
                    data: { "CVM": data, "articleId": id },
                    success: function (comment) {
                        success(comment);
                    },
                    error: error
                });
            },
            putComment: function (data, success, error) {
                $.ajax({
                    type: 'post',
                    dataType: "json",
                    url: '@Url.Action("PutArticleComment", "ILearn")',
                    data: { "CVM": data, "articleId": id },
                    success: function (comment) {
                        success(comment);
                    },
                    error: error
                });
            },
            deleteComment: function (data, success, error) {
                $.SmartMessageBox({
                    title: "Deleting Comment?",
                    content: "Are you sure that you want to delete this comment?",
                    buttons: '[No][Yes]'
                }, function (ButtonPressed) {
                    if (ButtonPressed === "Yes") {
                        $.ajax({
                            type: 'post',
                            dataType: "json",
                            url: '@Url.Action("DeleteArticleComment", "ILearn")',
                            data: { "CVM": data, "articleId": id },
                            success: function (data) {
                                if (data.status === "usersuccess") {
                                    $.smallBox({
                                        title: "<strong>Comment Deleted</strong>",
                                        content: "<i class='fa fa-clock-o'></i> <i>Comment was successfully deleted! <strong</strong></i>",
                                        color: "#659265",
                                        iconSmall: "fa fa-check fa-2x fadeInRight animated",
                                        timeout: 4000
                                    });
                                    success();
                                } else {
                                    success();
                                }
                            }
                        });
                    }
                    if (ButtonPressed === "No") {
                        $.smallBox({
                            title: "<strong>Comment not deleted</strong>",
                            content: "<i class='fa fa-clock-o'></i> <i>This comment has not been deleted.</i>",
                            color: "#C46A69",
                            iconSmall: "fa fa-times fa-2x fadeInRight animated",
                            timeout: 4000
                        });
                    }

                });
                e.preventDefault();
            },
            upvoteComment: function (data, success, error) {
                if (data.user_has_upvoted) {
                    $.ajax({
                        type: 'post',
                        dataType: "json",
                        url: '@Url.Action("UpVoteArticleComment", "ILearn")',
                        data: { "CVM": data, "articleId": id },
                        success: function () {
                            success(data)
                        },
                        error: error
                    });
                } else {
                    $.ajax({
                        type: 'post',
                        url: '@Url.Action("DeleteArticleCommentUpvote", "ILearn")',
                        data: { "commentId": data.id },
                        success: function () {
                            success(commentJSON)
                        },
                        error: error
                    });
                }
            },
            uploadAttachments: function (commentArray, success, error) {
                var responses = 0;
                var successfulUploads = [];

                var serverResponded = function () {
                    responses++;

                    // Check if all requests have finished
                    if (responses == commentArray.length) {

                        // Case: all failed
                        if (successfulUploads.length == 0) {
                            error();

                            // Case: some succeeded
                        } else {
                            success(successfulUploads)
                        }
                    }
                }

                $(commentArray).each(function (index, commentJSON) {

                    // Create form data
                    var formData = new FormData();
                    $(Object.keys(commentJSON)).each(function (index, key) {
                        var value = commentJSON[key];
                        if (value) formData.append(key, value);
                    });

                    formData.append('fkiKnowledgeSharingArticlesId', id);

                    $.ajax({
                        url: '@Url.Action("UploadToArticleComments", "ILearn")',
                        type: 'POST',
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function (commentJSON) {
                            successfulUploads.push(commentJSON);
                            serverResponded();
                        },
                        error: function (data) {
                            serverResponded();
                        },
                    });
                });
            }
        });

    },
    error: function (xhr, textStatus, errorThrown) {
        alert(xhr.responseText);
    }
});

MVC Partial View

@model Innovation_Cafe.Models.KnowledgeSharingArticles
<div class="col-lg-12">
    <div class="margin-top-10">
        <div style="text-align:center;border:solid;border-style:solid">
            <img src="@Model.ArticleImage" class="img-responsive" alt="img" style="width:100%;">
        </div>
        <ul class="list-inline padding-10">
            <li>
                <i class="fa fa-calendar"></i>
                @Model.DateTimeStamp.ToLongDateString()
            </li>
            <li>
                <i class="fa fa-comments"></i>
                @Model.ArticleComments
            </li>
            <li>
                <i class="fa fa-eye"></i>
                @Model.ArticleViews
            </li>
        </ul>
    </div>
</div>
<div class="col-lg-12">
    <h6 class="margin-top-0"> @Model.Title<br><small class="font-xs"><i>Published by <a href="@Url.Action(" GetProfileData","UserProfile", new { userid=Model.fkiUserId })">@Model.User_FullName</a></i></small></h6>
    <br />
    <p>
        @Html.Raw(Model.Description)
    </p>
    <p>
        @if (Model.FileType == ".mp4")
            {
            <div style="text-align:center;border-style:solid">
                <video controls width="100%">
                    <source src="@Model.FilePath" type="video/mp4" />
                </video>
            </div>
        }
        else
        {
            if (Model.FilePath !=null)
            {
            <p>Click here to view file: <a href="@Model.FilePath" target="_blank">Click here</a></p>
            }
        }

    </div>
    <div class="col-md-12">
        <p>&nbsp;</p>
        <hr style="border:solid" />
    </div>
    <div class="row col-md-12">
        <div class="col-md-12" id="articlecomments-container">

        </div>
    </div>

At the bottom of the partial view is this div where it is populated:

<div class="row col-md-12">
    <div class="col-md-12" id="articlecomments-container">

    </div>
</div>



from Viima JQuery Comments - GetUsers(Pinged users) displaying incorrectly

No comments:

Post a Comment