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

View file

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

View file

@ -56,6 +56,12 @@ class App.TaskWidget extends App.Controller
e.preventDefault() e.preventDefault()
key = $(e.target).parent().data('id') 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 # check if active task is closed
task_last = undefined task_last = undefined
tasks_all = App.TaskManager.all() tasks_all = App.TaskManager.all()

View file

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

View file

@ -5,7 +5,7 @@
</div> </div>
</div> </div>
</div> </div>
<form class="form-horizontal"> <form class="form-horizontal ticket-create">
<input type="hidden" value="" name="article_type"/> <input type="hidden" value="" name="article_type"/>
<div class="row"> <div class="row">
<div class="span9 ticket_create"></div> <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=""> <img class="thumbnail user-data" data-id="<%= @S('id') %>"" src="<%- @S('image') %>" alt="">
</div> </div>
<div class="span8 well-muted article-message"> <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-ticket-update"></div>
<div data-id="form-article-update"></div> <div data-id="form-article-update"></div>
<button type="submit" class="btn btn-primary submit"><%- @T( 'Submit' ) %></button> <button type="submit" class="btn btn-primary submit"><%- @T( 'Submit' ) %></button>