var Unibase; (function (Unibase) { let Platform; (function (Platform) { let Automation; (function (Automation) { let Components; (function (Components) { class Comments extends Unibase.Platform.Core.BaseComponent { constructor() { super(); this.commentcount = 0; } cssFiles() { return [""]; } jsFiles() { return [""]; } html(id, containerid) { let html = `
Comments (0)
`; $("." + containerid).html(html); return ""; } init(containerId) { var instance = this; instance.html("", containerId); var id = ""; var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; instance.InstalledAppId = InstalledAppId; for (let obj of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) { if (obj.Key === "hf_" + InstalledAppId + "_recordid") { id = obj.Value; } } instance.load(id, containerId, null); } load(id, containerid, callback) { var instance = this; instance.currentuser = Unibase.Platform.Membership.Infos.Identity.currentUser; instance.showComments(); } showComments() { var instance = this; $('.allComments_').remove(); var commentshtml = '
' + '
' + '
' + '' + '
'; $("#divComments").html(commentshtml); instance.loadComments(); instance.addComments(); } loadComments() { var instance = this; var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; var refGuid = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_versionguid").Value; var jsfiles = ['platform/automation/managers/commentmanager.js', 'platform/automation/infos/comment.js', 'platform/automation/requests/comment.js', 'platform/automation/enums/commenttype.js']; instance.fileCacheHelper.loadJsFiles(jsfiles, function () { Unibase.Platform.Automation.Managers.CommentManager.Instance().getMyCommentsByGuid(refGuid).then(function (response) { var CommentId = 0; var ParentCommentCount = 0; $('.commentsCount_').text(response.result.length); $('.comments_count').text(response.result.length); var html = ""; $(".comment-addItem").remove(); $(".comment-item_").remove(); var commentClosed = true; let photoUrl = ""; if (instance.currentUser.photoUrl != "" && instance.currentUser.photoUrl != null) { photoUrl = instance.currentUser.photoUrl; let srcSplit = photoUrl.split('/'); if (srcSplit[srcSplit.length - 1] == 'unnamed.png') { photoUrl = "tenants/themes/compact/imgs/avatar.jpg"; } } else { photoUrl = "tenants/themes/compact/imgs/avatar.jpg"; } html += `
`; for (var i = 0; i < response.result.length; i++) { var model = response.result[i]; var deletehtml = ''; if (model.CreatedBy == instance.currentuser.userId) { deletehtml = '
' + '
'; } var CreatedByImage = " "; if (model.FromUserPhotoUrl == null || model.FromUserPhotoUrl == "") { if (model.ImageUrl == null) { let avatarTxt = ""; let headingTxt = model.FromUserName; let matches = headingTxt.match(/\b(\w)/g); if (matches.length == 1) { avatarTxt = $.trim(headingTxt).substr(0, 2); } else { avatarTxt = matches.join('').slice(0, 2); } CreatedByImage = `
${avatarTxt}
`; } else { CreatedByImage = `img`; } } else { CreatedByImage = model.FromUserPhotoUrl; let srcSplit = CreatedByImage.split('/'); if (srcSplit[srcSplit.length - 1] == 'unnamed.png' || CreatedByImage == null || CreatedByImage == "") { let avatarTxt = ""; let headingTxt = model.FromUserName; let matches = headingTxt.match(/\b(\w)/g); if (matches.length == 1) { avatarTxt = $.trim(headingTxt).substr(0, 2); } else { avatarTxt = matches.join('').slice(0, 2); } CreatedByImage = `
${avatarTxt}
`; } else { CreatedByImage = `img`; } } var attachImage = ""; if (model.ImageUrl == null || model.ImageUrl == "") attachImage = ''; else { attachImage = ""; } var commentIcon = ""; var commentName = ""; var IsEvent = ""; var bgcolor = ""; var parentCount = `Replies`; parentCount += ` (${model.ParentCommentCount}) `; if (model.ParentCommentCount == 0) { parentCount = `Reply`; parentCount += ``; } if (model.CommentType == Unibase.Platform.Automation.Enums.CommentType.Comment) { } else if (model.CommentType == Unibase.Platform.Automation.Enums.CommentType.Call) { commentIcon = "fa fa-phone text-info"; commentName = "Call"; } else if (model.CommentType == Unibase.Platform.Automation.Enums.CommentType.Mail) { commentIcon = "fa fa-envelope-o text-info"; commentName = "Mail"; } else if (model.CommentType == Unibase.Platform.Automation.Enums.CommentType.Meeting) { commentIcon = "fa fa-users text-info "; commentName = "Meeting"; } else if (model.CommentType == Unibase.Platform.Automation.Enums.CommentType.Follow) { commentIcon = "fa fa-flash text-info"; commentName = "Event"; IsEvent = "hidden"; } if ($("#hfCommentids").val() != model.CommentId) { if ($("#hfCommentids").val() != "0") html += ''; $("#hfCommentids").val(model.CommentId); if (model.ParentCommentCount > 0) { html += '
' + '' + '
' + '
' + CreatedByImage + '
' + '
' + '
' + model.FromUserName + '
'; } else { html += '
' + '' + '
' + '
' + CreatedByImage + '
' + '
' + '
' + model.FromUserName + '
'; } if (model.IsSystemGenerated != true) { if (window.innerWidth <= 1198) { html += deletehtml + '
' + '
' + model.CommentSubject + '
'; } else { html += deletehtml + '
' + '
' + model.CommentSubject + '
'; } } } html += '
' + commentName + ''; if (model.IsSystemGenerated != true) { if (window.innerWidth <= 1198) { html += ' ' + parentCount + '' + '
' + Unibase.Platform.Helpers.DateTimeHelper.Instance().commentsdateformat(model.CreatedDate) + '
' + '
'; } else { html += ' ' + parentCount + '' + ' ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().commentsdateformat(model.CreatedDate) + '' + ' '; } } CommentId = model.CommentId; ParentCommentCount = model.ParentCommentCount; } $('.allComments_').after(html); let size_li = $("#divComments_ .comment-addItem").length; if (size_li >= 5) { $('#loadMore-Comments').removeClass("d-none"); } else { $('#loadMore-Comments').addClass("d-none"); } instance.commentcount = 5; $('#divComments_ .comment-addItem:lt(' + instance.commentcount + ')').removeClass("d-none"); $('#loadMore-Comments').click(function () { instance.commentcount = (instance.commentcount + 5 <= size_li) ? instance.commentcount + 5 : size_li; $('#divComments_ .comment-addItem:lt(' + instance.commentcount + ')').removeClass("d-none"); debugger; if (instance.commentcount == size_li) { $('#loadMore-Comments').addClass("d-none"); instance.commentcount = 0; } }); instance.toGetReplyCountByParentId(CommentId, ParentCommentCount); }, function (response) { }); }); } addComments() { var html = ""; $('#divComments_').append(html); $('#divComments_').append(`
More
`); } toGetReplyCountByParentId(Id, Count) { var ParentId = Id; var ParentCommentCount = Count; if (ParentId != 0) { Unibase.Platform.Automation.Managers.CommentManager.Instance().getCommentsByParentId(ParentId).then(function (response) { for (var i = 0; i < response.result.length; i++) { ParentCommentCount = ParentCommentCount + response.result[i].ParentCommentCount; if (ParentCommentCount != 0) { $('.toGetReplyCountByParentId' + ParentId).text('Replies'); $('#Reply_' + ParentId).text(`(${ParentCommentCount})`); } else { $('.toGetReplyCountByParentId' + ParentId).text('Reply'); $('#Reply_' + ParentId).text(``); } } }); } } saveComment() { var instance = this; let size_li = $("#divComments_ .comment-addItem").length; if (size_li >= 5) { $('#loadMore-Comments').removeClass("d-none"); } if ($('.txtnewComment_').val().toString().trim() == null || $('.txtnewComment_').val().toString().trim() == "") { MessageHelper.Instance().showError("Please Enter Something...", "div_message"); return false; } var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; var refGuid = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_versionguid").Value; var postData = { CommentId: 0, RefGuid: refGuid, CommentSubject: $(".txtnewComment_").val().toString().trim(), CommentType: Unibase.Platform.Automation.Enums.CommentType.Comment, Followers: null, InstallPageId: Unibase.Themes.Providers.DetailHelper.installedAppId, ParentId: 0 }; Unibase.Platform.Automation.Managers.CommentManager.Instance().saveComment(postData).then(function (response) { var CommentId = response.result.CommentId; $(".txtnewComment_").val(" "); $("#Notifications_txtActivities").val(' '); $("#childcomment-list_" + CommentId).html(' '); instance.loadComments(); instance.childComments(CommentId, undefined, true); }); } childComments(commentId, parentid, fromsendbtn) { Unibase.Platform.Automation.Managers.CommentManager.Instance().getCommentsByParentId(commentId).then(function (response) { if (parentid == undefined) { var html = '
' + '
' + '' + '
' + '
' + '
' + '
'; } else { if (!fromsendbtn || fromsendbtn && $('.childcomment-item_' + commentId + '').hasClass('ml-35')) { var html = '
'; } else if (fromsendbtn && !$('.childcomment-item_' + commentId + '').hasClass('ml-35')) { var html = '
'; } html += '
' + '' + '
' + '
' + '
' + '
'; } if (response.result != null) for (var i = response.result.length - 1; i >= 0; i--) { var model = response.result[i]; var parentCount = `Replies`; parentCount += ` (${model.ParentCommentCount}) `; if (model.ParentCommentCount == 0) { parentCount = `Reply`; parentCount += ``; } var commentIcon = ""; var bgcolor = ""; var CommImage = ""; if (model.FromUserPhotoUrl == null || model.FromUserPhotoUrl == "") { let avatarTxt = ""; let headingTxt = model.FromUserName; let matches = headingTxt.match(/\b(\w)/g); if (matches.length == 1) { avatarTxt = $.trim(headingTxt).substr(0, 2); } else { avatarTxt = matches.join('').slice(0, 2); } CommImage = `
${avatarTxt}
`; } else { let imgsrc = model.FromUserPhotoUrl; let srcSplit = imgsrc.split('/'); if (srcSplit[srcSplit.length - 1] == 'unnamed.png') { let avatarTxt = ""; let headingTxt = model.FromUserName; let matches = headingTxt.match(/\b(\w)/g); if (matches.length == 1) { avatarTxt = $.trim(headingTxt).substr(0, 2); } else { avatarTxt = matches.join('').slice(0, 2); } CommImage = `
${avatarTxt}
`; } else { CommImage = `img`; } } var deletehtml = ''; if (model.CreatedBy == Unibase.Platform.Automation.Components.Comments.Instance().currentuser.userId) { deletehtml = '
' + '
'; } bgcolor = "text-warning"; $("#hfAssignedFollowers").val(model.AssignedFollowers); if (window.innerWidth <= 1198) { var innerhtml = '
' + '
' + '
' + CommImage + '
' + '
' + model.FromUserName + '
' + deletehtml + '
' + model.CommentSubject + '
' + '
' + ' ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().commentsdateformat(model.CreatedDate) + '' + '
'; } else { var innerhtml = '
' + '
' + '
' + CommImage + '
' + '
' + model.FromUserName + '
' + deletehtml + '
' + model.CommentSubject + '
' + '
' + ' ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().commentsdateformat(model.CreatedDate) + '' + '
'; } if (parentid == undefined) { innerhtml += '' + '
'; } else { innerhtml += '' + '
'; } html = html + innerhtml; } if (fromsendbtn != true) { if ($('#comments-' + commentId).hasClass('hidden')) { $('#comments-' + commentId).removeClass('hidden').addClass('show'); } else { $('#comments-' + commentId).removeClass('show').addClass('hidden'); } } $("#childcomment-list_" + commentId).html(html); let userName; if ($('.toGetReplyCountByParentId' + commentId).parents('.stats_container').length > 0) { userName = $('.toGetReplyCountByParentId' + commentId).parents('.stats_container').siblings('.comment-user-details').find('.comment-username h6').text().trim(); } else if ($('.toGetReplyCountByParentId' + commentId).parents('.comment-username').length > 0) { userName = $('.toGetReplyCountByParentId' + commentId).parents('.comment-username').find('h6').text().trim(); } $('.txtnewComment_' + commentId).val('@' + userName + ' '); }); } addChildCommentsforChildComments(commentId, parentid, fromsendbtn) { var instance = this; if ($('.txtnewComment_' + commentId).val() == null || $('.txtnewComment_' + commentId).val() == "") { MessageHelper.Instance().showError("Please Enter Something...", "bizgaze_SpiltErrorMessages"); return false; } var assgflwrs = null; if ($('#hfAssignedFollowers_' + commentId).val() != null) { assgflwrs = $('#hfAssignedFollowers_' + commentId).val(); } var postData = { CommentId: 0, RefGuid: $('#hf_ParentCmtVersionGuid_' + parentid).val().toString(), CommentSubject: $(".txtnewComment_" + commentId).val().toString(), CommentType: Unibase.Platform.Automation.Enums.CommentType.Comment, Followers: assgflwrs, InstallPageId: $("#hfBizgaze_InstalledPageId").val(), ParentId: commentId, }; Unibase.Platform.Automation.Managers.CommentManager.Instance().saveComment(postData).then(function (response) { $(".txtnewComment_" + commentId).val(" "); instance.childComments(commentId, parentid, fromsendbtn); instance.toGetReplyCount(commentId, parentid); }); } deleteComment(commentId, parentCommentId, SuperParentCmtId, IsChild) { var instance = this; bootbox.confirm("Are you sure want to delete?", function (result) { if (result) { Unibase.Platform.Automation.Managers.CommentManager.Instance().deleteComment(commentId).then(function (response) { MessageHelper.Instance().showSuccess(response.message, ''); if (IsChild == 0) { instance.loadComments(); } else { instance.childComments(parentCommentId, SuperParentCmtId, true); } instance.toGetReplyCount(parentCommentId); }); } }); } toGetReplyCount(Id, parentId) { var CommentId = Id; var ParentCommentCount = 0; if (CommentId != 0) { Unibase.Platform.Automation.Managers.CommentManager.Instance().getCommentByCommentId(CommentId).then(function (response) { ParentCommentCount = ParentCommentCount + response.result.ParentCommentCount; if (ParentCommentCount != 0) { $('.toGetReplyCountByParentId' + CommentId).text('Replies'); $('#Reply_' + CommentId).text(`(${ParentCommentCount})`); } else { $('.toGetReplyCountByParentId' + CommentId).text('Reply'); $('#Reply_' + CommentId).text(``); } CommentId = response.result.ParentId; }); } } enableSendbtn(e, id) { let input = $('#commentTextBox_' + id); let btn = $('#commentPostButton_' + id).find('.commentSendBtn'); if (input.val().length > 0) { btn.removeClass('text-disabled').addClass('text-primary'); } else { btn.removeClass('text-primary').addClass('text-disabled'); } } static Instance() { if (this.instance == undefined) { this.instance = new Comments(); } return this.instance; } } Components.Comments = Comments; })(Components = Automation.Components || (Automation.Components = {})); })(Automation = Platform.Automation || (Platform.Automation = {})); })(Platform = Unibase.Platform || (Unibase.Platform = {})); })(Unibase || (Unibase = {}));