var fs_sidebar_menu_applied = false; var fs_loader_timeout; var fs_processing_send_reply = false; var fs_processing_save_draft = false; var fs_send_reply_allowed = true; var fs_send_reply_after_draft = false; var fs_autosave_note = true; var fs_connection_errors = 0; var fs_editor_change_timeout = -1; // For how long to remember conversation note drafts var fs_keep_conversation_notes = 30; // days var fs_draft_autosave_period = 12; // seconds var fs_reply_changed = false; var fs_conv_editor_buttons = {}; var fs_conv_editor_toolbar = [ ['style', ['attachment', 'bold', 'italic', 'underline', 'lists', 'removeformat', 'link', 'picture', 'codeview']], ['actions', ['savedraft', 'discard']], ]; var fs_in_app_data = {}; var fs_actions = {}; var fs_filters = {}; var fs_body_default = '
'+Lang.get("messages.error_occurred")+'
'); } }); }, 500); } } // Show floating error message on ajax error function showAjaxError(response, no_autohide) { var msg = ''; if (typeof(response.msg) != "undefined") { msg = response.msg; } else if (typeof(response.message) != "undefined") { // Standard Laravel error message is returned in [message] msg = response.message; } if (msg) { showFloatingAlert('error', response.msg, no_autohide); } else { showFloatingAlert('error', Lang.get("messages.error_occurred"), no_autohide); } } function initAfterSendModal(modal) { $(document).ready(function() { modal.children().find(".after-send-save:first").click(function(e) { saveAfterSend(e.target); }); }); } // Save default redirect function saveAfterSend(el) { var button = $(el); button.button('loading'); var value = $(el).parents('.modal-body:first').children().find('[name="after_send_default"]:first').val(); var mailbox_id = getGlobalAttr('mailbox_id'); if (!mailbox_id) { mailbox_id = $(el).parents('.modal-body:first').children().find('[name="default_redirect_mailbox_id"]:first').val() } data = { value: value, mailbox_id: mailbox_id, action: 'save_after_send' }; fsAjax(data, laroute.route('conversations.ajax'), function(response) { if (typeof(response.status) != "undefined" && response.status == 'success') { // Show selected option in the dropdown $('.dropdown-after-send [data-after-send='+value+']:first').click(); showFloatingAlert('success', Lang.get("messages.settings_saved")); $('.modal').modal('hide'); } else { showAjaxError(response); } button.button('reset'); }, true); } function viewMailboxInit() { conversationPagination(); starConversationInit(); initMailboxToolbar(); } function initMailboxToolbar() { $(document).ready(function() { // Empty trash $(".mailbox-empty-folder").click(function(e) { showModalDialog('#conversations-bulk-actions-delete-modal', { on_show: function(modal) { modal.children().find('.delete-conversation-ok:first').click(function(e) { var button = $(this); button.button('loading'); fsAjax( { action: 'empty_folder', folder_id: getGlobalAttr('folder_id'), mailbox_id: getGlobalAttr('mailbox_id') }, laroute.route('conversations.ajax'), function(response) { if (isAjaxSuccess(response)) { location.reload(); } else { modal.modal('hide'); showAjaxError(response); } }, true ); e.preventDefault(); }); } }); e.preventDefault(); }); }); } function searchInit() { $(document).ready(function() { // Open all links in new window //$(".conv-row a").attr('target', '_blank'); conversationPagination(); starConversationInit(); customersPagination(); $(".sidebar-menu .menu-link a").filter('[data-filter]').click(function(e){ var trigger = $(this); var filter = trigger.attr('data-filter'); if (!trigger.parent().hasClass('active')) { // Show $('#search-filters div[data-filter="'+filter+'"]:first').addClass('active') .find(':input:first').removeAttr('disabled'); trigger.parent().addClass('active'); } else { // Hide $('#search-filters div[data-filter="'+filter+'"]:first').removeClass('active') .find(':input:first').attr('disabled', 'disabled'); trigger.parent().removeClass('active'); } $('html, body').animate({scrollTop: 0}, 600, 'swing'); e.preventDefault(); }); $("#search-filters .remove").click(function(e){ var container = $(this).parents('.form-group:first'); var filter = container.attr('data-filter'); // Hide $('#search-filters div[data-filter="'+filter+'"]:first').removeClass('active') .find(':input:first').attr('disabled', 'disabled'); $('.sidebar-menu a[data-filter="'+filter+'"]:first').parent().removeClass('active'); e.preventDefault(); }); initCustomerSelector($('#search-filter-customer'), {width: '100%'}); // Dates $('#search-filters .input-date').flatpickr({allowInput: true}); $('#search-filters .filter-multiple').select2({ multiple: true, tags: true // Causes JS error on clear //allowClear: true }); }); } function loadConversations(page, table, no_loader) { var filter = null; var params = {}; var sorting = {}; if ($('body:first').hasClass('body-search')) { filter = { q: getQueryParam('q'), // For search f: getQueryParam('f') // For search }; } //var table = $(this).parents('.table-conversations:first'); if (typeof(table) == "undefined" || table === '') { table = $(".table-conversations:first"); } if (typeof(page) == "undefined" || page === '') { page = table.attr('data-page'); } if (typeof(no_loader) == "undefined") { no_loader = false; } var datas = table.data(); for (data_name in datas) { if (/^filter_/.test(data_name)) { if (filter == null) { filter = {}; } filter[data_name.replace(/^filter_/, '')] = datas[data_name]; } } // Params for (data_name in datas) { if (/^param_/.test(data_name)) { params[data_name.replace(/^param_/, '')] = datas[data_name]; } } // Sorting for (data_name in datas) { if (/^sorting_/.test(data_name)) { sorting[data_name.replace(/^sorting_/, '')] = datas[data_name]; } } if (typeof(URL) != "undefined") { const url = new URL(window.location); url.searchParams.set('page', page); window.history.replaceState({}, '', url); } fsAjax( { action: 'conversations_pagination', mailbox_id: getGlobalAttr('mailbox_id'), folder_id: getGlobalAttr('folder_id'), filter: filter, params: params, page: page, sorting: sorting }, laroute.route('conversations.ajax'), function(response) { if (typeof(response.status) != "undefined" && response.status == 'success') { if (typeof(response.html) != "undefined") { $(".table-conversations:first").replaceWith(response.html); conversationPagination(); starConversationInit(); converstationBulkActionsInit(); convListSortingInit(); triggersInit(); } } else { showAjaxError(response); } loaderHide(); }, no_loader ); } function loadCustomers(page, table) { var filter = null; //var params = {}; if ($('body:first').hasClass('body-search')) { filter = { q: getQueryParam('q'), // For search f: getQueryParam('f') // For search }; } if (typeof(table) == "undefined" || table === '') { table = $(".table-customers:first"); } if (typeof(page) == "undefined" || page === '') { page = table.attr('data-page'); } /*var datas = table.data(); for (data_name in datas) { if (/^filter_/.test(data_name)) { filter[data_name.replace(/^filter_/, '')] = datas[data_name]; } }*/ fsAjax( { action: 'customers_pagination', filter: filter, //params: params, page: page }, laroute.route('customers.ajax'), function(response) { if (isAjaxSuccess(response)) { if (typeof(response.html) != "undefined") { table.replaceWith(response.html); customersPagination(); initModals(); } } else { showAjaxError(response); } loaderHide(); } ); } function conversationPagination() { $(".table-conversations .pager-nav").click(function(e){ loadConversations($(this).attr('data-page'), $(this).parents('.table-conversations:first')); e.preventDefault(); }); } function customersPagination() { $(".table-customers .pager-nav").click(function(e){ loadCustomers($(this).attr('data-page'), $(this).parents('.table-customers:first')); e.preventDefault(); }); } // Change customer modal function changeCustomerInit() { $(document).ready(function() { var input = $(".change-customer-input"); initCustomerSelector(input, { dropdownParent: $('.modal-dialog:visible:first'), multiple: true, placeholder: input.attr('placeholder'), maximumSelectionLength: 1, ajax: { url: laroute.route('customers.ajax_search'), dataType: 'json', delay: 250, cache: true, data: function (params) { return { q: params.term, exclude_email: input.attr('data-customer_email'), search_by: 'all', page: params.page //use_id: true }; } } }); // Show confirmation dialog on customer select input.on('select2:selecting', function (e) { if (typeof(e.params) == "undefined" || typeof(e.params.args.data) == "undefined") { console.log(e); return; } var data = e.params.args.data; //el.select2('close'); var confirm_html = '