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 = `
`;
$("." + 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 = `
`;
}
}
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 = `
`;
}
}
var attachImage = "";
if (model.ImageUrl == null || model.ImageUrl == "")
attachImage = '';
else {
attachImage = "
";
}
var commentIcon = "";
var commentName = "";
var IsEvent = "";
var bgcolor = "";
var parentCount = ``;
parentCount += ``;
if (model.ParentCommentCount == 0) {
parentCount = ``;
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 += '';
}
}
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(``);
}
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 = '
' + model.FromUserName + '
' + model.FromUserName + '