Built files from Bizgaze WebServer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

timeline.js 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. var Unibase;
  2. (function (Unibase) {
  3. let Platform;
  4. (function (Platform) {
  5. let TimeLine;
  6. (function (TimeLine_1) {
  7. let Components;
  8. (function (Components) {
  9. class TimeLine extends Platform.Core.BaseComponent {
  10. constructor() {
  11. super(...arguments);
  12. this.isFilterApplied = false;
  13. this.Followers = [];
  14. this.Comments = [];
  15. this.stageReasons = '';
  16. this.recordId = 0;
  17. }
  18. cssFiles() {
  19. return [];
  20. }
  21. jsFiles() {
  22. return ["platform/automation/enums/eventtype.js", "platform/forms/managers/formmanager.js", "platform/automation/components/actions/externalfollowers.js", "platform/apps/managers/stagemanager.js", 'platform/automation/managers/commentmanager.js', 'platform/automation/infos/comment.js', 'platform/automation/requests/comment.js', 'platform/automation/enums/commenttype.js'];
  23. }
  24. html(id, containerid) {
  25. return null;
  26. }
  27. load(id, containerid, callback) {
  28. }
  29. init(containerid) {
  30. const instance = this;
  31. instance.containerid = containerid;
  32. instance.render(containerid);
  33. instance.loadJsFiles();
  34. let versionguid = "";
  35. if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0) {
  36. for (let obj of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) {
  37. if (obj.Key === "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_versionguid") {
  38. versionguid = obj.Value.toString();
  39. }
  40. }
  41. }
  42. instance.loadDataComments(versionguid, containerid);
  43. $(`#toggleCommentInputBtn_${containerid}`).click(function () {
  44. $(this).addClass('d-none');
  45. $(`#timelineHeaderRight_${containerid}`).removeClass('d-flex').addClass('d-none');
  46. $(`#timelineCommentInputWrap_${containerid}`).removeClass('d-none').addClass('d-flex');
  47. });
  48. $(`#closeCommentSearchBtn_${containerid}`).click(function () {
  49. $(`#toggleCommentInputBtn_${containerid}`).removeClass('d-none');
  50. $(`#timelineHeaderRight_${containerid}`).removeClass('d-none').addClass('d-flex');
  51. $(`#timelineCommentInputWrap_${containerid}`).removeClass('d-flex').addClass('d-none');
  52. });
  53. $(`#timelineCommentForm_${containerid}`).submit(function (e) {
  54. e.preventDefault();
  55. instance.saveComment(versionguid, containerid);
  56. });
  57. $(`#timelineCommentInput_${containerid}`).on('input', function (e) {
  58. const enteredComment = $(this).val().toString().trim();
  59. if (enteredComment) {
  60. $(`#saveCommentBtn_${containerid}`).removeClass('d-none');
  61. }
  62. else {
  63. $(`#saveCommentBtn_${containerid}`).addClass('d-none');
  64. }
  65. });
  66. }
  67. loadJsFiles() {
  68. var jsfiles = this.jsFiles();
  69. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFiles(jsfiles, function () {
  70. Unibase.Platform.TimeLine.Components.TimeLine.Instance().getFollowers();
  71. });
  72. }
  73. getFollowers() {
  74. var hiddenvalues = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_recordid");
  75. if (hiddenvalues != undefined) {
  76. this.recordId = Number(hiddenvalues.Value);
  77. Unibase.Platform.Automation.Managers.RuleManager.Instance().GetFollwersByPkid(this.recordId).then(function (response) {
  78. if (response.result != null) {
  79. TimeLine.Instance().Followers = response.result.filter(x => x.UserId != Unibase.Platform.Membership.Infos.Identity.currentUser.userId);
  80. }
  81. });
  82. }
  83. }
  84. render(containerid) {
  85. $("#" + containerid).empty();
  86. var versionguid = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_versionguid").Value;
  87. let html = `<div id="timeLineWrap_${containerid}" class="timeline-wrap card d-flex flex-column r-gap-15 pa-10">
  88. <div class="flex-between-center position-relative text-dark c-gap-5 c-gap-sm-10 timeline-header"><div class="timeline-header-left flex-grow-1"><a href="javascript:;" class="btn btn-outline-primary btn-sm d-md-none" id="toggleCommentInputBtn_${containerid}">Comment</a><div id="timelineCommentInputWrap_${containerid}" class="d-none d-md-flex align-items-center c-gap-10 flex-grow-1"><div class="d-flex position-relative c-gap-10 flex-grow-1"><form id="timelineCommentForm_${containerid}" method="post" class="w-100"><input type="text" id="timelineCommentInput_${containerid}" class="form-control timeline-comment-input pr-40 shadow-none" data-parentcommentid="0" placeholder="Type Comments here...." />
  89. <div class="d-flex align-items-center c-gap-5 absolute-top-center r-5"><a href="javascript:;" class="btn btn-flush-biz-theme btn-icon btn-file btn-rounded btn-sm flush-soft-hover d-30 d-none" data-tooltip="true" title="Upload file"><span class="btn-icon-wrap"><i class="las la-file-upload font-20"></i></i></span><input type="file" name="comment-file-upload"></a><button type="submit" id="saveCommentBtn_${containerid}" class="btn btn-flush-biz-theme btn-icon btn-rounded btn-sm flush-soft-hover d-30 save-comment-btn d-none" data-tooltip="true" title="Save"><span class="btn-icon-wrap"><i class="las la-paper-plane font-20"></i></span></button></div></form></div><a href="javascript:;" id="closeCommentSearchBtn_${containerid}" class="btn btn-icon btn-icon-circle btn-outline-danger btn-sm d-md-none"><span class="btn-icon-wrap"><i class="las la-times font-20"></i></span></a></div>
  90. </div>
  91. <div class="timeline-header-right d-flex align-items-center justify-content-end gap-5 c-gap-sm-10 flex-wrap" id="timelineHeaderRight_${containerid}">
  92. <a href="javascript:;" class="btn btn-icon btn-icon-circle btn-outline-primary btn-sm" data-tooltip="true" title="Call" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadform(3)"><span class="btn-icon-wrap"><i class="las la-phone font-20"></i></span></a><a href="javascript:;" class="btn btn-icon btn-icon-circle btn-outline-primary btn-sm" data-tooltip="true" title="Mail" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadform(0)"><span class="btn-icon-wrap"><i class="las la-envelope font-20"></i></span></a><a href="javascript:;" class="btn btn-icon btn-icon-circle btn-outline-primary btn-sm" data-tooltip="true" title="To Do" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadform(1)"><span class="btn-icon-wrap"><i class="las la-list font-20"></i></span></a>
  93. <a href="javascript:;" class="btn btn-icon btn-icon-circle btn-outline-primary btn-sm" data-tooltip="true" title="Sms" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadform(2)"><span class="btn-icon-wrap"><i class="las la-comment font-20"></i></span></a>
  94. <a href="javascript:;" class="btn btn-icon btn-icon-circle btn-outline-primary btn-sm" data-tooltip="true" title="Meetings" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadform(4)"><span class="btn-icon-wrap"><i class="las la-users font-20"></i></span></a><div class="timeline-filter-dropdown" id="timelineFilterDropdown_${containerid}">
  95. <a class="btn btn-icon btn-icon btn-icon-circle btn-outline-primary btn-sm" href="javascript:;" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-tooltip="true" title="Filter">
  96. <span class="btn-icon-wrap"><i class="las la-filter font-20"></i></span>
  97. </a>
  98. <div class="dropdown-menu timeline_dropdown_menu biz-custom-dropdown" id="timelineFilterDropdownMenu_${containerid}" onclick="event.stopPropagation();">
  99. <div class="row biz-select2-wrap">
  100. <div class="col-sm-6">
  101. <select class="form-control mr-4 event_filter" id="eventFilterSelect_${containerid}" data-placeholder="Select Event Type">
  102. </select>
  103. </div>
  104. <div class="col-sm-6">
  105. <select class="form-control custom-select time_filter" id="dateFilterSelect_${containerid}" data-placeholder="Select Date">
  106. </select>
  107. </div>
  108. </div>
  109. <div class="filter_footer d-flex justify-content-between align-items-center gap-10 mt-10">
  110. <a href="javascript:;" class="btn btn-outline-danger btn-sm Filterbuttons" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().clearTimelineFilters('${containerid}');">Clear</a>
  111. <a href="javascript:;" class="btn btn-outline-primary btn-sm Filterbuttons" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().applyTimelineFilters('${containerid}');">Apply</a>
  112. </div>
  113. </div></div>
  114. </div><div class="Isprimaryswitch mt-2 d-none"><label class="switch"><input type="checkbox" class="chk_primarylog switch" checked onchange="Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadDataComments('${versionguid}','${containerid}')"><span></span></label><span class="Primary_Label" style="position:absolute;right:3px;top:40px">Primary</span></div>
  115. </div>
  116. <div class="timeline-body px-10 d-none" id="timelineBody_${containerid}">
  117. <div class="text-danger text-center d-none" id="noTimelineDataMsg_${containerid}">No Data found!</div>
  118. <ul class="timeline d-flex flex-column r-gap-15" id="timeLineList_${containerid}"></ul>
  119. </div>
  120. <div class="form-error-message ml-0 r-0" id="timeLineErrMsg_${containerid}"></div>
  121. </div>`;
  122. $("#" + containerid).append(html);
  123. }
  124. setTimelineAvatar(timeline) {
  125. let avatarHtml = '';
  126. const { UserName, UserPhotoPath } = timeline;
  127. if (UserPhotoPath) {
  128. avatarHtml = `<img src="${UserPhotoPath}" class="avatar-img rounded-circle">`;
  129. }
  130. else if (UserName) {
  131. let avatarTxt = "";
  132. const headingTxt = UserName;
  133. let matches = headingTxt.match(/\b(\w)/g);
  134. if (matches.length == 1) {
  135. avatarTxt = $.trim(headingTxt).substr(0, 1).toUpperCase() + $.trim(headingTxt).substr(1, 1);
  136. }
  137. else {
  138. avatarTxt = matches.join('').slice(0, 2).toUpperCase();
  139. }
  140. avatarHtml = `<span class="avatar-text avatar-text-primary rounded-circle text-uppercase"><span class="initial-wrap"><span>${avatarTxt}</span></span></span>`;
  141. }
  142. return avatarHtml;
  143. }
  144. removeDuplicateFilterOptions(containerid) {
  145. const seen = {};
  146. $(`#dateFilterSelect_${containerid} option,#eventFilterSelect_${containerid} option`).each(function () {
  147. var txt = $(this).text();
  148. if (seen.hasOwnProperty(txt)) {
  149. $(this).closest("option").remove();
  150. }
  151. else {
  152. seen[txt] = true;
  153. }
  154. });
  155. $(`#eventFilterSelect_${containerid},#dateFilterSelect_${containerid}`).select2({
  156. allowClear: true
  157. });
  158. $(`#eventFilterSelect_${containerid},#dateFilterSelect_${containerid}`).val('').trigger('change');
  159. }
  160. applyTimelineFilters(containerid) {
  161. const instance = this;
  162. const eventFilterVal = $(`#eventFilterSelect_${containerid}`).val();
  163. const dateFilterVal = $(`#dateFilterSelect_${containerid}`).val();
  164. if (eventFilterVal || dateFilterVal) {
  165. const timelineListEl = $(`#timeLineList_${containerid}`);
  166. timelineListEl.find('.timeline-by-date-item,.timeline-item').addClass('d-none');
  167. let timelineItems = $();
  168. if (eventFilterVal) {
  169. timelineItems = timelineListEl.find(`.timeline-item[data-filtertype="${eventFilterVal}"]`);
  170. }
  171. else {
  172. timelineItems = timelineListEl.find(`.timeline-item[data-filterdate="${dateFilterVal}"]`);
  173. }
  174. if (eventFilterVal && dateFilterVal) {
  175. timelineItems = timelineListEl.find(`.timeline-item[data-filterdate="${dateFilterVal}"][data-filtertype="${eventFilterVal}"]`);
  176. }
  177. timelineItems.slice(0, 10).removeClass('d-none').parents('.timeline-by-date-item').removeClass('d-none');
  178. if (timelineItems.not(':visible').length) {
  179. $(`#loadMoreTimelineBtn_${containerid}`).removeClass('d-none');
  180. }
  181. else {
  182. $(`#loadMoreTimelineBtn_${containerid}`).addClass('d-none');
  183. }
  184. if (!timelineItems.length) {
  185. $(`#noTimelineDataMsg_${containerid}`).removeClass('d-none');
  186. }
  187. else {
  188. $(`#noTimelineDataMsg_${containerid}`).addClass('d-none');
  189. }
  190. $(`#timelineFilterDropdownMenu_${containerid}`).removeClass('show');
  191. instance.isFilterApplied = true;
  192. }
  193. }
  194. clearTimelineFilters(containerid) {
  195. if (this.isFilterApplied) {
  196. const timelineListEl = $(`#timeLineList_${containerid}`);
  197. $(`#eventFilterSelect_${containerid},#dateFilterSelect_${containerid}`).val('').trigger('change');
  198. timelineListEl.find('.timeline-item').addClass('d-none');
  199. timelineListEl.find('.timeline-by-date-item,.timeline-item:lt(10)').removeClass("d-none");
  200. timelineListEl.find('.timeline-by-date-item').each(function (i, e) {
  201. if (!$(e).find('.timeline-item:visible').length) {
  202. $(e).addClass('d-none');
  203. }
  204. else {
  205. $(e).removeClass('d-none');
  206. }
  207. });
  208. if (timelineListEl.find('.timeline-item').length > 10) {
  209. $(`#loadMoreTimelineBtn_${containerid}`).removeClass('d-none');
  210. }
  211. $(`#timelineFilterDropdownMenu_${containerid}`).removeClass('show');
  212. this.isFilterApplied = false;
  213. }
  214. }
  215. loadMoreTimeline(containerid) {
  216. const instance = this;
  217. const timelineListEl = $(`#timeLineList_${containerid}`);
  218. if (!instance.isFilterApplied) {
  219. timelineListEl.find('.timeline-item:hidden:lt(10)').removeClass("d-none").parents('.timeline-by-date-item').removeClass('d-none');
  220. if (!timelineListEl.find('.timeline-item:hidden').length) {
  221. $(`#loadMoreTimelineBtn_${containerid}`).addClass('d-none');
  222. }
  223. }
  224. else {
  225. const eventFilterVal = $(`#eventFilterSelect_${containerid}`).val();
  226. const dateFilterVal = $(`#dateFilterSelect_${containerid}`).val();
  227. if (eventFilterVal || dateFilterVal) {
  228. let timelineItems = $();
  229. if (eventFilterVal) {
  230. timelineItems = timelineListEl.find(`.timeline-item[data-filtertype="${eventFilterVal}"]`);
  231. }
  232. else {
  233. timelineItems = timelineListEl.find(`.timeline-item[data-filterdate="${dateFilterVal}"]`);
  234. }
  235. if (eventFilterVal && dateFilterVal) {
  236. timelineItems = timelineListEl.find(`.timeline-item[data-filterdate="${dateFilterVal}"][data-filtertype="${eventFilterVal}"]`);
  237. }
  238. timelineItems.not(':visible').slice(0, 10).removeClass('d-none').parents('.timeline-by-date-item').removeClass('d-none');
  239. if (timelineItems.not(':visible').length) {
  240. $(`#loadMoreTimelineBtn_${containerid}`).removeClass('d-none');
  241. }
  242. else {
  243. $(`#loadMoreTimelineBtn_${containerid}`).addClass('d-none');
  244. }
  245. }
  246. }
  247. }
  248. timelineTxtTrim(containerid) {
  249. const timelineListEl = $(`#timeLineList_${containerid}`);
  250. timelineListEl.find(".timelineContainer").each(function (i, e) {
  251. let containerHeight = $(e).outerHeight(true);
  252. if (containerHeight > 40) {
  253. $(e).addClass('timeline-data-hide');
  254. const firstTimelineEl = $(e).find('.timeline_data').first();
  255. const firstElOuterHeight = firstTimelineEl.outerHeight(true);
  256. if (firstElOuterHeight > 18 && firstElOuterHeight < 40) {
  257. firstTimelineEl.append('<a href="javascript:;" class="font-13 font-weight-600 timeline-more text-dark text-underline ml-10">More</a>');
  258. }
  259. else if (firstElOuterHeight > 40) {
  260. firstTimelineEl.addClass('d-flex align-items-end').append('<a href="javascript:;" class="font-13 font-weight-600 timeline-more text-dark text-underline ml-10">More</a>').find('.timeline-note').addClass('timeline-data-hide-single');
  261. }
  262. else {
  263. $(e).find('.timeline_data').eq(1).addClass('d-flex').append('<a href="javascript:;" class="font-13 font-weight-600 timeline-more text-dark text-underline ml-10">More</a>').find('.timeline-note').addClass('text-truncate');
  264. }
  265. }
  266. });
  267. timelineListEl.find('.timeline-more').on('click', function () {
  268. $(this).parents('.timelineContainer').removeClass('timeline-data-hide');
  269. $(this).parent().removeClass('d-flex').find('.timeline-note').removeClass('timeline-data-hide-single text-truncate');
  270. $(this).remove();
  271. });
  272. }
  273. StageChangeReasons(commentid) {
  274. var reason = "NA";
  275. var description = "NA";
  276. Unibase.Platform.Apps.Managers.StageManager.Instance().getStageChangesByCommentId(commentid).then(function (response) {
  277. if (response.result != null && response.result != "") {
  278. reason = response.result.Reason == null ? "NA" : response.result.Reason;
  279. description = response.result.Description == null ? "NA" : response.result.Description;
  280. }
  281. var html = '<table class="stagereason_table w-100"><tbody style="height:100px"><tr class="mb-2"><th class="text-dark" style="font-size:16px;">Reason</th><th class="text-dark" style="font-size:16px;">Description</th></tr><tr><td>' + reason + '</td><td>' + description + '</td></tr></tbody></table>';
  282. bootbox.dialog({
  283. message: html
  284. });
  285. });
  286. }
  287. loadform(formtype) {
  288. var formuniqueid = "Unibase_Platform_Communications_mails_App_mails_CreateForm_Duplicate";
  289. switch (formtype) {
  290. case 1:
  291. formuniqueid = "Bizgaze_Extension_Communication_Tasks_App_Tasks_CreateForm_Duplicate";
  292. break;
  293. case 2:
  294. formuniqueid = "Unibase_Platform_Communications_SMS_App_SMS_CreateForm_Duplicate";
  295. break;
  296. case 3:
  297. formuniqueid = "Bizgaze_Platform_Crm_Calls_App_Calls_CreateForm_Duplicate";
  298. break;
  299. case 4:
  300. formuniqueid = "Bizgaze_Platform_Communication_Meetings_App_Meetings_CreateForm_Duplicate";
  301. break;
  302. }
  303. Unibase.Platform.Forms.Managers.FormManager.Instance().getFormbyUniqueId(formuniqueid).then(function (response) {
  304. if (response.result != null) {
  305. Unibase.Platform.Helpers.NavigationHelper.Instance().loadForm(response.result.FormId, 0, 0, 0, function (response) { });
  306. }
  307. });
  308. }
  309. loadDataComments(versionguid, containerid) {
  310. if (versionguid != "" && versionguid != undefined) {
  311. var instance = this;
  312. var installedappid = Unibase.Themes.Providers.DetailHelper.installedAppId;
  313. this.fileCacheHelper.loadJsFile('platform/automation/managers/rulemanager.js', function () {
  314. var priority = $('.chk_primarylog').is(":checked");
  315. (priority == true) ? $('.Primary_Label').text('Primary') : $('.Primary_Label').text('Secondary');
  316. Unibase.Platform.Automation.Managers.RuleManager.Instance().getTimeLineLogs(versionguid, installedappid, priority).then(function (response) {
  317. let html = "";
  318. if (response.result == null || response.result.length == 0) {
  319. $(`#timelineFilterDropdown_${containerid}`).addClass('d-none');
  320. if (!$(`#timeLineWrap_${containerid}`).find('.alert').length) {
  321. html = '<div class="alert alert-primary alert_nodata text-center mb-0 border-0 w-100" style="border-radius:0">No data available</div>';
  322. $(`#timeLineWrap_${containerid}`).append(html);
  323. }
  324. }
  325. else if (response.result != null) {
  326. instance.Comments = response.result.filter(x => x.EventLogId == 0);
  327. response.result = response.result.filter(x => x.ParentCommentId == 0);
  328. const timelineListEl = $(`#timeLineList_${containerid}`);
  329. timelineListEl.html('');
  330. $(`#timelineBody_${containerid}`).removeClass('d-none');
  331. for (var i = 0; i < response.result.length; i++) {
  332. html = "";
  333. let username = response.result[i].UserName;
  334. var id = username + "_" + moment(response.result[i].CreatedDate).format("DDMMYYYYHHmm");
  335. id = id.replace(/\s/g, '');
  336. const timeLineDate = moment(response.result[i].CreatedDate).format("DD-MM-YYYY");
  337. html = Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadCommentsAndTimeLineLogs(response.result[i], id);
  338. if (html == '') {
  339. continue;
  340. }
  341. id = id + "_" + instance.EventType;
  342. var formatdate = moment(response.result[i].CreatedDate).format("DD MMM YYYY");
  343. if ($(timelineListEl).find('.timeLineByDate_' + timeLineDate).length == 0) {
  344. timelineListEl.append(`<li id="timeLineByDate_${timeLineDate} " class="timeline-by-date-item timeLineByDate_${timeLineDate}" data-date="${timeLineDate}"><div style="width: 100%; height: 15px; border-bottom: 1px solid black; text-align: center; margin-bottom:30px;">
  345. <span style="font-size:15px;background-color:white;padding: 0 5px;">
  346. ${formatdate}
  347. </span>
  348. </div><ul id="timeLineByDateList_${timeLineDate}" class="timeline-by-date-list d-flex flex-column r-gap-10"></ul></li>`);
  349. }
  350. if (instance.EventType == "Comment" || $('#timelineItem_' + id).length == 0) {
  351. timelineListEl.find(`#timeLineByDateList_${timeLineDate}`).append(html);
  352. }
  353. else {
  354. timelineListEl.find(`#timelineItem_${id}`).find('.ul_' + id).append(`<li class="timeline_data"><span class="timeline-note">${instance.EventNote}</span></li>`);
  355. }
  356. }
  357. timelineListEl.find('.timeline-item:gt(10)').addClass("d-none");
  358. timelineListEl.find('.timeline-by-date-item').each(function (i, e) {
  359. if (!$(e).find('.timeline-item:visible').length) {
  360. $(e).addClass('d-none');
  361. }
  362. });
  363. if (timelineListEl.find('.timeline-item').length > 10) {
  364. timelineListEl.append(`<div id="loadMoreTimelineBtn_${containerid}" class="btn btn-sm btn-outline-primary mx-auto" onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadMoreTimeline('${containerid}');">Load more</div>`);
  365. }
  366. instance.removeDuplicateFilterOptions(containerid);
  367. instance.timelineTxtTrim(containerid);
  368. }
  369. });
  370. });
  371. }
  372. }
  373. saveComment(versionguid, containerid) {
  374. const instance = this;
  375. const commentInputEl = $(`#timelineCommentInput_${containerid}`);
  376. const enteredComment = commentInputEl.val().toString().trim();
  377. var parentCommentId = Number($(commentInputEl).attr("data-parentcommentid"));
  378. if (!enteredComment) {
  379. MessageHelper.Instance().showError("Please Enter Something...", `timeLineErrMsg_${containerid}`);
  380. return false;
  381. }
  382. const postData = {
  383. CommentId: 0,
  384. RefGuid: versionguid,
  385. CommentSubject: enteredComment,
  386. CommentType: Unibase.Platform.Automation.Enums.CommentType.Comment,
  387. Followers: null,
  388. InstallPageId: Unibase.Themes.Providers.DetailHelper.installedAppId,
  389. ParentId: parentCommentId
  390. };
  391. Unibase.Platform.Automation.Managers.CommentManager.Instance().saveComment(postData).then(function (response) {
  392. if (response.status == Unibase.Data.Status.Error) {
  393. MessageHelper.Instance().showError(response.message, `timeLineErrMsg_${containerid}`);
  394. return false;
  395. }
  396. if (response.result) {
  397. var element = $(`#timeLineList_${instance.containerid}`);
  398. var obj = {
  399. EventLogId: 0,
  400. EventId: 0,
  401. CreatedDate: response.result.CreatedDate,
  402. EventTypeId: 10,
  403. UserName: response.result.FromUserName,
  404. UserPhotoPath: response.result.FromUserPhotoUrl,
  405. EventTemplateNote: null,
  406. SecondaryTemplateNote: null,
  407. CommentId: response.result.CommentId,
  408. ParentCommentId: response.result.ParentId,
  409. ParentUserId: 0,
  410. CommentSubject: response.result.CommentSubject,
  411. CreatedBy: Unibase.Platform.Membership.Infos.Identity.currentUser.userId
  412. };
  413. instance.Comments.push(obj);
  414. var id = response.result.FromUserName + "_" + moment(obj.CreatedDate).format("DDMMYYYYHHmm") + "_Comment";
  415. id = id.replace(/\s/g, '');
  416. const timeLineDate = moment(obj.CreatedDate).format("DD-MM-YYYY");
  417. var html = instance.loadCommentsAndTimeLineLogs(obj, id);
  418. if (parentCommentId != 0) {
  419. $(element).find('.childwithparent_' + parentCommentId).append(html);
  420. var count = Number($(element).find('.childwithparent_' + parentCommentId).parent().find('.rplybtn_' + parentCommentId).attr('data-childcount')) + 1;
  421. $(element).find('.childwithparent_' + parentCommentId).parent().find('.rplybtn_' + parentCommentId).attr('data-childcount', count);
  422. $(element).find('.childwithparent_' + parentCommentId).parent().find('.rplybtn_' + parentCommentId).text('Replies (' + count + ')');
  423. }
  424. else {
  425. var formatdate = moment(obj.CreatedDate).format("DD MMM YYYY");
  426. if ($(element).find('.timeLineByDate_' + timeLineDate).length == 0) {
  427. element.prepend(`<li id="timeLineByDate_${timeLineDate} " class="timeline-by-date-item timeLineByDate_${timeLineDate}" data-date="${timeLineDate}"><div style="width: 100%; height: 15px; border-bottom: 1px solid black; text-align: center; margin-bottom:30px;">
  428. <span style="font-size:15px;background-color:white;padding: 0 5px;">
  429. ${formatdate}
  430. </span>
  431. </div><ul id="timeLineByDateList_${timeLineDate}" class="timeline-by-date-list d-flex flex-column r-gap-10"></ul></li>`);
  432. }
  433. if ($(element).find('.timeLineByDate_' + timeLineDate).find('.timeline-item').length == 0) {
  434. $(element).find('.timeLineByDate_' + timeLineDate).append(html);
  435. }
  436. else {
  437. $(element).find('.timeLineByDate_' + timeLineDate).find('.timeline-item:eq(0)').before(html);
  438. }
  439. }
  440. commentInputEl.val('');
  441. $('.timeline-body').removeClass('d-none');
  442. $('.alert_nodata').addClass('d-none');
  443. $(`#saveCommentBtn_${containerid}`).addClass('d-none');
  444. MessageHelper.Instance().showSuccess("Comment Saved Successfully", "");
  445. instance.removeDuplicateFilterOptions(containerid);
  446. }
  447. $(commentInputEl).attr("data-parentcommentid", 0);
  448. });
  449. }
  450. replyComments(CommentId) {
  451. var instance = this;
  452. var element = $(`#timeLineList_${instance.containerid}`);
  453. var ChildComments = instance.Comments.filter(x => x.ParentCommentId == CommentId);
  454. if (ChildComments.length > 0 && $(element).find('.childwithparent_' + CommentId).find('li').length == 0) {
  455. for (let i = 0; i < ChildComments.length; i++) {
  456. var randomid = `${Date.now()}_${moment().unix()}`;
  457. var html = Unibase.Platform.TimeLine.Components.TimeLine.Instance().loadCommentsAndTimeLineLogs(ChildComments[i], randomid);
  458. $(element).find('.childwithparent_' + CommentId).append(html);
  459. instance.removeDuplicateFilterOptions(instance.containerid);
  460. }
  461. }
  462. else {
  463. var result = instance.Comments.find(x => x.CommentId = CommentId);
  464. var text = "@" + result.UserName;
  465. $(`#timelineCommentInput_${instance.containerid}`).val(text);
  466. $(`#timelineCommentInput_${instance.containerid}`).attr("data-parentcommentid", CommentId);
  467. $('.save-comment-btn').removeClass('d-none');
  468. }
  469. }
  470. loadCommentsAndTimeLineLogs(response, randIDGen) {
  471. var html = "", instance = this, icon = "", filterType = "", deleteIcon = "", commentClass = "";
  472. const timeLineDate = moment(response.CreatedDate).format("DD-MM-YYYY");
  473. var localdate = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate(response.CreatedDate);
  474. var datewithT = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateTimeWithT(response.CreatedDate);
  475. const timeLineTime = datewithT.replace(localdate, '');
  476. instance.stageReasons = "";
  477. const eventTypeId = response.EventTypeId;
  478. if (eventTypeId == Number(Unibase.Platform.Automation.Enums.EventType.Created)) {
  479. icon = 'fa fa-plus', filterType = 'Create';
  480. }
  481. else if (eventTypeId == Number(Unibase.Platform.Automation.Enums.EventType.Updated)) {
  482. icon = 'fa fa-pencil', filterType = 'Updated';
  483. }
  484. else if (eventTypeId == Number(Unibase.Platform.Automation.Enums.EventType.Deleted)) {
  485. icon = 'fa fa-trash', filterType = 'Deleted';
  486. }
  487. else if (eventTypeId == Number(Unibase.Platform.Automation.Enums.EventType.Comment)) {
  488. icon = 'fa fa-comment', filterType = 'Comment', deleteIcon = Unibase.Platform.Membership.Infos.Identity.currentUser.userId == response.CreatedBy ? `<i class='fa fa-trash-o text-danger font-16 'onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().deleteComment(${response.CommentId})"></i>` : "", commentClass = "Commentli_" + response.CommentId;
  489. }
  490. else if (eventTypeId == Number(Unibase.Platform.Automation.Enums.EventType.StageEvent)) {
  491. icon = 'fa fa-cogs', filterType = 'Changed';
  492. instance.stageReasons = '<span class="reason_div"><a onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().StageChangeReasons(' + response.CommentId + ')"><span class="biz-highlight-bg-color font-12">Reasons</span></a></span>';
  493. }
  494. else {
  495. icon = '', filterType = 'Result Action';
  496. }
  497. instance.EventType = filterType;
  498. let username = response.UserName;
  499. const avatartHtml = instance.setTimelineAvatar(response);
  500. var primarynote = response.EventTemplateNote;
  501. var secondarynote = JSON.parse(response.SecondaryTemplateNote);
  502. var eventtemplate = primarynote == null ? secondarynote : primarynote;
  503. var Event = "", EventNote = "";
  504. if (response.EventId != 0 && eventtemplate == null) {
  505. return html = '';
  506. }
  507. if (eventtemplate != null) {
  508. Event = eventtemplate.EventName.split("_");
  509. instance.EventType = Event[Event.length - 1];
  510. Event = Event[Event.length - 2] + " " + Event[Event.length - 1];
  511. EventNote = eventtemplate.NotesText.toLowerCase();
  512. var OldValue = response.OldValue;
  513. var NewValue = response.NewValue;
  514. if (response.Keys != "{}" && response.Keys != null) {
  515. let Keys = JSON.parse(response.Keys);
  516. var objectprop = Object.getOwnPropertyNames(Keys);
  517. for (let k = 0; k < objectprop.length; k++) {
  518. EventNote = EventNote.replaceAll('{{' + objectprop[k].toLowerCase() + '}}', Keys[objectprop[k]]);
  519. }
  520. }
  521. if (EventNote.indexOf("{{oldvalue}}") != -1) {
  522. EventNote = EventNote.replace("{{oldvalue}}", OldValue);
  523. }
  524. if (EventNote.indexOf("{{newvalue}}") != -1) {
  525. EventNote = EventNote.replace("{{newvalue}}", NewValue);
  526. }
  527. if (EventNote.match('{{.*}}')) {
  528. EventNote = EventNote.replaceAll('{{', '').replaceAll('}}', '');
  529. }
  530. if (eventtemplate.EventAliasName != '') {
  531. Event = eventtemplate.EventAliasName;
  532. }
  533. instance.EventNote = EventNote;
  534. }
  535. else if (eventtemplate == null && response.EventLogId == 0) {
  536. instance.EventType = "Comment";
  537. var childtext = "Reply";
  538. var childcount = instance.Comments.filter(x => x.ParentCommentId == response.CommentId).length;
  539. if (childcount > 0) {
  540. childtext = "Replies (" + childcount + ")";
  541. }
  542. EventNote = `<b>${response.CommentSubject}</b><div class="replaycomment"><a class="rplybtn_${response.CommentId}" data-childcount=${childcount} href="javascript:(0)" data-parentcommentid='${response.CommentId}' onclick="Unibase.Platform.TimeLine.Components.TimeLine.Instance().replyComments(${response.CommentId})">${childtext}</a><ul class="childwithparent_${response.CommentId}"></ul></div>`;
  543. }
  544. randIDGen = randIDGen + "_" + instance.EventType;
  545. html += `<li id="timelineItem_${randIDGen}" class="filtersearch pb-2 timelineItem_${randIDGen} timeline-item ${commentClass} my-1 my-md-0 mb-2 filterLi ${filterType} ${timeLineDate}" data-filterType="${filterType}" data-filterdate="${timeLineDate}"><div class="d-flex c-gap-10"><div class="avatar avatar-sm flex-shrink-0 timeline-avatar" data-tooltip="true" title="${username}">${avatartHtml}<span class="btn btn-icon btn-icon-circle btn-primary btn-xs d-20 timeline_icon_wrap" data-tooltip="true" title="${filterType}"><span class="btn-icon-wrap"><i class="${icon} font-10"></i></span></span></div><div class="d-flex flex-grow-1 c-gap-10 mnw-0"><div class="timeline_desc text-dark w-100 mnw-0 d-flex flex-column r-gap-5 font-12"><h6 class="text-capitalize font-14 time_title">${Event}</h6><ul class="timelineContainer text-light-80 ul_${randIDGen}"><li class="timeline_data"><span class="timeline-note">${EventNote}</span></li></ul>${instance.stageReasons}${response.ParentUserId ? `<span class="logged-from-div biz-highlight-bg-color font-12">logged from ${response.ParentUserName} to ${username}</span>` : ''}</div>${deleteIcon}<span class="timeline_date flex-shrink-0">${timeLineTime}</span></div></div></li>`;
  546. var eventfilterhtml = `<option value='${filterType}'>${filterType}</option>`;
  547. var timefilterhtml = `<option value='${timeLineDate}'>${timeLineDate}</option>`;
  548. $(`#eventFilterSelect_${instance.containerid}`).append(eventfilterhtml);
  549. $(`#dateFilterSelect_${instance.containerid}`).append(timefilterhtml);
  550. return html;
  551. }
  552. deleteComment(CommentId) {
  553. var instance = this;
  554. Unibase.Platform.Automation.Managers.CommentManager.Instance().deleteComment(CommentId).then(function (response) {
  555. if (response.status == Unibase.Data.Status.Success) {
  556. var parentCommentId = instance.Comments.find(x => x.CommentId == CommentId)["ParentCommentId"];
  557. var date = $('.Commentli_' + CommentId).attr('data-filterdate');
  558. $('.Commentli_' + CommentId).remove();
  559. if ($('.timeLineByDate_' + date).find('.timeline-item').length == 0) {
  560. $('.timeLineByDate_' + date).remove();
  561. }
  562. if (parentCommentId != 0) {
  563. var count = Number($('.childwithparent_' + parentCommentId).parent().find('.rplybtn_' + parentCommentId).attr('data-childcount')) - 1;
  564. var text = "Reply";
  565. if (count > 0) {
  566. text = "Replies (" + count + ")";
  567. }
  568. $('.childwithparent_' + parentCommentId).parent().find('.rplybtn_' + parentCommentId).attr('data-childcount', count);
  569. $('.childwithparent_' + parentCommentId).parent().find('.rplybtn_' + parentCommentId).text(text);
  570. }
  571. instance.Comments = instance.Comments.filter(x => x.CommentId != CommentId && x.ParentCommentId != CommentId);
  572. MessageHelper.Instance().showSuccess("Successfully comment deleted", "");
  573. }
  574. else {
  575. alert("Failed To Delete Comment");
  576. }
  577. });
  578. }
  579. static Instance() {
  580. if (this.instance === undefined) {
  581. this.instance = new TimeLine();
  582. }
  583. return this.instance;
  584. }
  585. }
  586. Components.TimeLine = TimeLine;
  587. })(Components = TimeLine_1.Components || (TimeLine_1.Components = {}));
  588. })(TimeLine = Platform.TimeLine || (Platform.TimeLine = {}));
  589. })(Platform = Unibase.Platform || (Unibase.Platform = {}));
  590. })(Unibase || (Unibase = {}));