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

@ -10,7 +10,7 @@ class App.Controller extends Spine.Controller
super super
# generate controllerId # generate controllerId
@controllerId = 'controller-' + new Date().getTime() + '-' + Math.floor( Math.random() * 999999 ) @controllerId = 'controller-' + new Date().getTime() + '-' + Math.floor(Math.random() * 999999)
# apply to release controller on dom remove # apply to release controller on dom remove
@el.on('remove', @releaseController) @el.on('remove', @releaseController)
@ -84,7 +84,7 @@ class App.Controller extends Spine.Controller
# add @title methode to set title # add @title methode to set title
title: (name, translate = false) -> title: (name, translate = false) ->
# $('html head title').html( @Config.get(product_name) + ' - ' + App.i18n.translateInline(name) ) # $('html head title').html(@Config.get(product_name) + ' - ' + App.i18n.translateInline(name))
title = name title = name
if translate if translate
title = App.i18n.translatePlain(name) title = App.i18n.translatePlain(name)
@ -92,9 +92,9 @@ class App.Controller extends Spine.Controller
copyToClipboard: (text) -> copyToClipboard: (text) ->
if window.clipboardData # IE if window.clipboardData # IE
window.clipboardData.setData( 'Text', text ) window.clipboardData.setData('Text', text)
else else
window.prompt( 'Copy to clipboard: Ctrl+C, Enter', text ) window.prompt('Copy to clipboard: Ctrl+C, Enter', text)
# disable all delay's and interval's # disable all delay's and interval's
disconnectClient: -> disconnectClient: ->
@ -238,11 +238,11 @@ class App.Controller extends Spine.Controller
currentVal = item.text() currentVal = item.text()
ui.frontendTimeUpdateItem(item, currentVal) ui.frontendTimeUpdateItem(item, currentVal)
) )
App.Interval.set( update, 61000, 'frontendTimeUpdate', 'ui' ) App.Interval.set(update, 61000, 'frontendTimeUpdate', 'ui')
frontendTimeUpdateItem: (item, currentVal) => frontendTimeUpdateItem: (item, currentVal) =>
timestamp = item.data('time') timestamp = item.data('time')
time = @humanTime( timestamp, item.hasClass('escalation') ) time = @humanTime(timestamp, item.hasClass('escalation'))
# only do dom updates on changes # only do dom updates on changes
return if time is currentVal return if time is currentVal

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,51 +413,62 @@ 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 return if !@ticket
currentStoreTicket = @ticket.attributes() currentParams = @formCurrent()
delete currentStoreTicket.article
currentStore =
ticket: currentStoreTicket
article:
to: ''
cc: ''
type: 'note'
body: ''
internal: ''
in_reply_to: ''
currentParams =
ticket: @formParam( @el.find('.edit') )
article: @formParam( @el.find('.article-add') )
# add attachments if exist # check changed between last autosave
attachmentCount = @$('.article-add .textBubble .attachments .attachment').length sameAsLastSave = _.isEqual(currentParams, @autosaveLast)
if attachmentCount > 0 return if sameAsLastSave
currentParams.article.attachments = true @autosaveLast = clone(currentParams)
else
delete currentParams.article.attachments
#console.log('lll', currentStore) # update changes in ui
# remove not needed attributes currentStore = @currentStore()
delete currentParams.article.form_id modelDiff = @formDiff(currentParams, currentStore)
@markFormDiff(modelDiff)
@taskUpdateAll(modelDiff)
# get diff of model
modelDiff =
ticket: App.Utils.formDiff( currentParams.ticket, currentStore.ticket )
article: App.Utils.formDiff( currentParams.article, currentStore.article )
#console.log('modelDiff', modelDiff)
# get diff of last save
changedBetweenLastSave = _.isEqual(currentParams, @autosaveLast)
if !changedBetweenLastSave
#console.log('model DIFF ', modelDiff)
@autosaveLast = clone(currentParams)
@markFormDiff(modelDiff)
@taskUpdateAll(modelDiff)
@interval(update, 2800, 'autosave') @interval(update, 2800, 'autosave')
currentStore: =>
return if !@ticket
currentStoreTicket = @ticket.attributes()
delete currentStoreTicket.article
currentStore =
ticket: currentStoreTicket
article:
to: ''
cc: ''
type: 'note'
body: ''
internal: ''
in_reply_to: ''
currentStore
formCurrent: =>
currentParams =
ticket: @formParam(@el.find('.edit'))
article: @formParam(@el.find('.article-add'))
# add attachments if exist
attachmentCount = @$('.article-add .textBubble .attachments .attachment').length
if attachmentCount > 0
currentParams.article.attachments = true
else
delete currentParams.article.attachments
# remove not needed attributes
delete currentParams.article.form_id
currentParams
formDiff: (currentParams, currentStore) ->
# get diff of model
modelDiff =
ticket: App.Utils.formDiff(currentParams.ticket, currentStore.ticket)
article: App.Utils.formDiff(currentParams.article, currentStore.article)
modelDiff
markFormDiff: (diff = {}) => markFormDiff: (diff = {}) =>
ticketForm = @$('.edit') ticketForm = @$('.edit')
ticketSidebar = @$('.tabsSidebar-tab[data-tab="ticket"]') ticketSidebar = @$('.tabsSidebar-tab[data-tab="ticket"]')

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)
@ -109,7 +109,7 @@ class App.OnlineNotificationWidget extends App.Controller
id: 'markAllAsRead' id: 'markAllAsRead'
type: 'POST' type: 'POST'
url: @apiPath + '/online_notifications/mark_all_as_read' url: @apiPath + '/online_notifications/mark_all_as_read'
data: JSON.stringify( '' ) data: JSON.stringify('')
processData: true processData: true
) )
@ -170,7 +170,7 @@ class App.OnlineNotificationWidget extends App.Controller
# update title # update title
$('.js-notificationsContainer .popover-title').html( $('.js-notificationsContainer .popover-title').html(
App.i18n.translateInline( 'Notifications' ) + " <span class='popover-notificationsCounter'>#{counter}</span>" App.i18n.translateInline('Notifications') + " <span class='popover-notificationsCounter'>#{counter}</span>"
) )
# show mark all as read if needed # show mark all as read if needed

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

@ -13,7 +13,7 @@ class AgentTicketActionsLevel2Test < TestCase
password: 'test', password: 'test',
url: browser_url, url: browser_url,
) )
tasks_close_all( browser: browser1 ) tasks_close_all(browser: browser1)
browser2 = browser_instance browser2 = browser_instance
login( login(
@ -22,7 +22,7 @@ class AgentTicketActionsLevel2Test < TestCase
password: 'test', password: 'test',
url: browser_url, url: browser_url,
) )
tasks_close_all( browser: browser2 ) tasks_close_all(browser: browser2)
# create ticket # create ticket
ticket1 = ticket_create( ticket1 = ticket_create(

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
@ -11,7 +62,7 @@ class AgentTicketActionsLevel3Test < TestCase
password: 'test', password: 'test',
url: browser_url, url: browser_url,
) )
tasks_close_all( browser: browser1 ) tasks_close_all(browser: browser1)
browser2 = browser_instance browser2 = browser_instance
login( login(
@ -20,7 +71,7 @@ class AgentTicketActionsLevel3Test < TestCase
password: 'test', password: 'test',
url: browser_url, url: browser_url,
) )
tasks_close_all( browser: browser2 ) tasks_close_all(browser: browser2)
# create ticket # create ticket
ticket1 = ticket_create( ticket1 = ticket_create(
@ -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

@ -13,7 +13,7 @@ class AgentTicketOverviewLevel1Test < TestCase
password: 'test', password: 'test',
url: browser_url, url: browser_url,
) )
tasks_close_all( browser: browser1 ) tasks_close_all(browser: browser1)
browser2 = browser_instance browser2 = browser_instance
login( login(
@ -22,7 +22,7 @@ class AgentTicketOverviewLevel1Test < TestCase
password: 'test', password: 'test',
url: browser_url, url: browser_url,
) )
tasks_close_all( browser: browser2 ) tasks_close_all(browser: browser2)
# create new overview # create new overview
overview_create( overview_create(

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