Fixes #3831 - Ticket zoom will loose attachments on rerender.
This commit is contained in:
parent
58898239d4
commit
2b94843bb7
3 changed files with 83 additions and 20 deletions
|
@ -493,16 +493,22 @@ class App.TicketZoom extends App.Controller
|
|||
@form_id = @taskGet('article').form_id || App.ControllerForm.formId()
|
||||
|
||||
@articleNew = new App.TicketZoomArticleNew(
|
||||
ticket: @ticket
|
||||
ticket_id: @ticket_id
|
||||
el: elLocal.find('.article-new')
|
||||
formMeta: @formMeta
|
||||
form_id: @form_id
|
||||
defaults: @taskGet('article')
|
||||
taskKey: @taskKey
|
||||
ui: @
|
||||
callbackFileUploadStart: @submitDisable
|
||||
callbackFileUploadStop: @submitEnable
|
||||
ticket: @ticket
|
||||
ticket_id: @ticket_id
|
||||
el: elLocal.find('.article-new')
|
||||
formMeta: @formMeta
|
||||
form_id: @form_id
|
||||
defaults: @taskGet('article')
|
||||
taskKey: @taskKey
|
||||
ui: @
|
||||
richTextUploadStartCallback: @submitDisable
|
||||
richTextUploadRenderCallback: (attachments) =>
|
||||
@submitEnable()
|
||||
@taskUpdateAttachments('article', attachments)
|
||||
@delay(@markForm, 250, 'ticket-zoom-form-update')
|
||||
richTextUploadDeleteCallback: (attachments) =>
|
||||
@taskUpdateAttachments('article', attachments)
|
||||
@delay(@markForm, 250, 'ticket-zoom-form-update')
|
||||
)
|
||||
|
||||
@highligher = new App.TicketZoomHighlighter(
|
||||
|
@ -721,7 +727,7 @@ class App.TicketZoom extends App.Controller
|
|||
# add attachments if exist
|
||||
attachmentCount = @$('.article-add .textBubble .attachments .attachment').length
|
||||
if attachmentCount > 0
|
||||
currentParams.article.attachments = true
|
||||
currentParams.article.attachments = attachmentCount
|
||||
else
|
||||
delete currentParams.article.attachments
|
||||
|
||||
|
@ -1079,6 +1085,13 @@ class App.TicketZoom extends App.Controller
|
|||
|
||||
App.TaskManager.update(@taskKey, taskData)
|
||||
|
||||
taskUpdateAttachments: (area, attachments) =>
|
||||
taskData = App.TaskManager.get(@taskKey)
|
||||
return if !taskData
|
||||
|
||||
taskData.attachments = attachments
|
||||
App.TaskManager.update(@taskKey, taskData)
|
||||
|
||||
taskUpdateAll: (data) =>
|
||||
@localTaskData = data
|
||||
@localTaskData.article['form_id'] = @form_id
|
||||
|
@ -1101,7 +1114,7 @@ class App.TicketZoom extends App.Controller
|
|||
@localTaskData =
|
||||
ticket: {}
|
||||
article: {}
|
||||
App.TaskManager.update(@taskKey, { 'state': @localTaskData })
|
||||
App.TaskManager.update(@taskKey, { 'state': @localTaskData, attachments: [] })
|
||||
|
||||
renderOverviewNavigator: (parentEl) ->
|
||||
new App.TicketZoomOverviewNavigator(
|
||||
|
|
|
@ -198,17 +198,17 @@ class App.TicketZoomArticleNew extends App.Controller
|
|||
inputField: @$('.article-attachment input')
|
||||
|
||||
onFileStartCallback: =>
|
||||
@callbackFileUploadStart?()
|
||||
@richTextUploadStartCallback?()
|
||||
|
||||
onFileCompletedCallback: (response) =>
|
||||
@attachments.push response.data
|
||||
@renderAttachment(response.data)
|
||||
@$('.article-attachment input').val('')
|
||||
|
||||
@callbackFileUploadStop?()
|
||||
@richTextUploadRenderCallback?(@attachments)
|
||||
|
||||
onFileAbortedCallback: =>
|
||||
@callbackFileUploadStop?()
|
||||
@richTextUploadRenderCallback?(@attachments)
|
||||
|
||||
attachmentPlaceholder: @attachmentPlaceholder
|
||||
attachmentUpload: @attachmentUpload
|
||||
|
@ -287,7 +287,6 @@ class App.TicketZoomArticleNew extends App.Controller
|
|||
params.preferences ||= {}
|
||||
params.preferences.security = @paramsSecurity()
|
||||
|
||||
params.attachments = @attachments
|
||||
params
|
||||
|
||||
validate: =>
|
||||
|
@ -624,6 +623,8 @@ class App.TicketZoomArticleNew extends App.Controller
|
|||
$(e.currentTarget).closest('.attachment').remove()
|
||||
if element.find('.attachment').length == 0
|
||||
element.empty()
|
||||
|
||||
@richTextUploadDeleteCallback?(@attachments)
|
||||
)
|
||||
|
||||
actions: ->
|
||||
|
|
|
@ -2011,13 +2011,13 @@ RSpec.describe 'Ticket zoom', type: :system do
|
|||
end
|
||||
|
||||
def expect_upload_and_text
|
||||
expect(page).to have_text('mail001.box')
|
||||
expect(page).to have_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test")
|
||||
expect(page.find('.article-new')).to have_text('mail001.box')
|
||||
expect(page.find('.article-new')).to have_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test")
|
||||
end
|
||||
|
||||
def expect_no_upload_and_text
|
||||
expect(page).to have_no_text('mail001.box')
|
||||
expect(page).to have_no_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test")
|
||||
expect(page.find('.article-new')).to have_no_text('mail001.box')
|
||||
expect(page.find('.article-new')).to have_no_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test")
|
||||
end
|
||||
|
||||
it 'does show up the attachments after a reload of the page' do
|
||||
|
@ -2044,6 +2044,55 @@ RSpec.describe 'Ticket zoom', type: :system do
|
|||
refresh
|
||||
expect_no_upload_and_text
|
||||
end
|
||||
|
||||
context 'when rerendering (#3831)' do
|
||||
def rerender
|
||||
page.evaluate_script("App.Event.trigger('ui:rerender')")
|
||||
end
|
||||
|
||||
it 'does loose attachments after rerender' do
|
||||
upload_and_set_text
|
||||
expect_upload_and_text
|
||||
rerender
|
||||
expect_upload_and_text
|
||||
end
|
||||
|
||||
it 'does not readd the attachments after reset' do
|
||||
upload_and_set_text
|
||||
expect_upload_and_text
|
||||
|
||||
page.find('.js-reset').click
|
||||
wait_for_upload_blank
|
||||
expect_no_upload_and_text
|
||||
rerender
|
||||
expect_no_upload_and_text
|
||||
end
|
||||
|
||||
it 'does not readd the attachments after submit' do
|
||||
upload_and_set_text
|
||||
expect_upload_and_text
|
||||
|
||||
page.find('.js-submit').click
|
||||
wait_for_upload_blank
|
||||
expect_no_upload_and_text
|
||||
rerender
|
||||
expect_no_upload_and_text
|
||||
end
|
||||
|
||||
it 'does not show the ticket as changed after the upload removal' do
|
||||
page.find('input#fileUpload_1', visible: :all).set(Rails.root.join('test/data/mail/mail001.box'))
|
||||
expect(page.find('.article-new')).to have_text('mail001.box')
|
||||
wait_for_upload_present
|
||||
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
|
||||
expect(page).to have_no_selector('.js-reset')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Unable to close tickets in certran cases if core workflow is used #3710', authenticated_as: :authenticate, db_strategy: :reset do
|
||||
|
|
Loading…
Reference in a new issue