class AuthorsController < ApplicationController
- before_filter :authenticate_user!, :only => [:index, :show]
+ layout 'test' if MagicNumber['test_layout']
+ before_filter :authenticate_user!, :only => [:index, :show, :new, :create, :edit, :update]
+ before_filter :authenticate_author, :only => [:index, :show, :edit, :update]
before_filter :authenticate_admin!, :only => [:list, :browse]
def index
@page = Author.page params[:page]
@page_size = Author.page_size params[:page_size]
- @authors = Author.list({}, @page, @page_size)
+ @authors = Author.list(@page, @page_size)
respond_to do |format|
format.html # index.html.erb
end
def show
- @author = Author.show(params[:id])
+ @au = Author.show(params[:id], @author)
respond_to do |format|
format.html
- format.json { render :json => @author.to_json(Author.list_json_opt) }
+ format.json { render :json => @au.to_json(Author.show_json_opt) }
end
end
def count
- @author = {:count => Author.visible_count}
+ @au = {:count => Author.visible_count}
respond_to do |format|
- format.json { render json: @author.to_json }
+ format.json { render json: @au.to_json }
end
end
end
def browse
- @author = Author.find(params[:id])
+ @au = Author.find(params[:id])
respond_to do |format|
format.html { render layout: 'system' }
end
end
+ def new
+ @au = Author.new
+ @au.supply_default
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.js
+ format.json { render json: @au.to_json(Author.show_json_opt) }
+ end
+ end
+
+ def edit
+ @au = Author.edit(params[:id], @author)
+ end
+
+ def create
+ @au = Author.new()
+ @au.supply_default
+ @au.attributes = params[:author]
+ @au.overwrite @user.id
+ respond_to do |format|
+ if @au.save
+ format.html { redirect_to root_path, notice: 'Author was successfully created.' }
+ format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @au.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ def update
+ @au = Author.edit(params[:id], @author)
+ @au.attributes = params[:author]
+ @au.overwrite @user.id
+
+ respond_to do |format|
+ if @au.save
+ format.html { redirect_to '/home/configure', notice: 'Author was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @au.errors, status: :unprocessable_entity }
+ end
+ end
+ end
end