Fixes #3827 - Ticket create screen will loose attachments by time.
This commit is contained in:
parent
ad12ad4e01
commit
3f1057c190
3 changed files with 48 additions and 0 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -282,6 +282,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
|
||||
|
@ -376,6 +383,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')
|
||||
|
|
|
@ -717,4 +717,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
|
||||
|
|
Loading…
Reference in a new issue