Fixed losing article text in tab close (was ignored on changes check).

This commit is contained in:
Martin Edenhofer 2016-02-29 16:00:11 +01:00
parent f4c78b9502
commit 77d4f00957
9 changed files with 178 additions and 64 deletions

View file

@ -126,10 +126,11 @@ class App.TicketZoom extends App.Controller
changed: => changed: =>
return false if !@ticket return false if !@ticket
formCurrent = @formParam( @el.find('.edit') ) currentParams = @formCurrent()
ticket = App.Ticket.find(@ticket_id).attributes() currentStore = @currentStore()
modelDiff = App.Utils.formDiff(formCurrent, ticket) modelDiff = @formDiff(currentParams, currentStore)
return false if !modelDiff || _.isEmpty(modelDiff) return false if !modelDiff || _.isEmpty(modelDiff)
return false if _.isEmpty(modelDiff.ticket) && _.isEmpty(modelDiff.article)
return true return true
release: => release: =>
@ -412,7 +413,23 @@ class App.TicketZoom extends App.Controller
if !@autosaveLast if !@autosaveLast
@autosaveLast = @taskGet() @autosaveLast = @taskGet()
update = => update = =>
#console.log('AR', @ticket_id, @ticket, @formParam( @el.find('.article-add') ) ) return if !@ticket
currentParams = @formCurrent()
# check changed between last autosave
sameAsLastSave = _.isEqual(currentParams, @autosaveLast)
return if sameAsLastSave
@autosaveLast = clone(currentParams)
# update changes in ui
currentStore = @currentStore()
modelDiff = @formDiff(currentParams, currentStore)
@markFormDiff(modelDiff)
@taskUpdateAll(modelDiff)
@interval(update, 2800, 'autosave')
currentStore: =>
return if !@ticket return if !@ticket
currentStoreTicket = @ticket.attributes() currentStoreTicket = @ticket.attributes()
delete currentStoreTicket.article delete currentStoreTicket.article
@ -425,6 +442,9 @@ class App.TicketZoom extends App.Controller
body: '' body: ''
internal: '' internal: ''
in_reply_to: '' in_reply_to: ''
currentStore
formCurrent: =>
currentParams = currentParams =
ticket: @formParam(@el.find('.edit')) ticket: @formParam(@el.find('.edit'))
article: @formParam(@el.find('.article-add')) article: @formParam(@el.find('.article-add'))
@ -436,26 +456,18 @@ class App.TicketZoom extends App.Controller
else else
delete currentParams.article.attachments delete currentParams.article.attachments
#console.log('lll', currentStore)
# remove not needed attributes # remove not needed attributes
delete currentParams.article.form_id delete currentParams.article.form_id
currentParams
formDiff: (currentParams, currentStore) ->
# get diff of model # get diff of model
modelDiff = modelDiff =
ticket: App.Utils.formDiff(currentParams.ticket, currentStore.ticket) ticket: App.Utils.formDiff(currentParams.ticket, currentStore.ticket)
article: App.Utils.formDiff(currentParams.article, currentStore.article) article: App.Utils.formDiff(currentParams.article, currentStore.article)
#console.log('modelDiff', modelDiff)
# get diff of last save modelDiff
changedBetweenLastSave = _.isEqual(currentParams, @autosaveLast)
if !changedBetweenLastSave
#console.log('model DIFF ', modelDiff)
@autosaveLast = clone(currentParams)
@markFormDiff(modelDiff)
@taskUpdateAll(modelDiff)
@interval(update, 2800, 'autosave')
markFormDiff: (diff = {}) => markFormDiff: (diff = {}) =>
ticketForm = @$('.edit') ticketForm = @$('.edit')

View file

@ -98,10 +98,10 @@ class App.OnlineNotificationWidget extends App.Controller
counterUpdate: (count) => counterUpdate: (count) =>
if !count if !count
@el.find('.js-counter').text('') @$('.js-counter').text('')
return return
@el.find('.js-counter').text(count) @$('.js-counter').text(count)
markAllAsRead: => markAllAsRead: =>
@counterUpdate(0) @counterUpdate(0)

View file

@ -53,7 +53,7 @@ class AgentTicketActionLevel0Test < TestCase
css: '.active div[data-name=body]', css: '.active div[data-name=body]',
value: 'some content' + random, value: 'some content' + random,
) )
tasks_close_all( discard_changes: true ) tasks_close_all()
# test with two browser windows # test with two browser windows
random = 'text_II_module_test_' + rand(99_999_999).to_s random = 'text_II_module_test_' + rand(99_999_999).to_s

View file

@ -2,6 +2,57 @@
require 'browser_test_helper' require 'browser_test_helper'
class AgentTicketActionsLevel3Test < TestCase class AgentTicketActionsLevel3Test < TestCase
def test_check_changes
@browser = browser_instance
login(
username: 'agent1@example.com',
password: 'test',
url: browser_url,
)
tasks_close_all()
# confirm on create
ticket_create(
data: {
customer: 'nico',
group: 'Users',
title: 'some changes',
body: 'some body 123äöü - changes',
},
do_not_submit: true,
)
close_task(
data: {
title: 'some changes',
},
discard_changes: true,
)
sleep 1
# confirm on zoom
ticket1 = ticket_create(
data: {
customer: 'nico',
group: 'Users',
title: 'some changes',
body: 'some body 123äöü - changes',
},
)
ticket_update(
data: {
body: 'some note',
},
do_not_submit: true,
)
close_task(
data: {
title: 'some changes',
},
discard_changes: true,
)
end
def test_work_with_two_browser_on_same_ticket_edit def test_work_with_two_browser_on_same_ticket_edit
browser1 = browser_instance browser1 = browser_instance
@ -52,6 +103,13 @@ class AgentTicketActionsLevel3Test < TestCase
}, },
do_not_submit: true, do_not_submit: true,
) )
sleep 6
watch_for(
browser: browser1,
css: '.content.active .js-reset',
value: '(Discard your unsaved changes.|Verwerfen der)',
no_quote: true,
)
# update ticket in instance 2 # update ticket in instance 2
ticket_update( ticket_update(
@ -61,6 +119,13 @@ class AgentTicketActionsLevel3Test < TestCase
}, },
do_not_submit: true, do_not_submit: true,
) )
sleep 6
watch_for(
browser: browser2,
css: '.content.active .js-reset',
value: '(Discard your unsaved changes.|Verwerfen der)',
no_quote: true,
)
click( click(
browser: browser2, browser: browser2,

View file

@ -73,7 +73,7 @@ class AgentUserManageTest < TestCase
sleep 4 sleep 4
# call new ticket screen again # call new ticket screen again
tasks_close_all( discard_changes: 1 ) tasks_close_all()
click( css: 'a[href="#new"]' ) click( css: 'a[href="#new"]' )
click( css: 'a[href="#ticket/create"]' ) click( css: 'a[href="#ticket/create"]' )

View file

@ -933,7 +933,7 @@ class TestCase < Test::Unit::TestCase
=end =end
def open_task(params = {}, _fallback = false) def open_task(params = {})
switch_window_focus(params) switch_window_focus(params)
log('open_task', params) log('open_task', params)
@ -949,6 +949,44 @@ class TestCase < Test::Unit::TestCase
true true
end end
=begin
close_task(
browser: browser1,
data: {
title: 'some title',
},
discard_changes: true,
)
=end
def close_task(params = {})
switch_window_focus(params)
log('close_task', params)
instance = params[:browser] || @browser
data = params[:data]
element = instance.find_elements(partial_link_text: data[:title])[0]
if !element
screenshot(browser: instance, comment: 'close_task_failed')
fail "no task with title '#{data[:title]}' found"
end
instance.mouse.move_to(element)
sleep 0.1
instance.execute_script("$('.navigation .tasks .task:contains(\"#{data[:title]}\") .js-close').click()")
# accept task close warning
if params[:discard_changes]
sleep 1
instance.find_elements(css: '.modal button.js-submit')[0].click
end
true
end
=begin =begin
file_upload( file_upload(
@ -1122,7 +1160,6 @@ wait untill text in selector disabppears
tasks_close_all( tasks_close_all(
browser: browser1, browser: browser1,
discard_changes: true,
) )
=end =end
@ -1144,8 +1181,8 @@ wait untill text in selector disabppears
click_element.click click_element.click
# accept task close warning # accept task close warning
if params[:discard_changes] if instance.find_elements(css: '.modal button.js-submit')[0]
sleep 1 sleep 0.5
instance.find_elements(css: '.modal button.js-submit')[0].click instance.find_elements(css: '.modal button.js-submit')[0].click
end end
end end