Improved handling with form changes.
This commit is contained in:
parent
369aa7e52d
commit
3d7aeea978
1 changed files with 25 additions and 23 deletions
|
@ -79,7 +79,7 @@ class App.TicketZoom extends App.Controller
|
||||||
return false if !@ticket
|
return false if !@ticket
|
||||||
formCurrent = @formParam( @el.find('.edit') )
|
formCurrent = @formParam( @el.find('.edit') )
|
||||||
ticket = App.Ticket.find(@ticket_id).attributes()
|
ticket = App.Ticket.find(@ticket_id).attributes()
|
||||||
modelDiff = @getDiff( ticket, formCurrent )
|
modelDiff = App.Utils.formDiff( formCurrent, ticket )
|
||||||
return false if !modelDiff || _.isEmpty( modelDiff )
|
return false if !modelDiff || _.isEmpty( modelDiff )
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ class App.TicketZoom extends App.Controller
|
||||||
|
|
||||||
defaults = ticket.attributes()
|
defaults = ticket.attributes()
|
||||||
task_state = @taskGet('ticket')
|
task_state = @taskGet('ticket')
|
||||||
modelDiff = @getDiff( defaults, task_state )
|
modelDiff = App.Utils.formDiff( task_state, defaults )
|
||||||
#if @isRole('Customer')
|
#if @isRole('Customer')
|
||||||
# delete defaults['state_id']
|
# delete defaults['state_id']
|
||||||
# delete defaults['state']
|
# delete defaults['state']
|
||||||
|
@ -483,18 +483,19 @@ class App.TicketZoom extends App.Controller
|
||||||
currentParams =
|
currentParams =
|
||||||
ticket: @formParam( @el.find('.edit') )
|
ticket: @formParam( @el.find('.edit') )
|
||||||
article: @formParam( @el.find('.article-add') )
|
article: @formParam( @el.find('.article-add') )
|
||||||
|
#console.log('lll', currentStore)
|
||||||
|
# remove not needed attributes
|
||||||
|
delete currentParams.article.form_id
|
||||||
|
|
||||||
# get diff of model
|
# get diff of model
|
||||||
modelDiff =
|
modelDiff =
|
||||||
ticket: @getDiff( currentStore.ticket, currentParams.ticket )
|
ticket: App.Utils.formDiff( currentParams.ticket, currentStore.ticket )
|
||||||
article: @getDiff( currentStore.article, currentParams.article )
|
article: App.Utils.formDiff( currentParams.article, currentStore.article )
|
||||||
#console.log('modelDiff', modelDiff)
|
#console.log('modelDiff', modelDiff)
|
||||||
|
|
||||||
# get diff of last save
|
# get diff of last save
|
||||||
changedBetweenLastSave = _.isEqual(currentParams, @autosaveLast )
|
changedBetweenLastSave = _.isEqual(currentParams, @autosaveLast )
|
||||||
#console.log('changedBetweenLastSave', changedBetweenLastSave)
|
|
||||||
if !changedBetweenLastSave
|
if !changedBetweenLastSave
|
||||||
#console.log('autosave DIFF result', changedBetweenLastSave)
|
|
||||||
console.log('model DIFF ', modelDiff)
|
console.log('model DIFF ', modelDiff)
|
||||||
|
|
||||||
@autosaveLast = clone(currentParams)
|
@autosaveLast = clone(currentParams)
|
||||||
|
@ -503,21 +504,11 @@ class App.TicketZoom extends App.Controller
|
||||||
@taskUpdateAll( modelDiff )
|
@taskUpdateAll( modelDiff )
|
||||||
@interval( update, 3000, 'autosave' )
|
@interval( update, 3000, 'autosave' )
|
||||||
|
|
||||||
getDiff: (model, params) =>
|
|
||||||
|
|
||||||
# do type convertation to compare it against form
|
|
||||||
modelClone = clone(model)
|
|
||||||
for key, value of modelClone
|
|
||||||
if key is 'owner_id' && modelClone[key] is 1
|
|
||||||
modelClone[key] = ''
|
|
||||||
else if typeof value is 'number'
|
|
||||||
modelClone[key] = value.toString()
|
|
||||||
#console.log('LLL', modelClone)
|
|
||||||
result = difference( modelClone, params )
|
|
||||||
|
|
||||||
markFormDiff: (diff = {}) =>
|
markFormDiff: (diff = {}) =>
|
||||||
ticketForm = @$('.edit')
|
ticketForm = @$('.edit')
|
||||||
|
ticketSidebar = @$('.tabsSidebar-tab[data-tab="ticket"]')
|
||||||
articleForm = @$('.article-add')
|
articleForm = @$('.article-add')
|
||||||
|
resetButton = @$('.js-reset')
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
params.ticket = @formParam( ticketForm )
|
params.ticket = @formParam( ticketForm )
|
||||||
|
@ -526,23 +517,30 @@ class App.TicketZoom extends App.Controller
|
||||||
|
|
||||||
# clear all changes
|
# clear all changes
|
||||||
if _.isEmpty(diff.ticket) && _.isEmpty(diff.article)
|
if _.isEmpty(diff.ticket) && _.isEmpty(diff.article)
|
||||||
|
ticketSidebar.removeClass('is-changed')
|
||||||
ticketForm.removeClass('form-changed')
|
ticketForm.removeClass('form-changed')
|
||||||
ticketForm.find('.form-group').removeClass('is-changed')
|
ticketForm.find('.form-group').removeClass('is-changed')
|
||||||
@$('.js-reset').addClass('hide')
|
resetButton.addClass('hide')
|
||||||
|
|
||||||
# set changes
|
# set changes
|
||||||
else
|
else
|
||||||
ticketForm.addClass('form-changed')
|
ticketForm.addClass('form-changed')
|
||||||
|
if !_.isEmpty(diff.ticket)
|
||||||
|
ticketSidebar.addClass('is-changed')
|
||||||
|
else
|
||||||
|
ticketSidebar.removeClass('is-changed')
|
||||||
for currentKey, currentValue of params.ticket
|
for currentKey, currentValue of params.ticket
|
||||||
element = @$('.edit [name="' + currentKey + '"]').parents('.form-group')
|
element = @$('.edit [name="' + currentKey + '"]').parents('.form-group')
|
||||||
if diff.ticket[currentKey]
|
if !element.get(0)
|
||||||
|
element = @$('.edit [data-name="' + currentKey + '"]').parents('.form-group')
|
||||||
|
if currentKey of diff.ticket
|
||||||
if !element.hasClass('is-changed')
|
if !element.hasClass('is-changed')
|
||||||
element.addClass('is-changed')
|
element.addClass('is-changed')
|
||||||
else
|
else
|
||||||
if element.hasClass('is-changed')
|
if element.hasClass('is-changed')
|
||||||
element.removeClass('is-changed')
|
element.removeClass('is-changed')
|
||||||
|
|
||||||
@$('.js-reset').removeClass('hide')
|
resetButton.removeClass('hide')
|
||||||
|
|
||||||
|
|
||||||
submit: (e) =>
|
submit: (e) =>
|
||||||
|
@ -700,9 +698,13 @@ class App.TicketZoom extends App.Controller
|
||||||
App.TaskManager.update( @task_key, { 'state': @localTaskData })
|
App.TaskManager.update( @task_key, { 'state': @localTaskData })
|
||||||
|
|
||||||
taskReset: =>
|
taskReset: =>
|
||||||
|
|
||||||
# hide reset button
|
# hide reset button
|
||||||
@$('.js-reset').addClass('hide')
|
@$('.js-reset').addClass('hide')
|
||||||
|
|
||||||
|
# remove change flag on tab
|
||||||
|
@$('.tabsSidebar-tab[data-tab="ticket"]').removeClass('is-changed')
|
||||||
|
|
||||||
# reset task state
|
# reset task state
|
||||||
@localTaskData =
|
@localTaskData =
|
||||||
ticket: {}
|
ticket: {}
|
||||||
|
|
Loading…
Reference in a new issue