diff --git a/app/Http/Controllers/ConversationsController.php b/app/Http/Controllers/ConversationsController.php index 55902dbfd..c9ca9a125 100755 --- a/app/Http/Controllers/ConversationsController.php +++ b/app/Http/Controllers/ConversationsController.php @@ -2276,6 +2276,36 @@ public function ajax(Request $request) break; + case 'load_customer_info': + $customer = Customer::getByEmail($request->customer_email); + + if ($customer) { + // Previous conversations + $prev_conversations = []; + + $mailbox = Mailbox::find($request->mailbox_id); + + if ($mailbox && $mailbox->userHasAccess($user->id)) { + $conversation_id = (int)$request->conversation_id ?? 0; + + $prev_conversations = $mailbox->conversations() + ->where('customer_id', $customer->id) + ->where('id', '<>', $conversation_id) + ->where('status', '!=', Conversation::STATUS_SPAM) + ->where('state', Conversation::STATE_PUBLISHED) + //->limit(self::PREV_CONVERSATIONS_LIMIT) + ->orderBy('created_at', 'desc') + ->paginate(self::PREV_CONVERSATIONS_LIMIT); + } + + $response['html'] = \View::make('conversations/partials/customer_sidebar')->with([ + 'customer' => $customer, + 'prev_conversations' => $prev_conversations, + ])->render(); + $response['status'] = 'success'; + } + break; + default: $response['msg'] = 'Unknown action'; break; diff --git a/public/js/main.js b/public/js/main.js index a07506d51..edc34fcd6 100755 --- a/public/js/main.js +++ b/public/js/main.js @@ -1764,6 +1764,36 @@ function convEditorInit() }).blur(function(event) { onReplyBlur(); }); + + // New conversation: load customer info + $("#to").on('change', function(event) { + var to = $('#to').val() + //var clean_customer = true; + // Do not clean customer info if customer has not changed + /*if (Array.isArray(to) && to.length == 1 && typeof(to[0]) != "undefined") { + if (to[0] == $('#conv-layout-customer li.customer-email:first').text()) { + clean_customer = false; + } + } + if (clean_customer) {*/ + $('#conv-layout-customer').html(''); + // Load customer info + if (Array.isArray(to) && to.length == 1 && typeof(to[0]) != "undefined") { + fsAjax({ + action: 'load_customer_info', + customer_email: to[0], + mailbox_id: getGlobalAttr('mailbox_id'), + conversation_id: getGlobalAttr('conversation_id') + }, laroute.route('conversations.ajax'), function(response) { + if (isAjaxSuccess(response) && typeof(response.html) != "undefined") { + $('#conv-layout-customer').html(response.html); + } + }, true, function() { + // Do nothing + }); + } + }); + // select2 does not react on keyup or keypress $(".recipient-select, .draft-changer").on('change', function(event) { onReplyChange(); diff --git a/resources/views/conversations/partials/customer_sidebar.blade.php b/resources/views/conversations/partials/customer_sidebar.blade.php index 9ff4b979b..2ea8f187d 100644 --- a/resources/views/conversations/partials/customer_sidebar.blade.php +++ b/resources/views/conversations/partials/customer_sidebar.blade.php @@ -1,30 +1,36 @@ @if (!empty($customer))
- @include('customers/profile_snippet', ['customer' => $customer, 'main_email' => $conversation->customer_email, 'conversation' => $conversation]) - + @include('customers/profile_snippet', ['customer' => $customer, 'main_email' => $conversation->customer_email ?? '', 'conversation' => $conversation ?? null]) + @if (isset($conversation)) + + @endif {{--
--}}
- @action('conversation.before_prev_convs', $customer, $conversation, $mailbox) + @if (isset($conversation) && isset($mailbox)) + @action('conversation.before_prev_convs', $customer, $conversation, $mailbox) + @endif @if (count($prev_conversations)) @include('conversations/partials/prev_convs_short') @endif - @action('conversation.after_prev_convs', $customer, $conversation, $mailbox) + @if (isset($conversation) && isset($mailbox)) + @action('conversation.after_prev_convs', $customer, $conversation, $mailbox) + @endif @endif \ No newline at end of file