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 = '