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,6 +83,24 @@ class Index extends App.Controller
|
||||||
# create ticket
|
# create ticket
|
||||||
object = new App.Ticket
|
object = new App.Ticket
|
||||||
@log 'updateAttributes', params
|
@log 'updateAttributes', 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)
|
object.load(params)
|
||||||
|
|
||||||
# validate form
|
# validate form
|
||||||
|
@ -102,24 +120,6 @@ class Index extends App.Controller
|
||||||
object.save(
|
object.save(
|
||||||
success: (r) =>
|
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 UI
|
||||||
@notify
|
@notify
|
||||||
type: 'success',
|
type: 'success',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class App.Ticket extends App.Model
|
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
|
@extend Spine.Model.Ajax
|
||||||
# @url: '/tickets'
|
# @url: '/tickets'
|
||||||
@configure_attributes = [
|
@configure_attributes = [
|
||||||
|
|
|
@ -20,11 +20,42 @@ class TicketsController < ApplicationController
|
||||||
@ticket = Ticket.new(params[:ticket])
|
@ticket = Ticket.new(params[:ticket])
|
||||||
@ticket.created_by_id = current_user.id
|
@ticket.created_by_id = current_user.id
|
||||||
|
|
||||||
if @ticket.save
|
# check if article is given
|
||||||
render :json => @ticket, :status => :created
|
if !params[:article]
|
||||||
else
|
render :json => 'article hash is missing', :status => :unprocessable_entity
|
||||||
render :json => @ticket.errors, :status => :unprocessable_entity
|
return
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# PUT /tickets/1
|
# PUT /tickets/1
|
||||||
|
|
Loading…
Reference in a new issue