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) ->
|
||||
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
|
||||
constructor: ->
|
||||
super
|
||||
|
@ -485,10 +510,10 @@ class App.ControllerModal extends App.Controller
|
|||
'.modal-body': 'body'
|
||||
|
||||
events:
|
||||
'submit form': 'onSubmit'
|
||||
'click .js-submit:not(.is-disabled)': 'onSubmit'
|
||||
'submit form': 'onSubmit'
|
||||
'click .js-submit: not(.is-disabled)': 'onSubmit'
|
||||
'click .js-cancel': 'hide'
|
||||
'click .js-close': 'hide'
|
||||
'click .js-close': 'hide'
|
||||
|
||||
className: 'modal fade'
|
||||
|
||||
|
|
|
@ -205,29 +205,6 @@ class App.TicketCreate extends App.Controller
|
|||
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) =>
|
||||
if attribute && attribute.name is 'group_id'
|
||||
signature = undefined
|
||||
|
@ -274,7 +251,7 @@ class App.TicketCreate extends App.Controller
|
|||
events:
|
||||
'change [name=customer_id]': @localUserInfo
|
||||
handlers: [
|
||||
formChanges,
|
||||
@ticketFormChanges,
|
||||
signatureChanges,
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
|
@ -297,7 +274,7 @@ class App.TicketCreate extends App.Controller
|
|||
events:
|
||||
'change [name=customer_id]': @localUserInfo
|
||||
handlers: [
|
||||
formChanges,
|
||||
@ticketFormChanges,
|
||||
signatureChanges,
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
|
@ -312,7 +289,7 @@ class App.TicketCreate extends App.Controller
|
|||
events:
|
||||
'change [name=customer_id]': @localUserInfo
|
||||
handlers: [
|
||||
formChanges,
|
||||
@ticketFormChanges,
|
||||
signatureChanges,
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
|
|
|
@ -64,29 +64,6 @@ class Index extends App.ControllerContent
|
|||
groupFilter = [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' )
|
||||
|
||||
new App.ControllerForm(
|
||||
|
@ -95,7 +72,7 @@ class Index extends App.ControllerContent
|
|||
model: App.Ticket
|
||||
screen: 'create_top'
|
||||
handlers: [
|
||||
formChanges
|
||||
@ticketFormChanges
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
autofocus: true
|
||||
|
@ -115,7 +92,7 @@ class Index extends App.ControllerContent
|
|||
model: App.Ticket
|
||||
screen: 'create_middle'
|
||||
handlers: [
|
||||
formChanges
|
||||
@ticketFormChanges
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
params: defaults
|
||||
|
|
|
@ -267,29 +267,6 @@ class App.TicketZoom extends App.Controller
|
|||
console.log('SHOW', ticket.id)
|
||||
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()
|
||||
task_state = @taskGet('ticket')
|
||||
modelDiff = @getDiff( defaults, task_state )
|
||||
|
@ -305,7 +282,7 @@ class App.TicketZoom extends App.Controller
|
|||
screen: 'edit'
|
||||
params: App.Ticket.find(ticket.id)
|
||||
handlers: [
|
||||
formChanges
|
||||
@ticketFormChanges
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
params: defaults
|
||||
|
|
|
@ -279,8 +279,10 @@ class TicketsController < ApplicationController
|
|||
:assets => assets,
|
||||
:links => link_list,
|
||||
:tags => tags,
|
||||
:form_meta => attributes_to_change,
|
||||
:edit_form => attributes_to_change,
|
||||
:form_meta => {
|
||||
:filter => attributes_to_change[:filter],
|
||||
:dependencies => attributes_to_change[:dependencies],
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue