Skip to content

Commit

Permalink
Merge multiple conversations at once - closes #3516
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Nov 24, 2023
1 parent 0c614c3 commit fbe3a79
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 17 deletions.
39 changes: 28 additions & 11 deletions app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2141,20 +2141,37 @@ public function ajax(Request $request)
$response['msg'] = __('Not enough permissions');
}

$merge_conversation = Conversation::find($request->merge_conversation_id);
if (!empty($request->merge_conversation_id) && is_array($request->merge_conversation_id)) {

$sigle_conv = count($request->merge_conversation_id) == 1;

if (!$merge_conversation) {
$response['msg'] = __('Conversation not found');
}
if (!$response['msg'] && !$user->can('view', $merge_conversation)) {
$response['msg'] = __('Not enough permissions');
}
foreach ($request->merge_conversation_id as $merge_conversation_id) {
$merge_conversation = Conversation::find($merge_conversation_id);

if (!$response['msg']) {
$conversation->mergeConversations($merge_conversation, $user);
$response['msg'] = '';

$response['status'] = 'success';
\Session::flash('flash_success_floating', __('Conversations merged'));
if (!$merge_conversation) {
$response['msg'] = __('Conversation not found');
if ($sigle_conv) {
break;
}
}
if (!$response['msg'] && !$user->can('view', $merge_conversation)) {
$response['msg'] = __('Not enough permissions').': #'.$merge_conversation->number;
if ($sigle_conv) {
break;
}
}

if (!$response['msg']) {
$conversation->mergeConversations($merge_conversation, $user);

if ($response['status'] != 'success') {
\Session::flash('flash_success_floating', __('Conversations merged'));
}
$response['status'] = 'success';
}
}
}

break;
Expand Down
8 changes: 6 additions & 2 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4325,11 +4325,15 @@ a.disabled:focus {
max-height: 200px;
overflow-y: auto;
}
.conv-merge-list .radio,
.conv-merge-search-result .radio {
.conv-merge-list .checkbox,
.conv-merge-search-result .checkbox,
.conv-merge-selected .checkbox {
margin-top: 0;
margin-bottom: 0;
}
.conv-merge-selected .alert {
margin-bottom: 10px;
}
.conv-tags {
float: left;
overflow: hidden;
Expand Down
45 changes: 44 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3040,9 +3040,18 @@ function initMergeConv()

button.button('loading');

var conv_ids = [];
$('.conv-merge-selected:visible:first .conv-merge-id:checked').each(function() {
conv_ids.push($(this).val());
});

if (!conv_ids.length) {
return;
}

fsAjax({
action: 'conversation_merge',
merge_conversation_id: $('.conv-merge-id:checked').val(),
merge_conversation_id: conv_ids,
conversation_id: getGlobalAttr('conversation_id')
},
laroute.route('conversations.ajax'),
Expand Down Expand Up @@ -3093,6 +3102,40 @@ function initMergeConvSelect()
{
$('.conv-merge-id').click(function() {
$('.btn-merge-conv:visible:first').removeAttr('disabled');

var checkbox_container = $(this).parent();
var selected_list = $('.conv-merge-selected:visible:first');
var clicked_conv_id = parseInt($(this).val());

// Do not add same conversation twice
if (!isNaN(clicked_conv_id) && !selected_list.children().find('.conv-merge-id[value="'+parseInt($(this).val())+'"]').length) {

var html = '<div class="alert alert-narrow alert-info">'
+checkbox_container[0].outerHTML
+'</div>';

selected_list.append(html);

// Remove conv from selected list
selected_list.children().find('.conv-merge-id:last').attr('checked', 'checked').click(function(e){
$('.conv-merge-list:visible:first').children()
.find('.conv-merge-id[value="'+parseInt($(this).val())+'"]:first')
.parents('tr:first').show();
$(this).parent().parent().remove();

if (!selected_list.children().find('.conv-merge-id').length) {
$('.btn-merge-conv:visible:first').attr('disabled', 'disabled');
}
});
}

if ($(this).hasClass('conv-merge-searched')) {
$('.conv-merge-search-result:first').addClass('hidden');
} else {
checkbox_container.parents('tr:first').hide();
}

$(this).prop("checked", false);
});
}

Expand Down
8 changes: 6 additions & 2 deletions resources/views/conversations/ajax_html/merge_conv.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@
@foreach ($prev_conversations as $prev_conversation)
<tr>
<td>
<div class="radio"><input type="radio" class="conv-merge-id" name="conv_merge" value="{{ $prev_conversation->id }}" /><a href="{{ $prev_conversation->url() }}" target="_blank" data-toggle="tooltip" title="{{ __('Click to view') }}"><strong>#{{ $prev_conversation->number }}</strong> {{ $prev_conversation->getSubject() }}</a></div>
<div class="checkbox"><input type="checkbox" class="conv-merge-id" value="{{ $prev_conversation->id }}" /><a href="{{ $prev_conversation->url() }}" target="_blank" data-toggle="tooltip" title="{{ __('Click to view') }}"><strong>#{{ $prev_conversation->number }}</strong> {{ $prev_conversation->getSubject() }}</a></div>
</td>
</tr>
@endforeach
</table>
</div>
@endif

<div class="form-group margin-top">
<div class="form-group conv-merge-selected margin-top">

</div>

<div class="form-group margin-top-10">
<button class="btn btn-primary btn-merge-conv" data-loading-text="{{ __('Merge') }}" type="submit" disabled>{{ __('Merge') }}</button>
</div>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="radio"><input type="radio" class="conv-merge-id" name="conv_merge" value="{{ $conversation->id }}" /><a href="{{ $conversation->url() }}" target="_blank" data-toggle="tooltip" title="{{ __('Click to view') }}"><strong>#{{ $conversation->number }}</strong> {{ $conversation->getSubject() }}</a></div>
<div class="checkbox"><input type="checkbox" class="conv-merge-id conv-merge-searched" value="{{ $conversation->id }}" /><a href="{{ $conversation->url() }}" target="_blank" data-toggle="tooltip" title="{{ __('Click to view') }}"><strong>#{{ $conversation->number }}</strong> {{ $conversation->getSubject() }}</a></div>

0 comments on commit fbe3a79

Please sign in to comment.