diff --git a/assets/components/tickets/js/web/default.js b/assets/components/tickets/js/web/default.js index fe10274..d2aabda 100644 --- a/assets/components/tickets/js/web/default.js +++ b/assets/components/tickets/js/web/default.js @@ -25,7 +25,13 @@ var Tickets = { return false; }); $(document).on('change', '#comments-subscribe', function () { - Tickets.comment.subscribe($('[name="thread"]', $('#comment-form'))); + var thread_id = $(this).parents('.comments-thread').attr('id'); + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+thread_id; + } + Tickets.comment.subscribe($(thread_id + ' [name="thread"]')); }); $(document).on('change', '#tickets-subscribe', function () { Tickets.ticket.subscribe($(this).data('id')); @@ -36,7 +42,8 @@ var Tickets = { return false; }); $(document).on('submit', '#comment-form', function (e) { - Tickets.comment.save(this, $(this).find('[type="submit"]')[0]); + var thread_id = $(this).parents('.comments-thread').attr('id'); + Tickets.comment.save(this, $(this).find('[type="submit"]')[0], thread_id); e.preventDefault(); return false; }); @@ -52,11 +59,12 @@ var Tickets = { return false; }); $(document).on('click touchend', '#comment-form .preview, #comment-form .submit', function (e) { + var thread_id = $(this).parents('.comments-thread').attr('id'); if ($(this).hasClass('preview')) { - Tickets.comment.preview(this.form, this); + Tickets.comment.preview(this.form, this, thread_id); } else { - Tickets.comment.save(this.form, this); + Tickets.comment.save(this.form, this, thread_id); } e.preventDefault(); return false; @@ -74,7 +82,13 @@ var Tickets = { }); // Show and hide forms $(document).on('click touchend', '#comment-new-link a', function (e) { - Tickets.forms.comment(); + var thread_id = $(this).parents('.comments-thread').attr('id'); + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } + Tickets.forms.comment(thread_id); e.preventDefault(); return false; }); @@ -135,22 +149,31 @@ var Tickets = { $('#ticket-editor').markItUp(TicketsConfig.editor.ticket); } if (TicketsConfig.enable_editor == true) { - $('#comment-editor').markItUp(TicketsConfig.editor.comment); + $('.comments-thread').each(function(){ + $(this).find('#comment-editor').markItUp(TicketsConfig.editor.comment); + }) } $.jGrowl.defaults.closerTemplate = '
[ ' + TicketsConfig.close_all_message + ' ]
'; - var count = $('.ticket-comment').length; - $('#comment-total, .ticket-comments-count').text(count); + $('.comments-thread').each(function(){ + var count = $(this).find('.ticket-comment').size(); + $(this).find('#comment-total, .ticket-comments-count').text(count); + }) $("#ticketForm.create").sisyphus({ excludeFields: $('#ticketForm .disable-sisyphus') }); + $('.comments-thread').each(function(){ // Auto hide new comment button - if ($('#comment-form').is(':visible')) { - $('#comment-new-link').hide(); - } + if ($(this).find('#comment-form').is(':visible')) { + $(this).find('#comment-new-link').hide(); + } else { + $(this).find('#comment-form').hide(); + $(this).find('#comment-new-link').show(); + } + }) }); // Link to parent comment @@ -271,7 +294,12 @@ var Tickets = { }, comment: { - preview: function (form, button) { + preview: function(form,button, thread_id) { + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } $(form).ajaxSubmit({ data: {action: 'comment/preview'}, url: TicketsConfig.actionUrl, @@ -285,7 +313,7 @@ var Tickets = { success: function (response) { $(button).removeAttr('disabled'); if (response.success) { - $('#comment-preview-placeholder').html(response.data.preview).show(); + $(thread_id+' #comment-preview-placeholder').html(response.data.preview).show(); prettyPrint(); } else { @@ -296,7 +324,12 @@ var Tickets = { return false; }, - save: function (form, button) { + save: function(form, button, thread_id) { + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } $(form).ajaxSubmit({ data: {action: 'comment/save'}, url: TicketsConfig.actionUrl, @@ -312,21 +345,21 @@ var Tickets = { success: function (response) { $(button).removeAttr('disabled'); if (response.success) { - Tickets.forms.comment(false); - $('#comment-preview-placeholder').html('').hide(); - $('#comment-editor', form).val(''); - $('.ticket-comment .comment-reply a').show(); + Tickets.forms.comment(thread_id, false); + $(thread_id+' #comment-preview-placeholder').html('').hide(); + $(thread_id+' #comment-editor',form).val(''); + $(thread_id+' .ticket-comment .comment-reply a').show(); // autoPublish = 0 if (!response.data.length && response.message) { Tickets.Message.info(response.message); } else { - Tickets.comment.insert(response.data.comment); + Tickets.comment.insert(thread_id, response.data.comment); Tickets.utils.goto($(response.data.comment).attr('id')); } - Tickets.comment.getlist(); + Tickets.comment.getlist(thread_id); prettyPrint(); } else { @@ -350,36 +383,46 @@ var Tickets = { } } if (response.data.captcha) { - $('input[name="captcha"]', form).val('').focus(); - $('#comment-captcha', form).text(response.data.captcha); + $(thread_id+' input[name="captcha"]', form).val('').focus(); + $(thread_id+' #comment-captcha', form).text(response.data.captcha); } } }); return false; }, - getlist: function () { - var form = $('#comment-form'); + getlist: function(thread_id) { + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } + var form = $(thread_id + ' #comment-form'); var thread = $('[name="thread"]', form); if (!thread) { return false; } - Tickets.tpanel.start(); + Tickets.tpanel.start(thread_id); $.post(TicketsConfig.actionUrl, {action: 'comment/getlist', thread: thread.val()}, function (response) { for (var k in response.data.comments) { if (response.data.comments.hasOwnProperty(k)) { - Tickets.comment.insert(response.data.comments[k], true); + Tickets.comment.insert(thread_id, response.data.comments[k], true); } } - var count = $('.ticket-comment').length; - $('#comment-total, .ticket-comments-count').text(count); + var count = $(thread_id + ' .ticket-comment').size(); + $(thread_id + ' #comment-total, '+ thread_id + ' .ticket-comments-count').text(count); - Tickets.tpanel.stop(); + Tickets.tpanel.stop(thread_id); }, 'json'); return true; }, - insert: function (data, remove) { + insert: function(thread_id, data, remove) { + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } var comment = $(data); var parent = $(comment).attr('data-parent'); var id = $(comment).attr('id'); @@ -401,13 +444,13 @@ var Tickets = { } if (parent == 0 && TicketsConfig.formBefore) { - $('#comments').prepend(data) + $(thread_id + ' #comments').prepend(data) } else if (parent == 0) { - $('#comments').append(data) + $(thread_id + ' #comments').append(data) } else { - var pcomm = $('#comment-' + parent); + var pcomm = $(thread_id + ' #comment-'+parent); if (pcomm.data('parent') != pcomm.data('newparent')) { parent = pcomm.data('newparent'); comment.attr('data-newparent', parent); @@ -421,7 +464,7 @@ var Tickets = { data = comment[0].outerHTML; } } - $('#comment-' + parent + ' > .comments-list').append(data); + $(thread_id + ' #comment-'+parent+' > .comments-list').append(data); } if (children.length > 0) { @@ -448,14 +491,20 @@ var Tickets = { forms: { reply: function (comment_id) { - $('#comment-new-link').show(); + var thread_id = $('#comment-'+comment_id).parents('.comments-thread ').attr('id'); + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } + $(thread_id + ' #comment-new-link').show(); clearInterval(window.timer); - var form = $('#comment-form'); + var form = $(thread_id + ' #comment-form'); $('.time', form).text(''); - $('.ticket-comment .comment-reply a').show(); + $(thread_id + ' .ticket-comment .comment-reply a').show(); - $('#comment-preview-placeholder').hide(); + $(thread_id + ' #comment-preview-placeholder').hide(); $('input[name="parent"]', form).val(comment_id); $('input[name="id"]', form).val(0); @@ -469,21 +518,26 @@ var Tickets = { }, comment: function (focus) { + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } if (focus !== false) { focus = true; } clearInterval(window.timer); - $('#comment-new-link').hide(); + $(thread_id).find('#comment-new-link').hide(); - var form = $('#comment-form'); + var form = $(thread_id).find('#comment-form'); $('.time', form).text(''); - $('.ticket-comment .comment-reply a:hidden').show(); + $(thread_id).find('.ticket-comment .comment-reply a:hidden').show(); - $('#comment-preview-placeholder').hide(); + $(thread_id).find('#comment-preview-placeholder').hide(); $('input[name="parent"]', form).val(0); $('input[name="id"]', form).val(0); - $(form).insertAfter('#comment-form-placeholder').show(); + $(form).insertAfter(thread_id + ' #comment-form-placeholder').show(); $('#comment-editor', form).val(''); if (focus) { @@ -493,7 +547,13 @@ var Tickets = { }, edit: function (comment_id) { - $('#comment-new-link').show(); + var thread_id = $('#comment-'+comment_id).parents('.comments-thread ').attr('id'); + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } + $(thread_id).find('#comment-new-link').show(); var thread = $('#comment-form [name="thread"]').val(); $.post(TicketsConfig.actionUrl, { @@ -506,9 +566,9 @@ var Tickets = { } else { clearInterval(window.timer); - $('.ticket-comment .comment-reply a:hidden').show(); - var form = $('#comment-form'); - $('#comment-preview-placeholder').hide(); + $(thread_id + ' .ticket-comment .comment-reply a:hidden').show(); + var form = $(thread_id + ' #comment-form'); + $(thread_id + ' #comment-preview-placeholder').hide(); $('input[name="parent"]', form).val(0); $('input[name="id"]', form).val(comment_id); @@ -743,23 +803,29 @@ Tickets.Star = { Tickets.tpanel = { - wrapper: $('#comments-tpanel'), - refresh: $('#tpanel-refresh'), - new_comments: $('#tpanel-new'), + wrapper: '.comments-thread #comments-tpanel', + refresh: '.comments-thread #tpanel-refresh', + new_comments: '.comments-thread #tpanel-new', class_new: 'ticket-comment-new', initialize: function () { if (TicketsConfig.tpanel) { - this.wrapper.show(); + $(this.wrapper).show(); this.stop(); } - this.refresh.on('click', function () { + $(this.refresh).on('click', function() { + var thread_id = $(this).parents('.comments-thread ').attr('id'); + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } $('.' + Tickets.tpanel.class_new).removeClass(Tickets.tpanel.class_new); - Tickets.comment.getlist(); + Tickets.comment.getlist(thread_id); }); - this.new_comments.on('click', function () { + $(this.new_comments).on('click', function() { var elem = $('.' + Tickets.tpanel.class_new + ':first'); $('html, body').animate({ scrollTop: elem.offset().top @@ -767,29 +833,37 @@ Tickets.tpanel = { elem.removeClass(Tickets.tpanel.class_new); }); - var count = parseInt(Tickets.tpanel.new_comments.text()); + var count = parseInt($(this).text()); if (count > 1) { - Tickets.tpanel.new_comments.text(count - 1); + $(this).text(count - 1); } else { - Tickets.tpanel.new_comments.text('').hide(); + $(this).text('').hide(); } }); }, - start: function () { - this.refresh.addClass('loading'); + start: function(thread_id) { + if (thread_id === undefined){ + thread_id = ''; + } else { + thread_id = '#'+String(thread_id).replace('#', ''); + } + $(thread_id + '' + this.refresh).addClass('loading'); }, - stop: function () { + stop: function(thread_id) { + if (thread_id === undefined){ + thread_id = ''; + } var count = $('.' + this.class_new).length; if (count > 0) { - this.new_comments.text(count).show(); + $(thread_id + '' + this.new_comments).text(count).show(); } else { - this.new_comments.hide(); + $(thread_id + '' + this.new_comments).hide(); } - this.refresh.removeClass('loading'); + $(thread_id + '' + this.refresh).removeClass('loading'); } }; diff --git a/core/components/tickets/elements/snippets/snippet.comments.php b/core/components/tickets/elements/snippets/snippet.comments.php index f3e9820..b8f3a8e 100644 --- a/core/components/tickets/elements/snippets/snippet.comments.php +++ b/core/components/tickets/elements/snippets/snippet.comments.php @@ -193,8 +193,8 @@ ? $modx->lexicon('ticket_thread_err_closed') : $form; $output = !empty($formBefore) - ? $commentForm . $commentsThread - : $commentsThread . $commentForm; + ? '
' . $commentForm . $commentsThread . '
' + : '
' . $commentsThread . $commentForm . '
'; if ($modx->user->hasSessionContext('mgr') && !empty($showLog)) { $output .= '
' . print_r($pdoFetch->getTime(), 1) . '
'; @@ -208,4 +208,4 @@ $modx->setPlaceholder($toPlaceholder, $output); } else { return $output; -} \ No newline at end of file +} diff --git a/core/components/tickets/model/tickets/tickets.class.php b/core/components/tickets/model/tickets/tickets.class.php index a7d2a58..ab6b741 100644 --- a/core/components/tickets/model/tickets/tickets.class.php +++ b/core/components/tickets/model/tickets/tickets.class.php @@ -399,7 +399,7 @@ public function previewComment($data = array()) /** @var modUser $user */ if ($this->authenticated && $user = $this->modx->getObject('modUser', $this->modx->user->id)) { - $comment['name'] = $this->modx->user->Profile->fullname; + $comment['name'] = ($this->modx->user->Profile->fullname == '') ? $this->modx->user->username : $this->modx->user->Profile->fullname; $comment['email'] = $this->modx->user->Profile->email; /** @var modUserProfile $profile */ $profile = $this->modx->user->Profile; @@ -439,7 +439,7 @@ public function saveComment($data = array()) : true; if ($this->authenticated) { if (empty($data['name'])) { - $data['name'] = $this->modx->user->Profile->get('fullname'); + $data['name'] = ($this->modx->user->Profile->get('fullname') == '') ? $this->modx->user->get('username') : $this->modx->user->Profile->get('fullname'); } $data['email'] = $this->modx->user->Profile->get('email'); } else {