From eb6b314861bd416f671b57066d022a2d041ec299 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Thu, 12 May 2016 00:25:25 +0000 Subject: [PATCH] collabs: Thread Collaborators Update Fix a bug where it was impossible to disable ALL collaborators Change recipients active/total count on update --- include/ajax.thread.php | 10 +++++++--- include/class.thread.php | 16 +++++++--------- include/staff/ticket-view.inc.php | 3 ++- scp/js/scp.js | 5 +++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/ajax.thread.php b/include/ajax.thread.php index 470f9276e..7850c67c0 100644 --- a/include/ajax.thread.php +++ b/include/ajax.thread.php @@ -230,9 +230,13 @@ class ThreadAjaxAPI extends AjaxController { $errors = $info = array(); if ($thread->updateCollaborators($_POST, $errors)) - Http::response(201, sprintf('Recipients (%d of %d)', - $thread->getNumActiveCollaborators(), - $thread->getNumCollaborators())); + Http::response(201, $this->json_encode(array( + 'id' => $thread->getId(), + 'text' => sprintf('Recipients (%d of %d)', + $thread->getNumActiveCollaborators(), + $thread->getNumCollaborators()) + ) + )); if($errors && $errors['err']) $info +=array('error' => $errors['err']); diff --git a/include/class.thread.php b/include/class.thread.php index 31b2c5c3d..b6fc9b5f1 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -197,15 +197,13 @@ class Thread extends VerySimpleModel { )); } - if ($cids) { - $this->collaborators->filter(array( - 'thread_id' => $this->getId(), - Q::not(array('id__in' => $cids)) - ))->update(array( - 'updated' => SqlFunction::NOW(), - 'isactive' => 0, - )); - } + $this->collaborators->filter(array( + 'thread_id' => $this->getId(), + Q::not(array('id__in' => $cids ?: array(0))) + ))->update(array( + 'updated' => SqlFunction::NOW(), + 'isactive' => 0, + )); unset($this->ht['active_collaborators']); $this->_collaborators = null; diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 36c1d34ef..62ac75e11 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -583,7 +583,8 @@ if ($errors['err'] && isset($_POST['a'])) { <label><strong><?php echo __('Collaborators'); ?>:</strong></label> </td> <td> - <input type='checkbox' value='1' name="emailcollab" id="emailcollab" + <input type='checkbox' value='1' name="emailcollab" + id="t<?php echo $ticket->getThreadId(); ?>-emailcollab" <?php echo ((!$info['emailcollab'] && !$errors) || isset($info['emailcollab']))?'checked="checked"':''; ?> style="display:<?php echo $ticket->getThread()->getNumCollaborators() ? 'inline-block': 'none'; ?>;" > diff --git a/scp/js/scp.js b/scp/js/scp.js index 1e2dfa304..3c04b4a9c 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -987,8 +987,9 @@ $(document).on('click', 'a.collaborator, a.collaborators', function(e) { e.preventDefault(); var url = 'ajax.php/'+$(this).attr('href').substr(1); $.dialog(url, 201, function (xhr) { - $('input#emailcollab').show(); - $('#recipients').text(xhr.responseText); + var resp = $.parseJSON(xhr.responseText); + $('input#t'+resp.id+'-emailcollab').show(); + $('#t'+resp.id+'-recipients').text(resp.text); $('.tip_box').remove(); }, { onshow: function() { $('#user-search').focus(); } -- GitLab