Skip to content

Commit d240be4

Browse files
committed
Add by default all previously used recipients in ticket
1 parent e3f3ed7 commit d240be4

6 files changed

Lines changed: 67 additions & 18 deletions

File tree

src/Controllers/TicketsController.php

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ public function create($parameters = null)
653653

654654
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getNewTicketCategories();
655655

656+
$data['a_notifications'] = [
657+
'note' => ($data['a_current']['agent_id'] != auth()->user()->id ? [$data['a_current']['agent_id']] : []),
658+
'reply' => ($data['a_current']['owner_id'] != auth()->user()->id ? [$data['a_current']['owner_id']] : [])
659+
];
660+
656661
return view('panichd::tickets.createedit', $data);
657662
}
658663

@@ -676,8 +681,27 @@ public function edit($id, $parameters = null)
676681
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
677682

678683
$member = $this->member->find(auth()->user()->id);
679-
$data['comments'] = $ticket->comments()->forLevel($member->levelInCategory($ticket->category_id))->orderBy('id','desc')->paginate(Setting::grab('paginate_items'));
680684

685+
// Ticket comments
686+
$all_comments = $ticket->comments();
687+
$comments = clone $all_comments;
688+
$data['comments'] = $comments->forLevel($member->levelInCategory($ticket->category_id))->orderBy('id','desc')->paginate(Setting::grab('paginate_items'));
689+
690+
// Default notification recipients
691+
$all_c = clone $all_comments;
692+
$a_reply = [(!is_null($ticket->owner) ? $ticket->owner->id : $ticket->user_id)];
693+
$a_note = [$ticket->agent->id];
694+
foreach($all_c->get() as $comm){
695+
if ($comm->type == 'reply'){
696+
$a_reply = array_merge($a_reply, $comm->notifications->pluck('member_id')->toArray());
697+
}elseif($comm->type == 'note'){
698+
$a_note = array_merge($a_note, $comm->notifications->pluck('member_id')->toArray());
699+
}
700+
}
701+
$data['a_notifications'] = [
702+
'note' => array_unique($a_note),
703+
'reply' => array_unique($a_reply)
704+
];
681705

682706
return view('panichd::tickets.createedit', $data);
683707
}
@@ -1250,12 +1274,34 @@ public function show($id)
12501274

12511275
$agent_lists = $this->agentList($ticket->category_id);
12521276

1253-
$comments = $ticket->comments()->with('notifications')->forLevel($member->levelInCategory($ticket->category_id))->orderBy('id','desc')->paginate(Setting::grab('paginate_items'));
1277+
$all_comments = $ticket->comments()->with('notifications')->forLevel($member->levelInCategory($ticket->category_id));
1278+
$comments = clone $all_comments;
1279+
$comments = $comments->orderBy('id','desc')->paginate(Setting::grab('paginate_items'));
1280+
1281+
$a_notifications = ['reply' => [], 'note' => []];
1282+
1283+
if($member->currentLevel() > 1 && $member->canManageTicket($ticket->id)){
1284+
$all_c = clone $all_comments;
1285+
$a_reply = [(!is_null($ticket->owner) ? $ticket->owner->id : $ticket->user_id)];
1286+
$a_note = [$ticket->agent->id];
1287+
foreach($all_c->get() as $comm){
1288+
if($comm->type == 'note'){
1289+
$a_note = array_merge($a_note, $comm->notifications->pluck('member_id')->toArray());
1290+
}elseif ($comm->type == 'reply'){
1291+
$a_reply = array_merge($a_reply, $comm->notifications->pluck('member_id')->toArray());
1292+
}
1293+
}
1294+
1295+
$a_notifications = [
1296+
'note' => array_unique($a_note),
1297+
'reply' => array_unique($a_reply)
1298+
];
1299+
}
12541300

12551301
$c_members = $this->members_collection($member, false);
12561302

12571303
$data = compact('ticket', 'a_reasons', 'a_tags_selected', 'status_lists', 'complete_status_list', 'agent_lists', 'tag_lists',
1258-
'comments', 'c_members', 'close_perm', 'reopen_perm');
1304+
'comments', 'a_notifications', 'c_members', 'close_perm', 'reopen_perm');
12591305
$data['menu'] = 'show';
12601306
return view('panichd::tickets.show', $data);
12611307
}

src/Public/css/panichd.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ h1, h2, h3, h4, h5, h6 {
151151
* General Select2 styles
152152
*/
153153
#panichd_content .select2-selection {
154-
height: 34px !important;
154+
min-height: 34px !important;
155155
border-color: #ccc !important;
156156
}
157157

src/Views/tickets/createedit.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
@section('footer')
1919
@include('panichd::tickets.createedit.scripts')
20-
@include('panichd::tickets.partials.comments.new_in_createedit_ticket_scripts')
20+
@if ($u->currentLevel() > 1)
21+
@include('panichd::tickets.partials.comments.new_in_createedit_ticket_scripts')
22+
@endif
2123
@include('panichd::tickets.partials.tags_footer_script')
2224
@append

src/Views/tickets/partials/comments/modal_new.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
<div class="form-group row">
3333
<label class="col-lg-2 col-form-label">{{ trans('panichd::lang.show-ticket-add-comment-notificate') . trans('panichd::lang.colon') }}</label>
3434
<div class="col-lg-10">
35-
<select name="note_recipients[]" id="note_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
35+
<select name="reply_recipients[]" id="reply_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
3636
@foreach ($c_members as $member)
37-
<option value="{{ $member->id }}" {{ $member->id == $ticket->agent->id ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
37+
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['reply']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
3838
@if ($setting->grab('departments_notices_feature'))
3939
@if ($member->ticketit_department == '0')
4040
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}
@@ -46,9 +46,9 @@
4646
@endforeach
4747
</select>
4848

49-
<select name="reply_recipients[]" id="reply_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
49+
<select name="note_recipients[]" id="note_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
5050
@foreach ($c_members as $member)
51-
<option value="{{ $member->id }}" {{ !is_null($ticket->owner) && $member->id == $ticket->owner->id ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
51+
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['note']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
5252
@if ($setting->grab('departments_notices_feature'))
5353
@if ($member->ticketit_department == '0')
5454
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}

src/Views/tickets/partials/comments/new_in_createedit_ticket_form.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
<label class="col-lg-2 col-form-label">{{ trans('panichd::lang.show-ticket-add-comment-notificate') . trans('panichd::lang.colon') }}</label>
2929
<div class="col-lg-10">
3030
<select class="form-control note_recipients" name="comment_x_recipients[]" multiple="multiple" style="display: none; width: 100%" disabled="disabled">
31-
@foreach ($c_members as $member)
32-
<option value="{{ $member->id }}" {{ ((isset($ticket) && $member->id == $ticket->agent->id) || (!isset($ticket) && $a_current['agent_id'] != auth()->user()->id && $a_current['agent_id'] == $member->id)) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
31+
@foreach ($c_members->filter(function($q)use($u){ return $q->id != $u->id; }) as $member)
32+
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['note']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
3333
@if ($setting->grab('departments_notices_feature'))
3434
@if ($member->ticketit_department == '0')
3535
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}
@@ -42,8 +42,8 @@
4242
</select>
4343
@php \Debugbar::info($a_current) @endphp
4444
<select class="form-control reply_recipients" name="comment_x_recipients[]" class="form-control" multiple="multiple" style="display: none; width: 100%" disabled="disabled">
45-
@foreach ($c_members as $member)
46-
<option value="{{ $member->id }}" {{ ((isset($ticket) && !is_null($ticket->owner) && $member->id == $ticket->owner->id) || (!isset($ticket) && $a_current['owner_id'] != auth()->user()->id && $a_current['owner_id'] == $member->id)) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
45+
@foreach ($c_members->filter(function($q)use($u){ return $q->id != $u->id; }) as $member)
46+
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['reply']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
4747
@if ($setting->grab('departments_notices_feature'))
4848
@if ($member->ticketit_department == '0')
4949
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}

src/Views/tickets/partials/comments/scripts.blade.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
1010
$('.comment-modal').on('shown.bs.modal', function (e) {
1111
$(this).find('.modal-title').text($(e.relatedTarget).text());
12+
13+
if ($(this).prop('id', 'modal-comment-new')){
14+
// Opening new comment modal
15+
$(this).find('#note_recipients').select2();
16+
}
17+
1218
if ($(e.relatedTarget).data('add-comment') == 'no') $(this).find('#comment-type-buttons').hide();
1319
1420
$(this).find("textarea.modal-summernote-editor").summernote(summernote_options);
@@ -18,11 +24,6 @@
1824
$(this).find("textarea.modal-summernote-editor").summernote('destroy');
1925
});
2026
21-
// Opening new comment modal
22-
$('#modal-comment-new').on('show.bs.modal', function (e) {
23-
$(this).find('#note_recipients').select2();
24-
});
25-
2627
// Comment form: Click on response type buttons (reply or note)
2728
$('.response_type').click(function(){
2829
var type = $(this).attr('data-type');

0 commit comments

Comments
 (0)