Added article data to ticket creation (improve performance).
This commit is contained in:
parent
4d591da87d
commit
9374e93ea8
3 changed files with 55 additions and 24 deletions
|
@ -83,8 +83,26 @@ class Index extends App.Controller
|
|||
# create ticket
|
||||
object = new App.Ticket
|
||||
@log 'updateAttributes', params
|
||||
object.load(params)
|
||||
|
||||
# find sender_id
|
||||
sender = App.TicketArticleSender.findByAttribute("name", "Customer")
|
||||
type = App.TicketArticleType.findByAttribute("name", "phone")
|
||||
group = App.Group.find(params.group_id)
|
||||
|
||||
# create article
|
||||
params['article'] = {
|
||||
from: params.customer_id_autocompletion,
|
||||
to: group.name,
|
||||
subject: params.subject,
|
||||
body: params.body,
|
||||
ticket_article_type_id: type.id,
|
||||
ticket_article_sender_id: sender.id,
|
||||
created_by_id: params.customer_id,
|
||||
}
|
||||
# console.log('params', params)
|
||||
|
||||
object.load(params)
|
||||
|
||||
# validate form
|
||||
errors = object.validate()
|
||||
|
||||
|
@ -101,24 +119,6 @@ class Index extends App.Controller
|
|||
|
||||
object.save(
|
||||
success: (r) =>
|
||||
|
||||
# find sender_id
|
||||
sender = App.TicketArticleSender.findByAttribute("name", "Customer")
|
||||
type = App.TicketArticleType.findByAttribute("name", "phone")
|
||||
|
||||
# create article
|
||||
article = new App.TicketArticle
|
||||
article.load(
|
||||
from: 'some guy',
|
||||
to: 'some group',
|
||||
subject: params.subject,
|
||||
body: params.body,
|
||||
ticket_id: r.id,
|
||||
ticket_article_type_id: type.id,
|
||||
ticket_article_sender_id: sender.id,
|
||||
)
|
||||
article.save()
|
||||
# console.log('params', params)
|
||||
|
||||
# notify UI
|
||||
@notify
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class App.Ticket extends App.Model
|
||||
@configure 'Ticket', 'number', 'title', 'group_id', 'owner_id', 'customer_id', 'ticket_state_id', 'ticket_priority_id'
|
||||
@configure 'Ticket', 'number', 'title', 'group_id', 'owner_id', 'customer_id', 'ticket_state_id', 'ticket_priority_id', 'article'
|
||||
@extend Spine.Model.Ajax
|
||||
# @url: '/tickets'
|
||||
@configure_attributes = [
|
||||
|
|
|
@ -20,11 +20,42 @@ class TicketsController < ApplicationController
|
|||
@ticket = Ticket.new(params[:ticket])
|
||||
@ticket.created_by_id = current_user.id
|
||||
|
||||
if @ticket.save
|
||||
render :json => @ticket, :status => :created
|
||||
else
|
||||
render :json => @ticket.errors, :status => :unprocessable_entity
|
||||
# check if article is given
|
||||
if !params[:article]
|
||||
render :json => 'article hash is missing', :status => :unprocessable_entity
|
||||
return
|
||||
end
|
||||
|
||||
# create ticket
|
||||
if !@ticket.save
|
||||
render :json => @ticket.errors, :status => :unprocessable_entity
|
||||
return
|
||||
end
|
||||
|
||||
# create article if given
|
||||
if params[:article]
|
||||
@article = Ticket::Article.new(params[:article])
|
||||
@article.created_by_id = params[:article][:created_by_id] || current_user.id
|
||||
@article.ticket_id = @ticket.id
|
||||
|
||||
# find attachments in upload cache
|
||||
@article['attachments'] = Store.list(
|
||||
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
|
||||
:o_id => @article.ticket_id
|
||||
)
|
||||
if !@article.save
|
||||
render :json => @article.errors, :status => :unprocessable_entity
|
||||
return
|
||||
end
|
||||
|
||||
# remove attachments from upload cache
|
||||
Store.remove(
|
||||
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
|
||||
:o_id => @article.ticket_id
|
||||
)
|
||||
end
|
||||
|
||||
render :json => @ticket, :status => :created
|
||||
end
|
||||
|
||||
# PUT /tickets/1
|
||||
|
|
Loading…
Reference in a new issue