Fixed edit form validation.

This commit is contained in:
Martin Edenhofer 2013-07-24 10:34:45 +02:00
parent ffb8d460a9
commit dd53ab616c

View file

@ -390,7 +390,7 @@ class Edit extends App.Controller
bind: { bind: {
name: 'ticket_article_type_id' name: 'ticket_article_type_id'
relation: 'TicketArticleType' relation: 'TicketArticleType'
value: ["email"] value: ['email']
}, },
change: { change: {
action: 'show' action: 'show'
@ -448,7 +448,17 @@ class Edit extends App.Controller
ticket = App.Ticket.retrieve( @ticket.id ) ticket = App.Ticket.retrieve( @ticket.id )
@log 'notice', 'update', params, ticket @log 'notice', 'update', params, ticket
article_type = App.TicketArticleType.find( params['ticket_article_type_id'] )
# find sender_id
if @isRole('Customer')
sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
article_type = App.TicketArticleType.findByAttribute( 'name', 'web' )
params.ticket_article_type_id = article_type.id
params.ticket_article_sender_id = sender.id
else
sender = App.TicketArticleSender.findByAttribute( 'name', 'Agent' )
article_type = App.TicketArticleType.find( params['ticket_article_type_id'] )
params.ticket_article_sender_id = sender.id
# update ticket # update ticket
ticket_update = {} ticket_update = {}
@ -465,6 +475,7 @@ class Edit extends App.Controller
alert( App.i18n.translateContent('Title needed') ) alert( App.i18n.translateContent('Title needed') )
return return
# validate email params
if article_type.name is 'email' if article_type.name is 'email'
# check if recipient exists # check if recipient exists
@ -483,9 +494,8 @@ class Edit extends App.Controller
attachmentTranslatedRegExp = new RegExp( attachmentTranslated, 'i' ) attachmentTranslatedRegExp = new RegExp( attachmentTranslated, 'i' )
if params['body'].match(/attachment/i) || params['body'].match( attachmentTranslatedRegExp ) if params['body'].match(/attachment/i) || params['body'].match( attachmentTranslatedRegExp )
if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') )
return
else
@autosaveStart() @autosaveStart()
return
ticket.load( ticket_update ) ticket.load( ticket_update )
@log 'notice', 'update ticket', ticket_update, ticket @log 'notice', 'update ticket', ticket_update, ticket
@ -493,60 +503,55 @@ class Edit extends App.Controller
# disable form # disable form
@formDisable(e) @formDisable(e)
# validate ticket
errors = ticket.validate() errors = ticket.validate()
if errors if errors
@log 'error', 'update', errors @log 'error', 'update', errors
@formEnable(e) @formEnable(e)
@autosaveStart() @autosaveStart()
return
# validate article
if params['body']
article = new App.TicketArticle
params.from = @Session.get( 'firstname' ) + ' ' + @Session.get( 'lastname' )
params.ticket_id = ticket.id
params.form_id = @form_id
if !params['internal']
params['internal'] = false
@log 'notice', 'update article', params, sender
article.load(params)
errors = article.validate()
if errors
@log 'error', 'update article', errors
@formEnable(e)
@autosaveStart()
return
ticket.save( ticket.save(
success: (r) => success: (r) =>
# create article # reset form after save
if params['body'] if article
article = new App.TicketArticle
params.from = @Session.get( 'firstname' ) + ' ' + @Session.get( 'lastname' )
params.ticket_id = ticket.id
params.form_id = @form_id
if !params['internal']
params['internal'] = false
# find sender_id
if @isRole('Customer')
sender = App.TicketArticleSender.findByAttribute( 'name', 'Customer' )
type = App.TicketArticleType.findByAttribute( 'name', 'web' )
params['ticket_article_type_id'] = type.id
else
sender = App.TicketArticleSender.findByAttribute( 'name', 'Agent' )
params.ticket_article_sender_id = sender.id
@log 'notice', 'update article', params, sender
article.load(params)
errors = article.validate()
if errors
@log 'error', 'update article', errors
# reset form after save
App.TaskManager.update( @task_key, { 'state': {} })
article.save( article.save(
success: (r) => success: (r) =>
@ui.fetch( ticket.id, true ) @ui.fetch( ticket.id, true )
# reset form after save
App.TaskManager.update( @task_key, { 'state': {} })
error: (r) => error: (r) =>
@log 'error', 'update article', r @log 'error', 'update article', r
) )
else else
# reset form after save # reset form after save
App.TaskManager.update( @task_key, { 'state': {} }) App.TaskManager.update( @task_key, { 'state': {} })
@ui.fetch( ticket.id, true ) @ui.fetch( ticket.id, true )
) )
# errors = article.validate()
# @log 'error new', errors
# @formValidate( form: e.target, errors: errors )
return false
reset: (e) => reset: (e) =>
e.preventDefault() e.preventDefault()
App.TaskManager.update( @task_key, { 'state': {} }) App.TaskManager.update( @task_key, { 'state': {} })