Added support of signature.

This commit is contained in:
Martin Edenhofer 2012-10-02 07:46:08 +02:00
parent abe409ad94
commit c3e6c4028a
3 changed files with 66 additions and 37 deletions

View file

@ -22,6 +22,8 @@ class Index extends App.Controller
@edit_form = undefined
@ticket_id = params.ticket_id
@article_id = params.article_id
@signature = undefined
@signature_used = undefined
@key = 'ticket::' + @ticket_id
cache = App.Store.get( @key )
@ -49,10 +51,13 @@ class Index extends App.Controller
# reset old indexes
@ticket = undefined
@articles = undefined
# get edit form attributes
@edit_form = data.edit_form
# get signature
@signature = data.signature
# load user collection
App.Collection.load( type: 'User', data: data.users )
@ -133,6 +138,9 @@ class Index extends App.Controller
model: {
configure_attributes: @configure_attributes_article,
},
# params: {
# body: @signature.body,
# }
form_data: @edit_form,
)
@ -205,13 +213,13 @@ class Index extends App.Controller
public_internal: (e) ->
e.preventDefault()
article_id = $(e.target).parents('[data-id]').data('id')
# storage update
article = App.TicketArticle.find(article_id)
internal = true
if article.internal == true
internal = false
article.updateAttributes(
internal: internal
)
@ -258,6 +266,16 @@ class Index extends App.Controller
@el.find('[name="cc"]').parents('.control-group').removeClass('hide')
# @el.find('[name="subject"]').parents('.control-group').removeClass('hide')
# add signature
if !@signature_used && @signature && @signature.body
@signature_used = true
body = @el.find('[name="body"]').val() || ''
body = body + "\n" + @signature.body
@el.find('[name="body"]').val( body )
# update textarea size
@el.find('[name="body"]').trigger('change')
reply: (e) =>
e.preventDefault()
article_id = $(e.target).parents('[data-id]').data('id')
@ -279,7 +297,7 @@ class Index extends App.Controller
@el.find('[name="cc"]').val('')
@el.find('[name="subject"]').val('')
@el.find('[name="in_reply_to"]').val('')
if article.message_id
@el.find('[name="in_reply_to"]').val(article.message_id)
@ -289,9 +307,9 @@ class Index extends App.Controller
to = customer.accounts['twitter'].username || customer.accounts['twitter'].uid
@log 'c', customer
@el.find('[name="body"]').val('@' + to)
else if article_type.name is 'twitter direct-message'
# show to
to = customer.accounts['twitter'].username || customer.accounts['twitter'].uid
@el.find('[name="to"]').val(to)
@ -306,7 +324,7 @@ class Index extends App.Controller
selection = window.Session['UISelection'].trim()
selection = selection.replace /^(.*)$/mg, (match) =>
'> ' + match
body = body + selection
body = selection + "\n" + body
@el.find('[name="body"]').val(body)
# update textarea size

View file

@ -34,13 +34,13 @@ class TicketsController < ApplicationController
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,
@ -87,18 +87,16 @@ class TicketsController < ApplicationController
head :ok
end
# GET /ticket_customer
# GET /tickets_customer
def ticket_customer
# get closed/open states
ticket_state_list_open = Ticket::State.where(
:ticket_state_type_id => Ticket::StateType.where(:name => ['new','open', 'pending remidner', 'pending action'])
:ticket_state_type_id => Ticket::StateType.where( :name => ['new','open', 'pending reminder', 'pending action'] )
)
ticket_state_list_closed = Ticket::State.where(
:ticket_state_type_id => Ticket::StateType.where(:name => ['closed'] )
:ticket_state_type_id => Ticket::StateType.where( :name => ['closed'] )
)
# get tickets
@ -150,10 +148,10 @@ class TicketsController < ApplicationController
def ticket_history
# get ticket data
ticket = Ticket.find(params[:id])
ticket = Ticket.find( params[:id] )
# permissin check
return if !ticket_permission(ticket)
return if !ticket_permission( ticket )
# get history of ticket
history = History.history_list( 'Ticket', params[:id], 'Ticket::Article' )
@ -212,7 +210,7 @@ class TicketsController < ApplicationController
end
# permissin check
return if !ticket_permission(ticket_slave)
return if !ticket_permission( ticket_slave )
# check diffetent ticket ids
if ticket_slave.id == ticket_master.id
@ -243,31 +241,43 @@ class TicketsController < ApplicationController
def ticket_full
# permission check
ticket = Ticket.find(params[:id])
return if !ticket_permission(ticket)
ticket = Ticket.find( params[:id] )
return if !ticket_permission( ticket )
# get related users
users = {}
if !users[ticket.owner_id]
users[ticket.owner_id] = User.user_data_full(ticket.owner_id)
users[ticket.owner_id] = User.user_data_full( ticket.owner_id )
end
if !users[ticket.customer_id]
users[ticket.customer_id] = User.user_data_full(ticket.customer_id)
users[ticket.customer_id] = User.user_data_full( ticket.customer_id )
end
if !users[ticket.created_by_id]
users[ticket.created_by_id] = User.user_data_full(ticket.created_by_id)
users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id )
end
owner_ids = []
ticket.agent_of_group.each { |user|
owner_ids.push user.id
if !users[user.id]
users[user.id] = User.user_data_full(user.id)
users[user.id] = User.user_data_full( user.id )
end
}
# log object as viewed
log_view(ticket)
log_view( ticket )
# get signature
signature = ticket.group.signature.attributes
# replace tags
signature['body'] = NotificationFactory.build(
:string => signature['body'],
:objects => {
:ticket => ticket,
:user => current_user,
}
)
# get related articles
ticket = ticket.attributes
@ -293,7 +303,7 @@ class TicketsController < ApplicationController
# load users
if !users[article.created_by_id]
users[article.created_by_id] = User.user_data_full(article.created_by_id)
users[article.created_by_id] = User.user_data_full( article.created_by_id )
end
}
@ -313,16 +323,17 @@ class TicketsController < ApplicationController
next if !agents[ user.id ]
groups_users[ group_id ].push user.id
if !users[user.id]
users[user.id] = User.user_data_full(user.id)
users[user.id] = User.user_data_full( user.id )
end
}
}
# return result
render :json => {
:ticket => ticket,
:articles => articles_used,
:users => users,
:ticket => ticket,
:articles => articles_used,
:signature => signature,
:users => users,
:edit_form => {
:group_id__owner_id => groups_users,
:owner_id => owner_ids,
@ -347,20 +358,20 @@ class TicketsController < ApplicationController
# get related users
if !users[ticket.owner_id]
users[ticket.owner_id] = User.user_data_full(ticket.owner_id)
users[ticket.owner_id] = User.user_data_full( ticket.owner_id )
end
if !users[ticket.customer_id]
users[ticket.customer_id] = User.user_data_full(ticket.customer_id)
users[ticket.customer_id] = User.user_data_full( ticket.customer_id )
end
if !users[ticket.created_by_id]
users[ticket.created_by_id] = User.user_data_full(ticket.created_by_id)
users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id )
end
owner_ids = []
ticket.agent_of_group.each { |user|
owner_ids.push user.id
if !users[user.id]
users[user.id] = User.user_data_full(user.id)
users[user.id] = User.user_data_full( user.id )
end
}
@ -374,13 +385,13 @@ class TicketsController < ApplicationController
# load users
if !users[article.created_by_id]
users[article.created_by_id] = User.user_data_full(article.created_by_id)
users[article.created_by_id] = User.user_data_full( article.created_by_id )
end
end
create_attributes[:owner_id].each {|user_id|
if !users[user_id]
users[user_id] = User.user_data_full(user_id)
users[user_id] = User.user_data_full( user_id )
end
}

View file

@ -24,7 +24,7 @@ end
module NotificationFactory
def self.build(data)
data[:string].gsub!( /\#\{(.+?)\}/ ) { |s|
# use quoted text
callback = $1
callback.gsub!( /\.body$/ ) { |item|
@ -55,7 +55,7 @@ module NotificationFactory
}
return data[:string]
end
def self.send(data)
sender = Setting.get('notification_sender')
a = Channel::IMAP.new