From 189ccb21dbef30a13b5ea37a2a4b4a5ef2160a25 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Fri, 29 Oct 2021 14:46:14 +0200 Subject: [PATCH] Fixes #3827 - Ticket create screen will loose attachments by time. --- .../controllers/_ui_element/richtext.coffee | 4 +++ .../controllers/agent_ticket_create.coffee | 9 +++++ spec/system/ticket/create_spec.rb | 35 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/app/assets/javascripts/app/controllers/_ui_element/richtext.coffee b/app/assets/javascripts/app/controllers/_ui_element/richtext.coffee index b7b027ae7..757ebaa03 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/richtext.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/richtext.coffee @@ -27,6 +27,8 @@ class App.UiElement.richtext renderFile = (file) -> item.find('.attachments').append(App.view('generic/attachment_item')(file)) attachments.push file + if form.richTextUploadRenderCallback + form.richTextUploadRenderCallback(attribute, attachments) if params && params.attachments for file in params.attachments @@ -54,6 +56,8 @@ class App.UiElement.richtext return if item.id.toString() is id.toString() item ) + if form.richTextUploadDeleteCallback + form.richTextUploadDeleteCallback(attribute, attachments) form_id = item.closest('form').find('[name=form_id]').val() diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index bd17a3122..51aa377b5 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -283,6 +283,13 @@ class App.TicketCreate extends App.Controller return if !@formMeta App.QueueManager.run(@queueKey) + updateTaskManagerAttachments: (attribute, attachments) => + taskData = App.TaskManager.get(@taskKey) + return if _.isEmpty(taskData) + + taskData.attachments = attachments + App.TaskManager.update(@taskKey, taskData) + render: (template = {}) -> return if !@formMeta # get params @@ -379,6 +386,8 @@ class App.TicketCreate extends App.Controller handlersConfig: handlersTunnel params: params taskKey: @taskKey + richTextUploadRenderCallback: @updateTaskManagerAttachments + richTextUploadDeleteCallback: @updateTaskManagerAttachments ) @controllerFormCreateBottom = new App.ControllerForm( el: @$('.ticket-form-bottom') diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index a5e482186..8ea72afc1 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -779,4 +779,39 @@ RSpec.describe 'Ticket Create', type: :system do end end end + + describe 'Ticket create screen will loose attachments by time #3827' do + before do + visit 'ticket/create' + end + + it 'does not loose attachments on rerender of the ui' do + # upload two files + page.find('input#fileUpload_1', visible: :all).set(Rails.root.join('test/data/mail/mail001.box')) + await_empty_ajax_queue + page.find('input#fileUpload_1', visible: :all).set(Rails.root.join('test/data/mail/mail002.box')) + await_empty_ajax_queue + wait(5).until { page.all('div.attachment-delete.js-delete', visible: :all).count == 2 } + expect(page).to have_text('mail001.box') + expect(page).to have_text('mail002.box') + + # remove last file + begin + page.evaluate_script("$('div.attachment-delete.js-delete:last').click()") # not interactable + rescue # Lint/SuppressedException + # because its not interactable it also + # returns this weird exception for the jquery + # even tho it worked fine + end + await_empty_ajax_queue + wait(5).until { page.all('div.attachment-delete.js-delete', visible: :all).count == 1 } + expect(page).to have_text('mail001.box') + expect(page).to have_no_text('mail002.box') + + # simulate rerender b + page.evaluate_script("App.Event.trigger('ui:rerender')") + expect(page).to have_text('mail001.box') + expect(page).to have_no_text('mail002.box') + end + end end