Moved history and merge into extra files.

This commit is contained in:
Martin Edenhofer 2012-07-04 23:36:39 +02:00
parent 834ccce2f6
commit 62733c0f58
6 changed files with 184 additions and 74 deletions

View file

@ -0,0 +1,69 @@
class App.TicketHistory extends App.ControllerModal
constructor: ->
super
@fetch(@ticket_id)
fetch: (@ticket_id) ->
# get data
@ajax = new App.Ajax
@ajax.ajax(
type: 'GET',
url: '/ticket_history/' + ticket_id,
data: {
# view: @view
}
# processData: true,
success: (data, status, xhr) =>
# remember ticket
@ticket = data.ticket
# load user collection
@loadCollection( type: 'User', data: data.users )
# load ticket collection
@loadCollection( type: 'Ticket', data: [data.ticket] )
# load history_type collections
@loadCollection( type: 'HistoryType', data: data.history_types )
# load history_object collections
@loadCollection( type: 'HistoryObject', data: data.history_objects )
# load history_attributes collections
@loadCollection( type: 'HistoryAttribute', data: data.history_attributes )
# load history collections
App.History.deleteAll()
@loadCollection( type: 'History', data: data.history )
# render page
@render()
)
render: ->
# create table/overview
table = @table(
overview_extended: [
{ name: 'type', },
{ name: 'attribute', },
{ name: 'value_from', },
{ name: 'value_to', },
{ name: 'created_by', class: 'user-data', data: { id: 1 } },
{ name: 'created_at', callback: @humanTime },
],
model: App.History,
objects: App.History.all(),
)
@html App.view('agent_ticket_history')(
# head: 'New User',
# form: @formGen( model: App.User, required: 'quick' ),
)
@el.find('.table_history').append(table)
@modalShow()
@userPopups()

View file

@ -0,0 +1,55 @@
class App.TicketMerge extends App.ControllerModal
constructor: ->
super
@render()
render: ->
@html App.view('agent_ticket_merge')(
# head: 'New User',
# form: @formGen( model: App.User, required: 'quick' ),
)
@log '123123123'
@modalShow()
submit: (e) =>
e.preventDefault()
params = @formParam(e.target)
# merge tickets
@ajax = new App.Ajax
@ajax.ajax(
type: 'GET',
url: '/ticket_merge/' + @ticket_id + '/' + params['master_ticket_number'],
data: {
# view: @view
}
processData: true,
success: (data, status, xhr) =>
if data['result'] is 'success'
@loadCollection( type: 'Ticket', data: [data.master_ticket] )
@loadCollection( type: 'Ticket', data: [data.slave_ticket] )
@modalHide()
# view ticket
@log 'nav...', App.Ticket.find( data.master_ticket['id'] )
@navigate '#ticket/zoom/' + data.master_ticket['id']
# notify UI
@notify
type: 'success',
msg: T( 'Ticket %s merged!', data.slave_ticket['number'] ),
timeout: 6000,
else
# notify UI
@notify
type: 'error',
msg: T( data['message'] ),
timeout: 6000,
# error: =>
)

View file

@ -7,7 +7,8 @@ class Index extends App.Controller
# 'click [data-type=reply-all]': 'replyall',
'click [data-type=public]': 'public_internal',
'click [data-type=internal]': 'public_internal',
'click [data-type=history]': 'history_view',
'click [data-type=history]': 'history_dialog',
'click [data-type=merge]': 'merge_dialog',
'change [name="ticket_article_type_id"]': 'form_update',
'click .show_toogle': 'show_toogle',
@ -26,6 +27,7 @@ class Index extends App.Controller
@fetch(@ticket_id)
fetch: (ticket_id) ->
# get data
@ajax = new App.Ajax
@ajax.ajax(
@ -208,9 +210,13 @@ class Index extends App.Controller
else
$(e.target).parent().next('div').show()
history_view: (e) ->
history_dialog: (e) ->
e.preventDefault()
new History( ticket_id: @ticket_id )
new App.TicketHistory( ticket_id: @ticket_id )
merge_dialog: (e) ->
e.preventDefault()
new App.TicketMerge( ticket_id: @ticket_id )
public_internal: (e) ->
e.preventDefault()
@ -370,75 +376,5 @@ class Index extends App.Controller
return false
class History extends App.ControllerModal
constructor: ->
super
@fetch(@ticket_id)
fetch: (@ticket_id) ->
# get data
@ajax = new App.Ajax
@ajax.ajax(
type: 'GET',
url: '/ticket_history/' + ticket_id,
data: {
# view: @view
}
# processData: true,
success: (data, status, xhr) =>
# remember ticket
@ticket = data.ticket
# load user collection
@loadCollection( type: 'User', data: data.users )
# load ticket collection
@loadCollection( type: 'Ticket', data: [data.ticket] )
# load history_type collections
@loadCollection( type: 'HistoryType', data: data.history_types )
# load history_object collections
@loadCollection( type: 'HistoryObject', data: data.history_objects )
# load history_attributes collections
@loadCollection( type: 'HistoryAttribute', data: data.history_attributes )
# load history collections
App.History.deleteAll()
@loadCollection( type: 'History', data: data.history )
# render page
@render()
)
render: ->
# create table/overview
table = @table(
overview_extended: [
{ name: 'type', },
{ name: 'attribute', },
{ name: 'value_from', },
{ name: 'value_to', },
{ name: 'created_by', class: 'user-data', data: { id: 1 } },
{ name: 'created_at', callback: @humanTime },
],
model: App.History,
objects: App.History.all(),
)
@html App.view('agent_ticket_history')(
# head: 'New User',
# form: @formGen( model: App.User, required: 'quick' ),
)
@el.find('.table_history').append(table)
@modalShow()
@userPopups()
Config.Routes['ticket/zoom/:ticket_id'] = Index
Config.Routes['ticket/zoom/:ticket_id/:article_id'] = Index

View file

@ -1,6 +1,6 @@
<div class="modal-header">
<a href="#" class="close">&times;</a>
<h3>History</h3>
<h3><%- T('History') %></h3>
</div>
<div class="modal-body">
<form class="form-horizontal"></form>

View file

@ -399,6 +399,54 @@ class TicketOverviewsController < ApplicationController
}
end
# GET /ticket_merge/1/1
def ticket_merge
# check master ticket
ticket_master = Ticket.where( :number => params[:master_ticket_number] ).first
if !ticket_master
render :json => {
:result => 'faild',
:message => 'No such master ticket number!',
}
return
end
# check slave ticket
ticket_slave = Ticket.where( :id => params[:slave_ticket_id] ).first
if !ticket_slave
render :json => {
:result => 'faild',
:message => 'No such slave ticket!',
}
return
end
# check diffetent ticket ids
if ticket_slave.id == ticket_master.id
render :json => {
:result => 'faild',
:message => 'Can\'t merge ticket with it self!',
}
return
end
# merge ticket
success = ticket_slave.merge_to(
{
:ticket_id => ticket_master.id,
:created_by_id => current_user.id,
}
)
# return result
render :json => {
:result => 'success',
:master_ticket => ticket_master.attributes,
:slave_ticket => ticket_slave.attributes,
}
end
# GET /activity_stream
# GET /activity_stream.json
def activity_stream

View file

@ -19,6 +19,8 @@ module ExtraRoutes
map.match '/ticket_create', :to => 'ticket_overviews#ticket_create'
map.match '/user_search', :to => 'ticket_overviews#user_search'
map.match '/ticket_merge/:slave_ticket_id/:master_ticket_number', :to => 'ticket_overviews#ticket_merge'
end
module_function :add
end