Fixes #3827 - Ticket create screen will loose attachments by time.

This commit is contained in:
Rolf Schmidt 2021-10-29 14:46:14 +02:00
parent 614724aa62
commit 189ccb21db
3 changed files with 48 additions and 0 deletions

View file

@ -27,6 +27,8 @@ class App.UiElement.richtext
renderFile = (file) -> renderFile = (file) ->
item.find('.attachments').append(App.view('generic/attachment_item')(file)) item.find('.attachments').append(App.view('generic/attachment_item')(file))
attachments.push file attachments.push file
if form.richTextUploadRenderCallback
form.richTextUploadRenderCallback(attribute, attachments)
if params && params.attachments if params && params.attachments
for file in params.attachments for file in params.attachments
@ -54,6 +56,8 @@ class App.UiElement.richtext
return if item.id.toString() is id.toString() return if item.id.toString() is id.toString()
item item
) )
if form.richTextUploadDeleteCallback
form.richTextUploadDeleteCallback(attribute, attachments)
form_id = item.closest('form').find('[name=form_id]').val() form_id = item.closest('form').find('[name=form_id]').val()

View file

@ -283,6 +283,13 @@ class App.TicketCreate extends App.Controller
return if !@formMeta return if !@formMeta
App.QueueManager.run(@queueKey) 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 = {}) -> render: (template = {}) ->
return if !@formMeta return if !@formMeta
# get params # get params
@ -379,6 +386,8 @@ class App.TicketCreate extends App.Controller
handlersConfig: handlersTunnel handlersConfig: handlersTunnel
params: params params: params
taskKey: @taskKey taskKey: @taskKey
richTextUploadRenderCallback: @updateTaskManagerAttachments
richTextUploadDeleteCallback: @updateTaskManagerAttachments
) )
@controllerFormCreateBottom = new App.ControllerForm( @controllerFormCreateBottom = new App.ControllerForm(
el: @$('.ticket-form-bottom') el: @$('.ticket-form-bottom')

View file

@ -779,4 +779,39 @@ RSpec.describe 'Ticket Create', type: :system do
end end
end 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 end