Added feature to warn if you try to close a tab with unsaved changes. Issue #55

This commit is contained in:
Martin Edenhofer 2013-04-24 10:58:46 +02:00
parent c9fedb7558
commit 4262c47e06
6 changed files with 31 additions and 4 deletions

View file

@ -64,7 +64,10 @@ class App.TicketCreate extends App.Controller
@title @article_attributes['title']
changed: =>
true
formCurrent = @formParam( '.ticket-create' )
diff = difference( @formDefault, formCurrent )
return false if !diff || _.isEmpty( diff )
return true
release: =>
# @clearInterval( @key, 'ticket_zoom' )
@ -193,6 +196,8 @@ class App.TicketCreate extends App.Controller
el: @el.find('[data-id="text_module"]'),
)
@formDefault = @formParam( '.ticket-create' )
localUserInfo: (params) =>
@userInfo( user_id: params.customer_id )

View file

@ -51,7 +51,13 @@ class App.TicketZoom extends App.Controller
@title 'Ticket Zoom ' + @ticket.number
# else
# @title 'Loading...'
changed: =>
formCurrent = @formParam( '.ticket-update' )
diff = difference( @formDefault, formCurrent )
return false if !diff || _.isEmpty( diff )
return true
release: =>
@clearInterval( @key, 'ticket_zoom' )
@el.remove()
@ -202,6 +208,8 @@ class App.TicketZoom extends App.Controller
# show frontend times
@frontendTimeUpdate()
@formDefault = @formParam( '.ticket-update' )
# scroll to article if given
if @article_id && document.getElementById( 'article-' + @article_id )
offset = document.getElementById( 'article-' + @article_id ).offsetTop

View file

@ -56,6 +56,12 @@ class App.TaskWidget extends App.Controller
e.preventDefault()
key = $(e.target).parent().data('id')
# check if input has changed
task = App.TaskManager.get( key )
if task.worker && task.worker.changed
if task.worker.changed()
return if !window.confirm( App.i18n.translateInline('Tab has changed, you really want to close it?') )
# check if active task is closed
task_last = undefined
tasks_all = App.TaskManager.all()

View file

@ -14,6 +14,11 @@ class App.TaskManager
_instance ?= new _Singleton
_instance.add( type, type_id, callback, params, to_not_show )
@get: ( key ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.get( key )
@remove: ( key ) ->
if _instance == undefined
_instance ?= new _Singleton
@ -118,6 +123,9 @@ class _Singleton extends App.Controller
@task_count
get: ( key ) =>
return @tasks[key]
remove: ( key, to_not_show = false ) =>
if @tasks[key]
@tasks[key].worker.release()

View file

@ -5,7 +5,7 @@
</div>
</div>
</div>
<form class="form-horizontal">
<form class="form-horizontal ticket-create">
<input type="hidden" value="" name="article_type"/>
<div class="row">
<div class="span9 ticket_create"></div>

View file

@ -82,7 +82,7 @@
<img class="thumbnail user-data" data-id="<%= @S('id') %>"" src="<%- @S('image') %>" alt="">
</div>
<div class="span8 well-muted article-message">
<form class="form-stacked pull-left">
<form class="form-stacked pull-left ticket-update">
<div data-id="form-ticket-update"></div>
<div data-id="form-article-update"></div>
<button type="submit" class="btn btn-primary submit"><%- @T( 'Submit' ) %></button>