Added init version of auto save.

This commit is contained in:
Martin Edenhofer 2013-05-30 00:25:04 +02:00
parent b351796986
commit c8e0d631ca
4 changed files with 106 additions and 26 deletions

View file

@ -49,6 +49,9 @@ class App.TicketCreate extends App.Controller
@log 'AgentTicketPhone', 'error', defaults
@render(defaults)
# start auto save
@autosave()
meta: =>
text = App.i18n.translateInline( @article_attributes['title'] )
subject = @el.find('[name=subject]').val()
@ -66,7 +69,7 @@ class App.TicketCreate extends App.Controller
activate: =>
@navupdate '#'
@title @article_attributes['title']
changed: =>
formCurrent = @formParam( @el.find('.ticket-create') )
diff = difference( @formDefault, formCurrent )
@ -76,6 +79,18 @@ class App.TicketCreate extends App.Controller
release: =>
# @clearInterval( @key, 'ticket_zoom' )
@el.remove()
@clearInterval( @id, @auto_save_key )
autosave: =>
@auto_save_key = 'create' + @type + @id
update = =>
data = @formParam( @el.find('.ticket-create') )
diff = difference( @autosaveLast, data )
if !@autosaveLast || ( diff && !_.isEmpty( diff ) )
@autosaveLast = data
console.log('form hash changed', diff, data)
App.TaskManager.update( @task_key, { 'state': data })
@interval( update, 10000, @id, @auto_save_key )
# get data / in case also ticket data for split
fetch: (params) ->
@ -135,7 +150,7 @@ class App.TicketCreate extends App.Controller
render: (template = {}) ->
# set defaults
defaults = template['options'] || {}
defaults = template['options'] || @form_state || {}
if !( 'ticket_state_id' of defaults )
defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id
if !( 'ticket_priority_id' of defaults )

View file

@ -34,6 +34,9 @@ class App.TicketZoom extends App.Controller
@fetch( @ticket_id, false)
@interval( update, 30000, @key, 'ticket_zoom' )
# start auto save
@autosave()
meta: =>
return if !@ticket
meta =
@ -62,6 +65,17 @@ class App.TicketZoom extends App.Controller
@clearInterval( @key, 'ticket_zoom' )
@el.remove()
autosave: =>
@auto_save_key = 'zoom' + @id
update = =>
data = @formParam( @el.find('.ticket-update') )
diff = difference( @autosaveLast, data )
if !@autosaveLast || ( diff && !_.isEmpty( diff ) )
@autosaveLast = data
console.log('form hash changed', diff, data)
App.TaskManager.update( @task_key, { 'state': data })
@interval( update, 10000, @id, @auto_save_key )
fetch: (ticket_id, force) ->
return if !@Session.all()
@ -141,34 +155,36 @@ class App.TicketZoom extends App.Controller
for article in @articles
new Article( article: article )
defaults = @form_state || {}
@configure_attributes_ticket = [
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left' },
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left' },
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: true, relation: 'Group', filter: @edit_form, class: 'span2', item_class: 'pull-left' },
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, relation: 'User', filter: @edit_form, nulloption: true, class: 'span2', item_class: 'pull-left' },
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left', default: defaults['ticket_state_id'] },
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left', default: defaults['ticket_priority_id'] },
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: true, relation: 'Group', filter: @edit_form, class: 'span2', item_class: 'pull-left', default: defaults['group_id'] },
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, relation: 'User', filter: @edit_form, nulloption: true, class: 'span2', item_class: 'pull-left', default: defaults['owner_id'] },
]
if @isRole('Customer')
@configure_attributes_ticket = [
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left' },
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left' },
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left', default: defaults['ticket_state_id'] },
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', filter: @edit_form, translate: true, class: 'span2', item_class: 'pull-left', default: defaults['ticket_priority_id'] },
]
@configure_attributes_article = [
{ name: 'ticket_article_type_id', display: 'Type', tag: 'select', multiple: false, null: true, relation: 'TicketArticleType', filter: @edit_form, default: '9', translate: true, class: 'medium', item_class: '' },
{ name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'in_reply_to', display: 'In Reply to', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'body', display: 'Text', tag: 'textarea', rows: 6, limit: 100, null: true, class: 'span7', item_class: '', upload: true },
{ name: 'internal', display: 'Visability', tag: 'select', default: false, null: true, options: { true: 'internal', false: 'public' }, class: 'medium', item_class: '' },
{ name: 'ticket_article_type_id', display: 'Type', tag: 'select', multiple: false, null: true, relation: 'TicketArticleType', filter: @edit_form, default: '9', translate: true, class: 'medium', item_class: '', default: defaults['ticket_article_type_id'] },
{ name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['to'] },
{ name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['cc'] },
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['subject'] },
{ name: 'in_reply_to', display: 'In Reply to', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['in_reply_to'] },
{ name: 'body', display: 'Text', tag: 'textarea', rows: 6, limit: 100, null: true, class: 'span7', item_class: '', upload: true, default: defaults['body'] },
{ name: 'internal', display: 'Visability', tag: 'select', default: false, null: true, options: { true: 'internal', false: 'public' }, class: 'medium', item_class: '', default: defaults['internal'] },
]
if @isRole('Customer')
@configure_attributes_article = [
{ name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'in_reply_to', display: 'In Reply to', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'body', display: 'Text', tag: 'textarea', rows: 6, limit: 100, null: true, class: 'span7', item_class: '', upload: true },
{ name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['to'] },
{ name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['cc'] },
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['subject'] },
{ name: 'in_reply_to', display: 'In Reply to', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide', default: defaults['in_reply_to'] },
{ name: 'body', display: 'Text', tag: 'textarea', rows: 6, limit: 100, null: true, class: 'span7', item_class: '', upload: true, default: defaults['body'] },
]
@html App.view('agent_ticket_zoom')(
@ -623,6 +639,7 @@ class TicketZoomRouter extends App.ControllerPermanent
constructor: (params) ->
super
@log 'zoom router', params
# cleanup params
clean_params =
ticket_id: params.ticket_id

View file

@ -15,8 +15,6 @@ class App.TaskWidget extends App.Controller
App.TaskManager.reset()
@el.html('')
App.TaskManager.syncInitial()
sync = =>
App.TaskManager.sync()
@delay( sync, 3000, 'task-widget' )

View file

@ -9,16 +9,21 @@ class App.TaskManager
_instance ?= new _Singleton
_instance.all()
@add: ( type, type_id, callback, params, to_not_show ) ->
@add: ( type, type_id, callback, params, to_not_show, state ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.add( type, type_id, callback, params, to_not_show )
_instance.add( type, type_id, callback, params, to_not_show, state )
@get: ( key ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.get( key )
@update: ( key, params ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.update( key, params )
@remove: ( key ) ->
if _instance == undefined
_instance ?= new _Singleton
@ -39,6 +44,11 @@ class App.TaskManager
_instance ?= new _Singleton
_instance.syncTasksInitial()
@syncSave: ->
if _instance == undefined
_instance ?= new _Singleton
_instance.syncSave()
@sync: ->
if _instance == undefined
_instance ?= new _Singleton
@ -50,11 +60,12 @@ class _Singleton extends App.Controller
constructor: ->
@tasks = {}
@task_count = 0
@syncTasksInitial()
all: ->
@tasks
add: ( type, type_id, callback, params, to_not_show = false ) ->
add: ( type, type_id, callback, params, to_not_show = false, state ) ->
for key, task of @tasks
if task.type is type && task.type_id is type_id
return key if to_not_show
@ -99,6 +110,13 @@ class _Singleton extends App.Controller
params_app = _.clone(params)
params_app['el'] = $('#content_permanent_' + @task_count )
params_app['task_key'] = @task_count
# check if we have old state there
if !state
oldTask = @get_by_type( type, type_id )
if oldTask
state = oldTask.state
params_app['form_state'] = state
if to_not_show
params_app['doNotLog'] = 1
a = new App[callback]( params_app )
@ -128,6 +146,12 @@ class _Singleton extends App.Controller
get: ( key ) =>
return @tasks[key]
update: ( key, params ) =>
return false if !@tasks[key]
for item, value of params
@tasks[key][item] = value
@syncSave()
remove: ( key, to_not_show = false ) =>
if @tasks[key]
@tasks[key].worker.release()
@ -143,6 +167,11 @@ class _Singleton extends App.Controller
@tasks = {}
App.Event.trigger 'ui:rerender'
get_by_type: (type, type_id) =>
store = @syncLoad() || []
for item in store
return item if item.type is type && item.type_id is type_id
syncAdd: (task) =>
store = @syncLoad() || []
for item in store
@ -163,6 +192,27 @@ class _Singleton extends App.Controller
storeNew.push item
App.Store.write( 'tasks', storeNew )
syncSave: =>
store = @syncLoad() || []
storeNew = []
for item in store
for key, task of @tasks
if task.type is item.type && task.type_id is item.type_id
console.log('MATCH', item)
if @tasks[key]['state']
item['state'] = @tasks[key]['state']
storeNew.push item
# if @tasks[key]
# @tasks[key].worker.release()
#
# storeNew.push item
# item =
# type: task.type
# type_id: task.type_id
# params: task.params
# callback: task.callback
App.Store.write( 'tasks', storeNew )
syncLoad: =>
App.Store.get( 'tasks' )
@ -176,7 +226,7 @@ class _Singleton extends App.Controller
@delay(
=>
task = store.shift()
@add(task.type, task.type_id, task.callback, task.params, true)
@add(task.type, task.type_id, task.callback, task.params, true, task.state)
task_count * 500
)