2012-04-10 14:06:46 +00:00
|
|
|
class TicketArticlesController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
|
|
|
# GET /articles
|
|
|
|
def index
|
|
|
|
@articles = Ticket::Article.all
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @articles
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /articles/1
|
|
|
|
def show
|
|
|
|
@article = Ticket::Article.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @article
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /articles
|
|
|
|
def create
|
|
|
|
@article = Ticket::Article.new(params[:ticket_article])
|
|
|
|
@article.created_by_id = current_user.id
|
|
|
|
|
|
|
|
# find attachments in upload cache
|
|
|
|
@article['attachments'] = Store.list(
|
|
|
|
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
|
|
|
|
:o_id => @article.ticket_id
|
|
|
|
)
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
if @article.save
|
|
|
|
|
|
|
|
# remove attachments from upload cache
|
|
|
|
Store.remove(
|
|
|
|
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
|
|
|
|
:o_id => @article.ticket_id
|
|
|
|
)
|
2012-04-16 12:56:04 +00:00
|
|
|
|
|
|
|
render :json => @article, :status => :created
|
2012-04-12 11:27:01 +00:00
|
|
|
else
|
|
|
|
render :json => @article.errors, :status => :unprocessable_entity
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /articles/1
|
|
|
|
def update
|
|
|
|
@article = Ticket::Article.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
if @article.update_attributes(params[:ticket_article])
|
|
|
|
render :json => @article, :status => :ok
|
|
|
|
else
|
|
|
|
render :json => @article.errors, :status => :unprocessable_entity
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /articles/1
|
|
|
|
def destroy
|
|
|
|
@article = Ticket::Article.find(params[:id])
|
|
|
|
@article.destroy
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
head :ok
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|