Fixed ticket update and bulk action.

This commit is contained in:
Martin Edenhofer 2012-09-13 02:43:45 +02:00
parent 7059cc7a24
commit 419c65f9f8
7 changed files with 146 additions and 92 deletions

View file

@ -284,7 +284,7 @@ class App.ControllerForm extends App.Controller
for item in ui.model.configure_attributes for item in ui.model.configure_attributes
if item.name is toChangeAttribute if item.name is toChangeAttribute
item.display = false item.display = false
item['filter'][toChangeAttribute]['id'] = newListAttributes item['filter'][toChangeAttribute] = newListAttributes
if params[changedAttribute] if params[changedAttribute]
item.default = params[toChangeAttribute] item.default = params[toChangeAttribute]
if !item.default if !item.default
@ -362,15 +362,12 @@ class App.ControllerForm extends App.Controller
for record in App[attribute.relation].all() for record in App[attribute.relation].all()
# check all filter attributes # check all filter attributes
for key of filter for key in filter
# check all filter values as array # check all filter values as array
if filter[key] # if it's matching, use it for selection
for value in filter[key] if record['id'] is key
list.push record
# if it's matching, use it for selection
if record[key] is value
list.push record
else else
list = App[attribute.relation].all() list = App[attribute.relation].all()

View file

@ -193,32 +193,22 @@ class Index extends App.Controller
bulk_form: => bulk_form: =>
@configure_attributes_ticket = [ @configure_attributes_ticket = [
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', nulloption: true, default: '', class: 'span2', item_class: 'keepleft' }, { name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', filter: @bulk, nulloption: true, default: '', class: 'span2', item_class: 'keepleft' },
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', nulloption: true, default: '', class: 'span2', item_class: 'keepleft' }, { name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', filter: @bulk, nulloption: true, default: '', class: 'span2', item_class: 'keepleft' },
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: true, relation: 'Group', nulloption: true, class: 'span2', item_class: 'keepleft' }, { name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: true, relation: 'Group', filter: @bulk, nulloption: true, class: 'span2', item_class: 'keepleft' },
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, relation: 'User', filter: @bulk, nulloption: true, class: 'span2', item_class: 'keepleft' }, { name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, relation: 'User', filter: @bulk, nulloption: true, class: 'span2', item_class: 'keepleft' },
] ]
form_ticket = @formGen( model: { configure_attributes: @configure_attributes_ticket, className: 'create' } )
@configure_attributes_article = [
# { name: 'from', display: 'From', tag: 'input', type: 'text', limit: 100, null: false, class: 'span8', },
{ name: 'to', display: 'To', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'cc', display: 'Cc', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'in_reply_to', display: 'In Reply to', tag: 'input', type: 'text', limit: 100, null: true, class: 'span7', item_class: 'hide' },
{ name: 'body', display: 'Text', tag: 'textarea', rows: 4, limit: 100, null: true, class: 'span7', },
{ name: 'ticket_article_type_id', display: 'Type', tag: 'select', multiple: false, null: true, relation: 'TicketArticleType', default: '9', class: 'medium', item_class: 'keepleft' },
{ name: 'internal', display: 'Visability', tag: 'radio', default: false, null: true, options: { true: 'internal', false: 'public' }, class: 'medium', item_class: 'keepleft' },
# { name: 'ticket_article_sender_id', display: 'Sender', tag: 'select', multiple: false, null: true, relation: 'TicketArticleSender', default: '', class: 'medium' },
]
form_article = @formGen( model: { configure_attributes: @configure_attributes_article } )
# render init page # render init page
html = App.view('agent_ticket_view/bulk')( html = $( App.view('agent_ticket_view/bulk')() )
meta: @overview.meta, new App.ControllerForm(
form_ticket: form_ticket, el: html.find('#form-ticket-bulk'),
# form_article: form_article, model: {
configure_attributes: @configure_attributes_ticket,
className: 'create',
},
form_data: @bulk,
) )
html = $(html)
# html.delegate('.bulk-action-form', 'submit', (e) => # html.delegate('.bulk-action-form', 'submit', (e) =>
html.bind('submit', (e) => html.bind('submit', (e) =>
e.preventDefault() e.preventDefault()

View file

@ -85,15 +85,15 @@ class Index extends App.Controller
# set title # set title
@title 'Ticket Zoom ' + @ticket.number @title 'Ticket Zoom ' + @ticket.number
@configure_attributes_ticket = [ @configure_attributes_ticket = [
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', translate: true, class: 'span2', item_class: 'keepleft' }, { name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', filter: @edit_form, translate: true, class: 'span2', item_class: 'keepleft' },
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', translate: true, class: 'span2', item_class: 'keepleft' }, { name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', filter: @edit_form, translate: true, class: 'span2', item_class: 'keepleft' },
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: true, relation: 'Group', class: 'span2', item_class: 'keepleft' }, { name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: true, relation: 'Group', filter: @edit_form, class: 'span2', item_class: 'keepleft' },
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, relation: 'User', filter: @edit_form, nulloption: true, class: 'span2', item_class: 'keepleft' }, { name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, relation: 'User', filter: @edit_form, nulloption: true, class: 'span2', item_class: 'keepleft' },
] ]
if @isRole('Customer') if @isRole('Customer')
@configure_attributes_ticket = [ @configure_attributes_ticket = [
{ name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', translate: true, class: 'span2', item_class: 'keepleft' }, { name: 'ticket_state_id', display: 'State', tag: 'select', multiple: false, null: true, relation: 'TicketState', filter: @edit_form, translate: true, class: 'span2', item_class: 'keepleft' },
{ name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', translate: true, class: 'span2', item_class: 'keepleft' }, { name: 'ticket_priority_id', display: 'Priority', tag: 'select', multiple: false, null: true, relation: 'TicketPriority', filter: @edit_form, translate: true, class: 'span2', item_class: 'keepleft' },
] ]
@configure_attributes_article = [ @configure_attributes_article = [
@ -114,17 +114,30 @@ class Index extends App.Controller
{ name: 'body', display: 'Text', tag: 'textarea', rows: 5, limit: 100, null: true, class: 'span7', item_class: '' }, { name: 'body', display: 'Text', tag: 'textarea', rows: 5, limit: 100, null: true, class: 'span7', item_class: '' },
] ]
form_ticket = @formGen( model: { configure_attributes: @configure_attributes_ticket, className: 'create' }, params: @ticket )
form_article = @formGen( model: { configure_attributes: @configure_attributes_article } )
@html App.view('agent_ticket_zoom')( @html App.view('agent_ticket_zoom')(
ticket: @ticket, ticket: @ticket,
articles: @articles, articles: @articles,
form_ticket: form_ticket,
form_article: form_article,
nav: @nav, nav: @nav,
) )
new App.ControllerForm(
el: @el.find('#form-ticket-update'),
model: {
configure_attributes: @configure_attributes_ticket,
className: 'create',
},
params: @ticket
form_data: @edit_form,
)
new App.ControllerForm(
el: @el.find('#form-article-update'),
model: {
configure_attributes: @configure_attributes_article,
},
form_data: @edit_form,
)
@el.find('textarea').elastic() @el.find('textarea').elastic()
# enable user popups # enable user popups

View file

@ -1,5 +1,4 @@
<form class="form-stacked keepleft update-box bulk-action-form"> <form class="form-stacked keepleft update-box bulk-action-form">
<%- @form_ticket %> <div id="form-ticket-bulk"></div>
<%- @form_article %>
<input type="submit" class="btn primary submit" value="update"> <input type="submit" class="btn primary submit" value="update">
</form> </form>

View file

@ -79,14 +79,11 @@
</div> </div>
<div class="span8 well-muted article-message"> <div class="span8 well-muted article-message">
<form class="form-stacked keepleft"> <form class="form-stacked keepleft">
<div id="form-ticket-update"></div>
<%- @form_ticket %> <div id="form-article-update"></div>
<div class="keepleft" id="file-uploader"></div>
<%- @form_article %> &nbsp;
<button type="submit" class="btn btn-primary submit"><%- T('Submit') %></button>
<div class="keepleft" id="file-uploader"></div>
&nbsp;
<button type="submit" class="btn btn-primary submit"><%- T('Submit') %></button>
</form> </form>
</div> </div>
</div> </div>

View file

@ -60,14 +60,25 @@ class TicketOverviewsController < ApplicationController
end end
} }
# get data for bulk action # get groups
bulk_owners = Role.where( :name => ['Agent'] ).first.users.select(:id).where( :active => true ).uniq() group_ids = []
bulk_owner_ids = [] Group.where( :active => true ).each { |group|
bulk_owners.each { |user| group_ids.push group.id
bulk_owner_ids.push user.id }
if !users[ user.id ] agents = {}
users[ user.id ] = User.user_data_full( user.id ) Ticket.agents.each { |user|
end agents[ user.id ] = 1
}
groups_users = {}
group_ids.each {|group_id|
groups_users[ group_id ] = []
Group.find(group_id).users.each {|user|
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)
end
}
} }
# return result # return result
@ -77,9 +88,7 @@ class TicketOverviewsController < ApplicationController
:tickets_count => overview[:tickets_count], :tickets_count => overview[:tickets_count],
:users => users, :users => users,
:bulk => { :bulk => {
:owner_id => { :group_id__owner_id => groups_users,
:id => bulk_owner_ids,
},
}, },
} }
end end
@ -89,18 +98,18 @@ class TicketOverviewsController < ApplicationController
def ticket_create def ticket_create
# get attributes # get attributes
(users, ticket_owner_ids, ticket_group_ids, ticket_state_ids, ticket_priority_ids) = Ticket.create_attributes( create_attributes = Ticket.create_attributes(
:current_user_id => current_user.id, :current_user_id => current_user.id,
) )
# split data # split data
ticket = nil ticket = nil
articles = nil articles = nil
users = {}
if params[:ticket_id] && params[:article_id] if params[:ticket_id] && params[:article_id]
ticket = Ticket.find( params[:ticket_id] ) ticket = Ticket.find( params[:ticket_id] )
# get related users # get related users
users = {}
if !users[ticket.owner_id] 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 end
@ -133,25 +142,18 @@ class TicketOverviewsController < ApplicationController
end end
end end
create_attributes[:owner_id].each {|user_id|
if !users[user_id]
users[user_id] = User.user_data_full(user_id)
end
}
# return result # return result
render :json => { render :json => {
:ticket => ticket, :ticket => ticket,
:articles => [ article ], :articles => [ article ],
:users => users, :users => users,
:edit_form => { :edit_form => create_attributes,
:owner_id => {
:id => ticket_owner_ids
},
:group_id => {
:id => ticket_group_ids
},
:ticket_state_id => {
:id => ticket_state_ids
},
:ticket_priority_id => {
:id => ticket_priority_ids
}
}
} }
end end
@ -213,15 +215,35 @@ class TicketOverviewsController < ApplicationController
end end
} }
# get groups
group_ids = []
Group.where( :active => true ).each { |group|
group_ids.push group.id
}
agents = {}
Ticket.agents.each { |user|
agents[ user.id ] = 1
}
groups_users = {}
group_ids.each {|group_id|
groups_users[ group_id ] = []
Group.find(group_id).users.each {|user|
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)
end
}
}
# return result # return result
render :json => { render :json => {
:ticket => ticket, :ticket => ticket,
:articles => articles_used, :articles => articles_used,
:users => users, :users => users,
:edit_form => { :edit_form => {
:owner_id => { :group_id__owner_id => groups_users,
:id => owner_ids :owner_id => owner_ids,
}
} }
} }
end end

View file

@ -396,12 +396,34 @@ class ClientState
@data[cache_key] = overview_data_time @data[cache_key] = overview_data_time
overview_data = CacheIn.get( cache_key, { :ignore_expire => true } ) overview_data = CacheIn.get( cache_key, { :ignore_expire => true } )
self.log "push overview_data for user #{user.id}" self.log "push overview_data for user #{user.id}"
users = {} users = {}
tickets = [] tickets = []
overview_data[:tickets].each {|ticket_id| overview_data[:tickets].each {|ticket_id|
self.ticket( ticket_id, tickets, users ) self.ticket( ticket_id, tickets, users )
} }
# get groups
group_ids = []
Group.where( :active => true ).each { |group|
group_ids.push group.id
}
agents = {}
Ticket.agents.each { |user|
agents[ user.id ] = 1
}
groups_users = {}
groups_users[''] = []
group_ids.each {|group_id|
groups_users[ group_id ] = []
Group.find(group_id).users.each {|user|
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)
end
}
}
# send update to browser # send update to browser
self.transaction({ self.transaction({
:data => { :data => {
@ -411,7 +433,11 @@ class ClientState
:collections => { :collections => {
:User => users, :User => users,
:Ticket => tickets, :Ticket => tickets,
} },
:bulk => {
:group_id__owner_id => groups_users,
:owner_id => [],
},
}, },
:event => [ 'loadCollection', 'ticket_overview_rebuild' ], :event => [ 'loadCollection', 'ticket_overview_rebuild' ],
:collection => 'ticket_overview_' + overview.meta[:url].to_s, :collection => 'ticket_overview_' + overview.meta[:url].to_s,
@ -424,13 +450,23 @@ class ClientState
ticket_create_attributes_time = CacheIn.get_time( cache_key, { :ignore_expire => true } ) ticket_create_attributes_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
if ticket_create_attributes_time && @data[:ticket_create_attributes_time] != ticket_create_attributes_time if ticket_create_attributes_time && @data[:ticket_create_attributes_time] != ticket_create_attributes_time
@data[:ticket_create_attributes_time] = ticket_create_attributes_time @data[:ticket_create_attributes_time] = ticket_create_attributes_time
ticket_create_attributes = CacheIn.get( cache_key, { :ignore_expire => true } ) create_attributes = CacheIn.get( cache_key, { :ignore_expire => true } )
users = {}
create_attributes[:owner_id].each {|user_id|
if !users[user_id]
users[user_id] = User.user_data_full(user_id)
end
}
data = {
:users => users,
:edit_form => create_attributes,
}
self.log "push ticket_create_attributes for user #{user.id}" self.log "push ticket_create_attributes for user #{user.id}"
# send update to browser # send update to browser
self.transaction({ self.transaction({
:collection => 'ticket_create_attributes', :collection => 'ticket_create_attributes',
:data => ticket_create_attributes, :data => data,
}) })
end end