Merge branch 'develop' of github.com:martini/zammad into develop
This commit is contained in:
commit
fe572ae54b
15 changed files with 191 additions and 220 deletions
|
@ -505,10 +505,10 @@ class App.Controller extends Spine.Controller
|
|||
|
||||
# central method, is getting called on every ticket form change
|
||||
ticketFormChanges: (params, attribute, attributes, classname, form, ui) =>
|
||||
if @form_meta.dependencies && @form_meta.dependencies[attribute.name]
|
||||
dependency = @form_meta.dependencies[attribute.name][ parseInt(params[attribute.name]) ]
|
||||
if @formMeta.dependencies && @formMeta.dependencies[attribute.name]
|
||||
dependency = @formMeta.dependencies[attribute.name][ parseInt(params[attribute.name]) ]
|
||||
if !dependency
|
||||
dependency = @form_meta.dependencies[attribute.name][ params[attribute.name] ]
|
||||
dependency = @formMeta.dependencies[attribute.name][ params[attribute.name] ]
|
||||
if dependency
|
||||
for fieldNameToChange of dependency
|
||||
filter = []
|
||||
|
|
|
@ -15,9 +15,6 @@ class App.TicketCreate extends App.Controller
|
|||
App.TaskManager.remove(@task_key)
|
||||
return
|
||||
|
||||
# set title
|
||||
@form_meta = undefined
|
||||
|
||||
# define default type
|
||||
@default_type = 'phone-in'
|
||||
|
||||
|
@ -29,8 +26,6 @@ class App.TicketCreate extends App.Controller
|
|||
# update navbar highlighting
|
||||
@navupdate '#ticket/create/id/' + @id + split
|
||||
|
||||
@fetch(params)
|
||||
|
||||
# lisen if view need to be rerendered
|
||||
@bind 'ticket_create_rerender', (defaults) =>
|
||||
@log 'notice', 'error', defaults
|
||||
|
@ -41,9 +36,11 @@ class App.TicketCreate extends App.Controller
|
|||
return if !@authenticate(true)
|
||||
@render()
|
||||
|
||||
# bind on new ticket_create_attributes updates
|
||||
@bind 'ticket_create_attributes', (data) =>
|
||||
App.SessionStorage.set('ticket_create_attributes', data)
|
||||
load = (data) =>
|
||||
App.Collection.loadAssets(data.assets)
|
||||
@formMeta = data.form_meta
|
||||
@buildScreen(params)
|
||||
@bindId = App.TicketCreateCollection.one(load)
|
||||
|
||||
changeFormType: (e) =>
|
||||
type = $(e.target).data('type')
|
||||
|
@ -121,9 +118,6 @@ class App.TicketCreate extends App.Controller
|
|||
return false if !diff || _.isEmpty( diff )
|
||||
return true
|
||||
|
||||
release: ->
|
||||
# nothing
|
||||
|
||||
autosave: =>
|
||||
update = =>
|
||||
data = @formParam( @el.find('.ticket-create') )
|
||||
|
@ -135,42 +129,27 @@ class App.TicketCreate extends App.Controller
|
|||
@interval( update, 3000, @id )
|
||||
|
||||
# get data / in case also ticket data for split
|
||||
fetch: (params) ->
|
||||
|
||||
# use cache
|
||||
cache = App.SessionStorage.get('ticket_create_attributes')
|
||||
|
||||
if cache && !params.ticket_id && !params.article_id
|
||||
|
||||
# get edit form attributes
|
||||
@form_meta = cache.form_meta
|
||||
|
||||
# load assets
|
||||
App.Collection.loadAssets(cache.assets)
|
||||
buildScreen: (params) =>
|
||||
|
||||
if !params.ticket_id && !params.article_id
|
||||
@render()
|
||||
else
|
||||
return
|
||||
|
||||
# fetch split ticket data
|
||||
@ajax(
|
||||
id: 'ticket_create' + @task_key
|
||||
id: 'ticket_split' + @task_key
|
||||
type: 'GET'
|
||||
url: @apiPath + '/ticket_create'
|
||||
url: @apiPath + '/ticket_split'
|
||||
data:
|
||||
ticket_id: params.ticket_id
|
||||
article_id: params.article_id
|
||||
processData: true
|
||||
success: (data, status, xhr) =>
|
||||
|
||||
# cache request
|
||||
App.SessionStorage.set('ticket_create_attributes', data)
|
||||
|
||||
# get edit form attributes
|
||||
@form_meta = data.form_meta
|
||||
|
||||
# load assets
|
||||
App.Collection.loadAssets(data.assets)
|
||||
|
||||
# split ticket
|
||||
if data.split && data.split.ticket_id && data.split.article_id
|
||||
# prefill with split ticket
|
||||
t = App.Ticket.find( params.ticket_id ).attributes()
|
||||
a = App.TicketArticle.find( params.article_id )
|
||||
|
||||
|
@ -259,7 +238,7 @@ class App.TicketCreate extends App.Controller
|
|||
@ticketFormChanges,
|
||||
signatureChanges,
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
filter: @formMeta.filter
|
||||
autofocus: true
|
||||
params: params
|
||||
)
|
||||
|
@ -282,7 +261,7 @@ class App.TicketCreate extends App.Controller
|
|||
@ticketFormChanges,
|
||||
signatureChanges,
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
filter: @formMeta.filter
|
||||
params: params
|
||||
noFieldset: true
|
||||
)
|
||||
|
@ -297,7 +276,7 @@ class App.TicketCreate extends App.Controller
|
|||
@ticketFormChanges,
|
||||
signatureChanges,
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
filter: @formMeta.filter
|
||||
params: params
|
||||
)
|
||||
|
||||
|
|
|
@ -13,45 +13,14 @@ class Index extends App.ControllerContent
|
|||
# set title
|
||||
@title 'New Ticket'
|
||||
@form_id = App.ControllerForm.formId()
|
||||
@form_meta = undefined
|
||||
|
||||
@fetch(params)
|
||||
@navupdate '#customer_ticket_new'
|
||||
|
||||
# get data / in case also ticket data for split
|
||||
fetch: (params) ->
|
||||
|
||||
# use cache
|
||||
cache = App.SessionStorage.get( 'ticket_create_attributes' )
|
||||
|
||||
if cache
|
||||
|
||||
# get edit form attributes
|
||||
@form_meta = cache.form_meta
|
||||
|
||||
# load assets
|
||||
App.Collection.loadAssets( cache.assets )
|
||||
|
||||
@render()
|
||||
else
|
||||
@ajax(
|
||||
id: 'ticket_create',
|
||||
type: 'GET',
|
||||
url: @apiPath + '/ticket_create',
|
||||
processData: true,
|
||||
success: (data, status, xhr) =>
|
||||
|
||||
# cache request
|
||||
App.SessionStorage.set( 'ticket_create_attributes', data )
|
||||
|
||||
# get edit form attributes
|
||||
@form_meta = data.form_meta
|
||||
|
||||
# load assets
|
||||
load = (data) =>
|
||||
App.Collection.loadAssets(data.assets)
|
||||
|
||||
@formMeta = data.form_meta
|
||||
@render()
|
||||
)
|
||||
@bindId = App.TicketCreateCollection.one(load)
|
||||
|
||||
render: (template = {}) ->
|
||||
|
||||
|
@ -62,7 +31,7 @@ class Index extends App.ControllerContent
|
|||
if groupFilter
|
||||
if !_.isArray(groupFilter)
|
||||
groupFilter = [groupFilter]
|
||||
@form_meta.filter.group_id = groupFilter
|
||||
@formMeta.filter.group_id = groupFilter
|
||||
|
||||
@html App.view('customer_ticket_create')(
|
||||
head: 'New Ticket'
|
||||
|
@ -77,7 +46,7 @@ class Index extends App.ControllerContent
|
|||
handlers: [
|
||||
@ticketFormChanges
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
filter: @formMeta.filter
|
||||
autofocus: true
|
||||
params: defaults
|
||||
)
|
||||
|
@ -97,7 +66,7 @@ class Index extends App.ControllerContent
|
|||
handlers: [
|
||||
@ticketFormChanges
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
filter: @formMeta.filter
|
||||
params: defaults
|
||||
noFieldset: true
|
||||
)
|
||||
|
@ -109,7 +78,7 @@ class Index extends App.ControllerContent
|
|||
# handlers: [
|
||||
# formChanges
|
||||
# ]
|
||||
# filter: @form_meta.filter
|
||||
# filter: @formMeta.filter
|
||||
# params: defaults
|
||||
#)
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class App.TicketZoom extends App.Controller
|
|||
App.TaskManager.remove(@task_key)
|
||||
return
|
||||
|
||||
@form_meta = undefined
|
||||
@formMeta = undefined
|
||||
@ticket_id = params.ticket_id
|
||||
@article_id = params.article_id
|
||||
@sidebarState = {}
|
||||
|
@ -235,7 +235,7 @@ class App.TicketZoom extends App.Controller
|
|||
@tags = data.tags
|
||||
|
||||
# get edit form attributes
|
||||
@form_meta = data.form_meta
|
||||
@formMeta = data.form_meta
|
||||
|
||||
# load assets
|
||||
App.Collection.loadAssets(data.assets)
|
||||
|
@ -331,7 +331,7 @@ class App.TicketZoom extends App.Controller
|
|||
ticket: @ticket
|
||||
ticket_id: @ticket.id
|
||||
el: @$('.article-new')
|
||||
form_meta: @form_meta
|
||||
formMeta: @formMeta
|
||||
form_id: @form_id
|
||||
defaults: @taskGet('article')
|
||||
task_key: @task_key
|
||||
|
@ -365,7 +365,7 @@ class App.TicketZoom extends App.Controller
|
|||
task_key: @task_key
|
||||
tags: @tags
|
||||
links: @links
|
||||
form_meta: @form_meta
|
||||
formMeta: @formMeta
|
||||
)
|
||||
|
||||
# show article
|
||||
|
|
|
@ -33,7 +33,7 @@ class App.TicketZoomSidebar extends App.Controller
|
|||
handlers: [
|
||||
@ticketFormChanges
|
||||
]
|
||||
filter: @form_meta.filter
|
||||
filter: @formMeta.filter
|
||||
params: defaults
|
||||
#bookmarkable: true
|
||||
)
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
class App._CollectionSingletonBase
|
||||
event: 'to_be_defined'
|
||||
restEndpoint: '/to_be_defined'
|
||||
|
||||
constructor: ->
|
||||
@callbacks = {}
|
||||
@counter = 0
|
||||
|
||||
# read from cache
|
||||
cache = App.SessionStorage.get("collection-#{@event}")
|
||||
if cache
|
||||
@set(cache)
|
||||
|
||||
# websocket updates
|
||||
App.Event.bind @event, (data) =>
|
||||
@set(data)
|
||||
@callback(data)
|
||||
|
||||
get: ->
|
||||
@collection_data
|
||||
|
||||
set: (data) ->
|
||||
App.SessionStorage.set("collection-#{@event}", data)
|
||||
@collection_data = data
|
||||
|
||||
bind: (callback, init = true, one = false) ->
|
||||
@counter += 1
|
||||
|
||||
# start init call if needed
|
||||
if init
|
||||
if @collection_data is undefined
|
||||
@fetch()
|
||||
else
|
||||
callback(@collection_data)
|
||||
return if one
|
||||
|
||||
@callbacks[@counter] =
|
||||
callback: callback
|
||||
one: one
|
||||
|
||||
unbind: (callback) ->
|
||||
for counter, attr of @callbacks
|
||||
if callback is attr.callback
|
||||
delete @callbacks[counter]
|
||||
|
||||
fetch: =>
|
||||
return if @fetchActive
|
||||
@fetchActive = true
|
||||
App.Ajax.request(
|
||||
id: "collection-#{@event}"
|
||||
type: 'GET'
|
||||
url: App.Config.get('api_path') + @restEndpoint
|
||||
processData: true
|
||||
success: (data) =>
|
||||
@fetchActive = false
|
||||
@set(data)
|
||||
@callback(data)
|
||||
error: =>
|
||||
@fetchActive = false
|
||||
)
|
||||
|
||||
trigger: =>
|
||||
@callback(@get())
|
||||
|
||||
callback: (data) =>
|
||||
for counter, attr of @callbacks
|
||||
attr.callback(data)
|
||||
if attr.one
|
||||
delete @callbacks[counter]
|
|
@ -1,81 +1,24 @@
|
|||
class _Singleton extends App._CollectionSingletonBase
|
||||
event: 'ticket_overview_index'
|
||||
restEndpoint: '/ticket_overviews'
|
||||
|
||||
class App.OverviewIndexCollection
|
||||
_instance = undefined # Must be declared here to force the closure on the class
|
||||
_instance = new _Singleton
|
||||
|
||||
@get: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.get()
|
||||
|
||||
@bind: (callback) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.bind(callback)
|
||||
@one: (callback, init = true) ->
|
||||
_instance.bind(callback, init, true)
|
||||
|
||||
@bind: (callback, init = true) ->
|
||||
_instance.bind(callback, init, false)
|
||||
|
||||
@unbind: (callback) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.unbind(callback)
|
||||
|
||||
@trigger: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.trigger()
|
||||
|
||||
@fetch: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.fetch()
|
||||
|
||||
# The actual Singleton class
|
||||
class _Singleton
|
||||
constructor: ->
|
||||
@callbacks = {}
|
||||
@counter = 0
|
||||
|
||||
# websocket updates
|
||||
App.Event.bind 'ticket_overview_index', (data) =>
|
||||
@overview_index = data
|
||||
@callback(data)
|
||||
|
||||
get: ->
|
||||
@overview_index
|
||||
|
||||
bind: (callback, init = true) ->
|
||||
@counter += 1
|
||||
|
||||
# start init call if needed
|
||||
if init
|
||||
if @overview_index is undefined
|
||||
@fetch()
|
||||
else
|
||||
@callback(@overview_index)
|
||||
|
||||
@callbacks[@counter] = callback
|
||||
|
||||
unbind: (callback) ->
|
||||
for counter, localCallback of @callbacks
|
||||
if callback is localCallback
|
||||
delete @callbacks[counter]
|
||||
|
||||
fetch: =>
|
||||
return if @fetchActive
|
||||
@fetchActive = true
|
||||
App.Ajax.request(
|
||||
id: 'ticket_overviews',
|
||||
type: 'GET',
|
||||
url: App.Config.get('api_path') + '/ticket_overviews',
|
||||
processData: true,
|
||||
success: (data) =>
|
||||
@fetchActive = false
|
||||
@overview_index = data
|
||||
@callback(data)
|
||||
error: =>
|
||||
@fetchActive = false
|
||||
)
|
||||
|
||||
trigger: =>
|
||||
@callback(@get())
|
||||
|
||||
callback: (data) =>
|
||||
for counter, callback of @callbacks
|
||||
callback(data)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
class _Singleton extends App._CollectionSingletonBase
|
||||
event: 'ticket_create_attributes'
|
||||
restEndpoint: '/ticket_create'
|
||||
|
||||
class App.TicketCreateCollection
|
||||
_instance = new _Singleton
|
||||
|
||||
@get: ->
|
||||
_instance.get()
|
||||
|
||||
@one: (callback, init = true) ->
|
||||
_instance.bind(callback, init, true)
|
||||
|
||||
@bind: (callback, init = true) ->
|
||||
_instance.bind(callback, init, false)
|
||||
|
||||
@unbind: (callback) ->
|
||||
_instance.unbind(callback)
|
||||
|
||||
@trigger: ->
|
||||
_instance.trigger()
|
||||
|
||||
@fetch: ->
|
||||
_instance.fetch()
|
|
@ -169,7 +169,7 @@ class TicketsController < ApplicationController
|
|||
def ticket_merge
|
||||
|
||||
# check master ticket
|
||||
ticket_master = Ticket.where( number: params[:master_ticket_number] ).first
|
||||
ticket_master = Ticket.find_by(number: params[:master_ticket_number])
|
||||
if !ticket_master
|
||||
render json: {
|
||||
result: 'faild',
|
||||
|
@ -182,7 +182,7 @@ class TicketsController < ApplicationController
|
|||
return if !ticket_permission(ticket_master)
|
||||
|
||||
# check slave ticket
|
||||
ticket_slave = Ticket.where( id: params[:slave_ticket_id] ).first
|
||||
ticket_slave = Ticket.find_by(id: params[:slave_ticket_id] )
|
||||
if !ticket_slave
|
||||
render json: {
|
||||
result: 'faild',
|
||||
|
@ -282,39 +282,31 @@ class TicketsController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
# GET /api/v1/ticket_create/1
|
||||
# GET /api/v1/ticket_split
|
||||
def ticket_split
|
||||
|
||||
# permission check
|
||||
ticket = Ticket.find(params[:ticket_id])
|
||||
return if !ticket_permission(ticket)
|
||||
assets = ticket.assets({})
|
||||
|
||||
# get related articles
|
||||
article = Ticket::Article.find(params[:article_id])
|
||||
assets = article.assets(assets)
|
||||
|
||||
render json: {
|
||||
assets: assets
|
||||
}
|
||||
end
|
||||
|
||||
# GET /api/v1/ticket_create
|
||||
def ticket_create
|
||||
|
||||
# get attributes to update
|
||||
attributes_to_change = Ticket::ScreenOptions.attributes_to_change(
|
||||
user: current_user,
|
||||
ticket_id: params[:ticket_id],
|
||||
article_id: params[:article_id]
|
||||
)
|
||||
|
||||
assets = attributes_to_change[:assets]
|
||||
# split data
|
||||
split = {}
|
||||
if params[:ticket_id] && params[:article_id]
|
||||
ticket = Ticket.find( params[:ticket_id] )
|
||||
split[:ticket_id] = ticket.id
|
||||
assets = ticket.assets(assets)
|
||||
|
||||
# get related articles
|
||||
article = Ticket::Article.find( params[:article_id] )
|
||||
split[:article_id] = article.id
|
||||
assets = article.assets(assets)
|
||||
end
|
||||
|
||||
# return result
|
||||
render json: {
|
||||
split: split,
|
||||
assets: assets,
|
||||
form_meta: {
|
||||
filter: attributes_to_change[:filter],
|
||||
dependencies: attributes_to_change[:dependencies],
|
||||
}
|
||||
}
|
||||
render json: attributes_to_change
|
||||
end
|
||||
|
||||
# GET /api/v1/tickets/search
|
||||
|
|
|
@ -99,9 +99,11 @@ returns
|
|||
|
||||
{
|
||||
assets: assets,
|
||||
form_meta: {
|
||||
filter: filter,
|
||||
dependencies: dependencies,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
=begin
|
||||
|
|
|
@ -9,6 +9,7 @@ Zammad::Application.routes.draw do
|
|||
match api_path + '/tickets', to: 'tickets#create', via: :post
|
||||
match api_path + '/tickets/:id', to: 'tickets#update', via: :put
|
||||
match api_path + '/ticket_create', to: 'tickets#ticket_create', via: :get
|
||||
match api_path + '/ticket_split', to: 'tickets#ticket_split', via: :get
|
||||
match api_path + '/ticket_full/:id', to: 'tickets#ticket_full', via: :get
|
||||
match api_path + '/ticket_history/:id', to: 'tickets#ticket_history', via: :get
|
||||
match api_path + '/ticket_customer', to: 'tickets#ticket_customer', via: :get
|
||||
|
|
|
@ -39,17 +39,9 @@ class Sessions::Backend::TicketCreate
|
|||
# set new timeout
|
||||
Sessions::CacheIn.set( client_key, true, { expires_in: @ttl.seconds } )
|
||||
|
||||
ticket_create_attributes = load
|
||||
data = load
|
||||
|
||||
return if !ticket_create_attributes
|
||||
|
||||
data = {
|
||||
assets: ticket_create_attributes[:assets],
|
||||
form_meta: {
|
||||
filter: ticket_create_attributes[:filter],
|
||||
dependencies: ticket_create_attributes[:dependencies],
|
||||
}
|
||||
}
|
||||
return if !data
|
||||
|
||||
if !@client
|
||||
return {
|
||||
|
|
|
@ -291,7 +291,7 @@ class TestCase < Test::Unit::TestCase
|
|||
|
||||
execute(
|
||||
browser: instance,
|
||||
js: "\$('#{params[:css]}').get(0).scrollIntoView(true)",
|
||||
js: "\$('#{params[:css]}').get(0).scrollIntoView(false)",
|
||||
mute_log: params[:mute_log]
|
||||
)
|
||||
sleep 0.4
|
||||
|
|
Loading…
Reference in a new issue