Centralised ticket form changes observer.
This commit is contained in:
parent
5132248142
commit
37f63cbac3
5 changed files with 38 additions and 80 deletions
|
@ -467,6 +467,31 @@ class App.Controller extends Spine.Controller
|
||||||
ws_send: (data) ->
|
ws_send: (data) ->
|
||||||
App.Event.trigger( 'ws:send', JSON.stringify(data) )
|
App.Event.trigger( 'ws:send', JSON.stringify(data) )
|
||||||
|
|
||||||
|
# central method, is getting called on every ticket form change
|
||||||
|
ticketFormChanges: (params, attribute, attributes, classname, form, ui) =>
|
||||||
|
if @form_meta.dependencies && @form_meta.dependencies[attribute.name]
|
||||||
|
dependency = @form_meta.dependencies[attribute.name][ parseInt(params[attribute.name]) ]
|
||||||
|
if !dependency
|
||||||
|
dependency = @form_meta.dependencies[attribute.name][ params[attribute.name] ]
|
||||||
|
if dependency
|
||||||
|
for fieldNameToChange of dependency
|
||||||
|
filter = []
|
||||||
|
if dependency[fieldNameToChange]
|
||||||
|
filter = dependency[fieldNameToChange]
|
||||||
|
|
||||||
|
# find element to replace
|
||||||
|
for item in attributes
|
||||||
|
if item.name is fieldNameToChange
|
||||||
|
item['filter'] = {}
|
||||||
|
item['filter'][ fieldNameToChange ] = filter
|
||||||
|
item.default = params[item.name]
|
||||||
|
#if !item.default
|
||||||
|
# delete item['default']
|
||||||
|
newElement = ui.formGenItem( item, classname, form )
|
||||||
|
|
||||||
|
# replace new option list
|
||||||
|
form.find('[name="' + fieldNameToChange + '"]').closest('.form-group').replaceWith( newElement )
|
||||||
|
|
||||||
class App.ControllerPermanent extends App.Controller
|
class App.ControllerPermanent extends App.Controller
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
|
|
|
@ -205,29 +205,6 @@ class App.TicketCreate extends App.Controller
|
||||||
form_id: @form_id
|
form_id: @form_id
|
||||||
)
|
)
|
||||||
|
|
||||||
formChanges = (params, attribute, attributes, classname, form, ui) =>
|
|
||||||
if @form_meta.dependencies && @form_meta.dependencies[attribute.name]
|
|
||||||
dependency = @form_meta.dependencies[attribute.name][ parseInt(params[attribute.name]) ]
|
|
||||||
if dependency
|
|
||||||
|
|
||||||
for fieldNameToChange of dependency
|
|
||||||
filter = []
|
|
||||||
if dependency[fieldNameToChange]
|
|
||||||
filter = dependency[fieldNameToChange]
|
|
||||||
|
|
||||||
# find element to replace
|
|
||||||
for item in attributes
|
|
||||||
if item.name is fieldNameToChange
|
|
||||||
item['filter'] = {}
|
|
||||||
item['filter'][ fieldNameToChange ] = filter
|
|
||||||
item.default = params[item.name]
|
|
||||||
#if !item.default
|
|
||||||
# delete item['default']
|
|
||||||
newElement = ui.formGenItem( item, classname, form )
|
|
||||||
|
|
||||||
# replace new option list
|
|
||||||
form.find('[name="' + fieldNameToChange + '"]').closest('.form-group').replaceWith( newElement )
|
|
||||||
|
|
||||||
signatureChanges = (params, attribute, attributes, classname, form, ui) =>
|
signatureChanges = (params, attribute, attributes, classname, form, ui) =>
|
||||||
if attribute && attribute.name is 'group_id'
|
if attribute && attribute.name is 'group_id'
|
||||||
signature = undefined
|
signature = undefined
|
||||||
|
@ -274,7 +251,7 @@ class App.TicketCreate extends App.Controller
|
||||||
events:
|
events:
|
||||||
'change [name=customer_id]': @localUserInfo
|
'change [name=customer_id]': @localUserInfo
|
||||||
handlers: [
|
handlers: [
|
||||||
formChanges,
|
@ticketFormChanges,
|
||||||
signatureChanges,
|
signatureChanges,
|
||||||
]
|
]
|
||||||
filter: @form_meta.filter
|
filter: @form_meta.filter
|
||||||
|
@ -297,7 +274,7 @@ class App.TicketCreate extends App.Controller
|
||||||
events:
|
events:
|
||||||
'change [name=customer_id]': @localUserInfo
|
'change [name=customer_id]': @localUserInfo
|
||||||
handlers: [
|
handlers: [
|
||||||
formChanges,
|
@ticketFormChanges,
|
||||||
signatureChanges,
|
signatureChanges,
|
||||||
]
|
]
|
||||||
filter: @form_meta.filter
|
filter: @form_meta.filter
|
||||||
|
@ -312,7 +289,7 @@ class App.TicketCreate extends App.Controller
|
||||||
events:
|
events:
|
||||||
'change [name=customer_id]': @localUserInfo
|
'change [name=customer_id]': @localUserInfo
|
||||||
handlers: [
|
handlers: [
|
||||||
formChanges,
|
@ticketFormChanges,
|
||||||
signatureChanges,
|
signatureChanges,
|
||||||
]
|
]
|
||||||
filter: @form_meta.filter
|
filter: @form_meta.filter
|
||||||
|
|
|
@ -64,29 +64,6 @@ class Index extends App.ControllerContent
|
||||||
groupFilter = [groupFilter]
|
groupFilter = [groupFilter]
|
||||||
@form_meta.filter.group_id = groupFilter
|
@form_meta.filter.group_id = groupFilter
|
||||||
|
|
||||||
formChanges = (params, attribute, attributes, classname, form, ui) =>
|
|
||||||
if @form_meta.dependencies && @form_meta.dependencies[attribute.name]
|
|
||||||
dependency = @form_meta.dependencies[attribute.name][ parseInt(params[attribute.name]) ]
|
|
||||||
if dependency
|
|
||||||
|
|
||||||
for fieldNameToChange of dependency
|
|
||||||
filter = []
|
|
||||||
if dependency[fieldNameToChange]
|
|
||||||
filter = dependency[fieldNameToChange]
|
|
||||||
|
|
||||||
# find element to replace
|
|
||||||
for item in attributes
|
|
||||||
if item.name is fieldNameToChange
|
|
||||||
item['filter'] = {}
|
|
||||||
item['filter'][ fieldNameToChange ] = filter
|
|
||||||
item.default = params[item.name]
|
|
||||||
#if !item.default
|
|
||||||
# delete item['default']
|
|
||||||
newElement = ui.formGenItem( item, classname, form )
|
|
||||||
|
|
||||||
# replace new option list
|
|
||||||
form.find('[name="' + fieldNameToChange + '"]').closest('.form-group').replaceWith( newElement )
|
|
||||||
|
|
||||||
@html App.view('customer_ticket_create')( head: 'New Ticket' )
|
@html App.view('customer_ticket_create')( head: 'New Ticket' )
|
||||||
|
|
||||||
new App.ControllerForm(
|
new App.ControllerForm(
|
||||||
|
@ -95,7 +72,7 @@ class Index extends App.ControllerContent
|
||||||
model: App.Ticket
|
model: App.Ticket
|
||||||
screen: 'create_top'
|
screen: 'create_top'
|
||||||
handlers: [
|
handlers: [
|
||||||
formChanges
|
@ticketFormChanges
|
||||||
]
|
]
|
||||||
filter: @form_meta.filter
|
filter: @form_meta.filter
|
||||||
autofocus: true
|
autofocus: true
|
||||||
|
@ -115,7 +92,7 @@ class Index extends App.ControllerContent
|
||||||
model: App.Ticket
|
model: App.Ticket
|
||||||
screen: 'create_middle'
|
screen: 'create_middle'
|
||||||
handlers: [
|
handlers: [
|
||||||
formChanges
|
@ticketFormChanges
|
||||||
]
|
]
|
||||||
filter: @form_meta.filter
|
filter: @form_meta.filter
|
||||||
params: defaults
|
params: defaults
|
||||||
|
|
|
@ -267,29 +267,6 @@ class App.TicketZoom extends App.Controller
|
||||||
console.log('SHOW', ticket.id)
|
console.log('SHOW', ticket.id)
|
||||||
el.find('.edit').html('')
|
el.find('.edit').html('')
|
||||||
|
|
||||||
formChanges = (params, attribute, attributes, classname, form, ui) =>
|
|
||||||
if @form_meta.dependencies && @form_meta.dependencies[attribute.name]
|
|
||||||
dependency = @form_meta.dependencies[attribute.name][ parseInt(params[attribute.name]) ]
|
|
||||||
if dependency
|
|
||||||
|
|
||||||
for fieldNameToChange of dependency
|
|
||||||
filter = []
|
|
||||||
if dependency[fieldNameToChange]
|
|
||||||
filter = dependency[fieldNameToChange]
|
|
||||||
|
|
||||||
# find element to replace
|
|
||||||
for item in attributes
|
|
||||||
if item.name is fieldNameToChange
|
|
||||||
item['filter'] = {}
|
|
||||||
item['filter'][ fieldNameToChange ] = filter
|
|
||||||
item.default = params[item.name]
|
|
||||||
#if !item.default
|
|
||||||
# delete item['default']
|
|
||||||
newElement = ui.formGenItem( item, classname, form )
|
|
||||||
|
|
||||||
# replace new option list
|
|
||||||
form.find('[name="' + fieldNameToChange + '"]').closest('.form-group').replaceWith( newElement )
|
|
||||||
|
|
||||||
defaults = ticket.attributes()
|
defaults = ticket.attributes()
|
||||||
task_state = @taskGet('ticket')
|
task_state = @taskGet('ticket')
|
||||||
modelDiff = @getDiff( defaults, task_state )
|
modelDiff = @getDiff( defaults, task_state )
|
||||||
|
@ -305,7 +282,7 @@ class App.TicketZoom extends App.Controller
|
||||||
screen: 'edit'
|
screen: 'edit'
|
||||||
params: App.Ticket.find(ticket.id)
|
params: App.Ticket.find(ticket.id)
|
||||||
handlers: [
|
handlers: [
|
||||||
formChanges
|
@ticketFormChanges
|
||||||
]
|
]
|
||||||
filter: @form_meta.filter
|
filter: @form_meta.filter
|
||||||
params: defaults
|
params: defaults
|
||||||
|
|
|
@ -279,8 +279,10 @@ class TicketsController < ApplicationController
|
||||||
:assets => assets,
|
:assets => assets,
|
||||||
:links => link_list,
|
:links => link_list,
|
||||||
:tags => tags,
|
:tags => tags,
|
||||||
:form_meta => attributes_to_change,
|
:form_meta => {
|
||||||
:edit_form => attributes_to_change,
|
:filter => attributes_to_change[:filter],
|
||||||
|
:dependencies => attributes_to_change[:dependencies],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue