Merge branch 'develop' into interface

Conflicts:
	app/assets/javascripts/app/controllers/ticket_zoom.js.coffee
	app/assets/javascripts/app/controllers/widget/tag.js.coffee
This commit is contained in:
Martin Edenhofer 2014-09-23 13:24:13 +02:00
commit 9be9d56d74
5 changed files with 103 additions and 57 deletions

View file

@ -113,6 +113,12 @@ class App.TicketZoom extends App.Controller
# remember article ids # remember article ids
@ticket_article_ids = data.ticket_article_ids @ticket_article_ids = data.ticket_article_ids
# remember link
@links = data.links
# remember tags
@tags = data.tags
# get edit form attributes # get edit form attributes
@form_meta = data.form_meta @form_meta = data.form_meta
@ -155,12 +161,14 @@ class App.TicketZoom extends App.Controller
el: el.find('.tags') el: el.find('.tags')
object_type: 'Ticket' object_type: 'Ticket'
object: @ticket object: @ticket
tags: @tags
) )
el.append('<div class="links"></div>') el.append('<div class="links"></div>')
new App.WidgetLink( new App.WidgetLink(
el: el.find('.links') el: el.find('.links')
object_type: 'Ticket' object_type: 'Ticket'
object: @ticket object: @ticket
links: @links
) )
el.append('<div class="action"></div>') el.append('<div class="action"></div>')
showHistory = => showHistory = =>
@ -865,26 +873,14 @@ class Edit extends App.Controller
@autosaveStart() @autosaveStart()
return return
ticket.article = article
ticket.save( ticket.save(
done: (r) => done: (r) =>
# reset form after save # reset form after save
if article App.TaskManager.update( @task_key, { 'state': {} })
article.save(
done: (r) =>
@ui.fetch( ticket.id, true )
# reset form after save @ui.fetch( ticket.id, true )
App.TaskManager.update( @task_key, { 'state': {} })
fail: (r) =>
@log 'error', 'update article', r
)
else
# reset form after save
App.TaskManager.update( @task_key, { 'state': {} })
@ui.fetch( ticket.id, true )
) )
reset: (e) => reset: (e) =>

View file

@ -5,7 +5,12 @@ class App.WidgetLink extends App.Controller
constructor: -> constructor: ->
super super
@fetch()
# if links are given, do not init fetch
if @links
@render()
else
@fetch()
fetch: => fetch: =>
# fetch item on demand # fetch item on demand

View file

@ -12,10 +12,16 @@ class App.WidgetTag extends App.Controller
constructor: -> constructor: ->
super super
@cacheKey = "tags::#{@object_type}::#{@object.id}" @cacheKey = "tags::#{@object_type}::#{@object.id}"
if @tags
@render(@tags)
return
@tagList = App.Store.get( @cacheKey ) || [] @tagList = App.Store.get( @cacheKey ) || []
@render()
if !_.isEmpty(@tagList) if !_.isEmpty(@tagList)
@render()
@delay( @delay(
=> =>
@fetch() @fetch()

View file

@ -171,6 +171,7 @@ class App.Model extends Spine.Model
attribute[item] = value attribute[item] = value
attributesNew[ attribute.name ] = attribute attributesNew[ attribute.name ] = attribute
# if no screen is given or no attribute has this screen - use default attributes
if !screen || _.isEmpty( attributesNew ) if !screen || _.isEmpty( attributesNew )
for attribute in attributes for attribute in attributes
attributesNew[ attribute.name ] = attribute attributesNew[ attribute.name ] = attribute
@ -335,9 +336,13 @@ class App.Model extends Spine.Model
# fetch init collection # fetch init collection
if param.initFetch is true if param.initFetch is true
@one 'refresh', (collection) => if !@initFetchActive
callback(collection) @one 'refresh', (collection) =>
@fetch( {}, { clear: true } ) @initFetchActive = true
callback(collection)
@fetch( {}, { clear: true } )
else
callback( @all() )
# return key # return key
key key

View file

@ -22,7 +22,7 @@ class TicketsController < ApplicationController
# POST /api/v1/tickets # POST /api/v1/tickets
def create def create
@ticket = Ticket.new( Ticket.param_validation( params[:ticket] ) ) ticket = Ticket.new( Ticket.param_validation( params[:ticket] ) )
# check if article is given # check if article is given
if !params[:article] if !params[:article]
@ -31,8 +31,8 @@ class TicketsController < ApplicationController
end end
# create ticket # create ticket
if !@ticket.save if !ticket.save
render :json => @ticket.errors, :status => :unprocessable_entity render :json => ticket.errors, :status => :unprocessable_entity
return return
end end
@ -42,7 +42,7 @@ class TicketsController < ApplicationController
tags.each {|tag| tags.each {|tag|
Tag.tag_add( Tag.tag_add(
:object => 'Ticket', :object => 'Ticket',
:o_id => @ticket.id, :o_id => ticket.id,
:item => tag, :item => tag,
:created_by_id => current_user.id, :created_by_id => current_user.id,
) )
@ -51,57 +51,39 @@ class TicketsController < ApplicationController
# create article if given # create article if given
if params[:article] if params[:article]
form_id = params[:article][:form_id] article_create( ticket, params[:article] )
params[:article].delete(:form_id)
@article = Ticket::Article.new( Ticket::Article.param_validation( params[:article] ) )
@article.ticket_id = @ticket.id
# find attachments in upload cache
if form_id
@article.attachments = Store.list(
:object => 'UploadCache',
:o_id => form_id,
)
end
if !@article.save
render :json => @article.errors, :status => :unprocessable_entity
return
end
# remove attachments from upload cache
if form_id
Store.remove(
:object => 'UploadCache',
:o_id => form_id,
)
end
end end
render :json => @ticket, :status => :created render :json => ticket, :status => :created
end end
# PUT /api/v1/tickets/1 # PUT /api/v1/tickets/1
def update def update
@ticket = Ticket.find(params[:id]) ticket = Ticket.find(params[:id])
# permissin check # permissin check
return if !ticket_permission(@ticket) return if !ticket_permission(ticket)
if @ticket.update_attributes( Ticket.param_validation( params[:ticket] ) ) if ticket.update_attributes( Ticket.param_validation( params[:ticket] ) )
render :json => @ticket, :status => :ok
if params[:article]
article_create( ticket, params[:article] )
end
render :json => ticket, :status => :ok
else else
render :json => @ticket.errors, :status => :unprocessable_entity render :json => ticket.errors, :status => :unprocessable_entity
end end
end end
# DELETE /api/v1/tickets/1 # DELETE /api/v1/tickets/1
def destroy def destroy
@ticket = Ticket.find( params[:id] ) ticket = Ticket.find( params[:id] )
# permissin check # permissin check
return if !ticket_permission(@ticket) return if !ticket_permission(ticket)
@ticket.destroy ticket.destroy
head :ok head :ok
end end
@ -286,12 +268,34 @@ class TicketsController < ApplicationController
assets = article.assets(assets) assets = article.assets(assets)
} }
# get links
links = Link.list(
:link_object => 'Ticket',
:link_object_value => ticket.id,
)
link_list = []
links.each { |item|
link_list.push item
if item['link_object'] == 'Ticket'
ticket = Ticket.lookup( :id => item['link_object_value'] )
assets = ticket.assets(assets)
end
}
# get tags
tags = Tag.tag_list(
:object => 'Ticket',
:o_id => ticket.id,
)
# return result # return result
render :json => { render :json => {
:ticket_id => ticket.id, :ticket_id => ticket.id,
:ticket_article_ids => article_ids, :ticket_article_ids => article_ids,
:signature => signature, :signature => signature,
:assets => assets, :assets => assets,
:links => link_list,
:tags => tags,
:form_meta => attributes_to_change, :form_meta => attributes_to_change,
:edit_form => attributes_to_change, :edit_form => attributes_to_change,
} }
@ -361,4 +365,34 @@ class TicketsController < ApplicationController
} }
end end
private
def article_create(ticket, params)
puts params.inspect
# create article if given
form_id = params[:form_id]
params.delete(:form_id)
article = Ticket::Article.new( Ticket::Article.param_validation( params ) )
article.ticket_id = ticket.id
# find attachments in upload cache
if form_id
article.attachments = Store.list(
:object => 'UploadCache',
:o_id => form_id,
)
end
if !article.save
render :json => article.errors, :status => :unprocessable_entity
return
end
# remove attachments from upload cache
if form_id
Store.remove(
:object => 'UploadCache',
:o_id => form_id,
)
end
end
end end