class StoriesController < ApplicationController
- layout 'test' if Pettanr::TestLayout
- if Const.run_mode == 0
+ layout 'test' if MagicNumber['test_layout']
+ if MagicNumber['run_mode'] == 0
before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy]
else
- before_filter :authenticate_user!, :only => [:index, :show, :new, :create, :edit, :update, :destroy]
+ before_filter :authenticate_user!, :only => [:index, :show, :comic, :new, :create, :edit, :update, :destroy]
end
before_filter :authenticate_admin!, :only => [:list, :browse]
+ def index
+ @page = Story.page params[:page]
+ @page_size = Story.page_size params[:page_size]
+ @stories = Story.list(@page, @page_size)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render :json => @stories.to_json(Story.list_json_opt) }
+ end
+ end
+
def show
+ @story = Story.show(params[:id], @author)
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @story.story_as_json(@author) }
+ end
+ end
+
+ def comic
@comic = Comic.show(params[:id], @author)
cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
@offset = Story.offset cnt, params[:offset]
@panel_count = Story.panel_count cnt, params[:count]
- @stories = Story.list(@comic, @author, @offset, @panel_count)
+ @stories = Story.play_list(@comic, @author, @offset, @panel_count)
respond_to do |format|
format.html # index.html.erb
- format.json {
- render :json => @stories.to_json_list
- }
+ format.json {render text: Story.list_as_json_text(@stories, @author)}
format.jsonp {
render :json => "callback(" + @stories.to_json_list + ");"
}
respond_to do |format|
format.html # new.html.erb
format.js
- format.json { render json: @story }
+ format.json { render json: @story.story_as_json(@author) }
end
end
# GET /stories/1/edit
# GET /stories/1.js/edit
def edit
- @story = Story.show(params[:id], @author)
+ @story = Story.edit(params[:id], @author)
respond_to do |format|
format.html
format.js
@story.supply_default
@story.attributes = params[:story]
@story.overwrite @author
+ @comic = Comic.edit(@story.comic_id, @author)
+ @panel = Panel.show(@story.panel_id, @author)
respond_to do |format|
if @story.store
- format.html { redirect_to action: :show, id: @story.comic_id }
- format.json { render json: @story.to_json() }
+ format.html { redirect_to action: :comic, id: @story.comic_id }
+ format.json { render json: @story.story_as_json(@author) }
else
format.html { render action: "new" }
format.json { render json: @story.errors, status: :unprocessable_entity }
@story.overwrite @author
respond_to do |format|
if @story.store ot
- format.html { redirect_to action: :show, id: @story.comic_id }
+ format.html { redirect_to action: :comic, id: @story.comic_id }
format.json { head :ok }
else
format.html { render action: "edit" }