diff --git a/app/Http/Controllers/ConversationsController.php b/app/Http/Controllers/ConversationsController.php index 27dcbbfa9..8cb3c9734 100755 --- a/app/Http/Controllers/ConversationsController.php +++ b/app/Http/Controllers/ConversationsController.php @@ -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; diff --git a/public/css/style.css b/public/css/style.css index d91523b7a..840d242b5 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -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; diff --git a/public/js/main.js b/public/js/main.js index ef625c507..d40cf398a 100755 --- a/public/js/main.js +++ b/public/js/main.js @@ -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'), @@ -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 = '
' + +checkbox_container[0].outerHTML + +'
'; + + 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); }); } diff --git a/resources/views/conversations/ajax_html/merge_conv.blade.php b/resources/views/conversations/ajax_html/merge_conv.blade.php index 516628e46..1f215b55d 100644 --- a/resources/views/conversations/ajax_html/merge_conv.blade.php +++ b/resources/views/conversations/ajax_html/merge_conv.blade.php @@ -39,7 +39,7 @@ @foreach ($prev_conversations as $prev_conversation) -
#{{ $prev_conversation->number }} {{ $prev_conversation->getSubject() }}
+
#{{ $prev_conversation->number }} {{ $prev_conversation->getSubject() }}
@endforeach @@ -47,6 +47,10 @@ @endif -
+
+ +
+ +
\ No newline at end of file diff --git a/resources/views/conversations/partials/merge_search_result.blade.php b/resources/views/conversations/partials/merge_search_result.blade.php index 1a7e40608..aabe17958 100644 --- a/resources/views/conversations/partials/merge_search_result.blade.php +++ b/resources/views/conversations/partials/merge_search_result.blade.php @@ -1 +1 @@ -
#{{ $conversation->number }} {{ $conversation->getSubject() }}
\ No newline at end of file +
#{{ $conversation->number }} {{ $conversation->getSubject() }}
\ No newline at end of file