2012-11-20 17:56:30 +00:00
|
|
|
class Desktop::CoAuthorsController < ApplicationController
|
|
|
|
def index
|
|
|
|
@co_authors = CoAuthor.where(name_id: current_user.id)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :layout => false}
|
|
|
|
format.json { render json: @co_authors }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@co_author = CoAuthor.find(params[:id])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to desktop_co_authors_url, :layout => false }
|
|
|
|
format.json { render json: @co_author }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@co_author = CoAuthor.new
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :layout => false}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@co_author = CoAuthor.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :layout => false}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@co_author = CoAuthor.new(params[:co_author])
|
|
|
|
@co_author.name_id= current_user.id
|
|
|
|
|
2012-11-22 02:49:54 +00:00
|
|
|
if @co_author.save
|
2012-11-27 03:15:15 +00:00
|
|
|
render json: {success:true, msg: t('create.sucess.co_author')}.to_json
|
2012-11-21 06:52:26 +00:00
|
|
|
else
|
2012-11-26 07:45:51 +00:00
|
|
|
error_msg = @co_author.errors.full_messages.join("<br />")
|
|
|
|
render json: {success: false, msg: error_msg}.to_json
|
2012-11-20 17:56:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@co_author = CoAuthor.find(params[:id])
|
|
|
|
|
2012-11-22 02:49:54 +00:00
|
|
|
if @co_author.update_attributes(params[:co_author])
|
2012-11-27 03:15:15 +00:00
|
|
|
render json: {success:true, msg: t('update.sucess.co_author')}.to_json
|
2012-11-22 02:49:54 +00:00
|
|
|
else
|
2012-11-26 07:45:51 +00:00
|
|
|
error_msg = @co_author.errors.full_messages.join("<br />")
|
|
|
|
render json: {success: false, msg: error_msg}.to_json
|
2012-11-20 17:56:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete
|
|
|
|
@co_author = CoAuthor.find(params[:id])
|
|
|
|
@co_author.destroy
|
|
|
|
|
2012-11-23 04:28:36 +00:00
|
|
|
#respond_to do |format|
|
|
|
|
# format.html { redirect_to desktop_co_authors_url, :layout => false }
|
|
|
|
# format.json { head :no_content }
|
|
|
|
#end
|
2012-11-20 17:56:30 +00:00
|
|
|
end
|
2012-11-23 02:44:48 +00:00
|
|
|
|
|
|
|
def get_co_authors_json
|
|
|
|
@co_authors = CoAuthor.where(name_id: current_user.id)
|
|
|
|
data = Array.new
|
|
|
|
|
|
|
|
@co_authors.each do |co_author|
|
|
|
|
data << {
|
|
|
|
author: co_author.co_author,
|
|
|
|
email: co_author.email,
|
|
|
|
type: co_author.type
|
|
|
|
}
|
|
|
|
end
|
|
|
|
render json: JSON.pretty_generate(data)
|
|
|
|
end
|
2012-11-20 17:56:30 +00:00
|
|
|
end
|