1 class StoriesController < ApplicationController
2 layout 'test' if Pettanr::TestLayout
4 before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy]
6 before_filter :authenticate_user!, :only => [:index, :show, :comic, :new, :create, :edit, :update, :destroy]
8 before_filter :authenticate_admin!, :only => [:list, :browse]
11 @story = Story.show(params[:id], @author)
13 respond_to do |format|
14 format.html # show.html.erb
15 format.json { render json: @story.story_as_json(@author) }
20 @comic = Comic.show(params[:id], @author)
21 cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
22 @offset = Story.offset cnt, params[:offset]
23 @panel_count = Story.panel_count cnt, params[:count]
24 @stories = Story.play_list(@comic, @author, @offset, @panel_count)
25 respond_to do |format|
26 format.html # index.html.erb
28 render :json => '[' + @stories.map {|i| i.story_as_json(@author)}.join(',') + ']'
31 render :json => "callback(" + @stories.to_json_list + ");"
39 respond_to do |format|
40 format.html { render layout: 'system' }# index.html.erb
41 format.json { render json: @stories }
46 @story = Story.find(params[:id])
48 respond_to do |format|
49 format.html { render layout: 'system' } # show.html.erb
50 format.json { render json: @story }
56 # GET /stories/new.json
60 respond_to do |format|
61 format.html # new.html.erb
63 format.json { render json: @story.story_as_json(@author) }
68 # GET /stories/1.js/edit
70 @story = Story.edit(params[:id], @author)
71 respond_to do |format|
82 @story.attributes = params[:story]
83 @story.overwrite @author
84 @comic = Comic.edit(@story.comic_id, @author)
85 @panel = Panel.show(@story.panel_id, @author)
87 respond_to do |format|
89 format.html { redirect_to action: :comic, id: @story.comic_id }
90 format.json { render json: @story.story_as_json(@author) }
92 format.html { render action: "new" }
93 format.json { render json: @story.errors, status: :unprocessable_entity }
101 @story = Story.edit(params[:id], @author)
103 @story.attributes = params[:story]
104 @story.overwrite @author
105 respond_to do |format|
107 format.html { redirect_to action: :comic, id: @story.comic_id }
108 format.json { head :ok }
110 format.html { render action: "edit" }
111 format.json { render json: @story.errors, status: :unprocessable_entity }
117 # DELETE /stories/1.js
118 # DELETE /stories/1.json
120 @story = Story.edit(params[:id], @author)
122 @story.destroy_and_shorten
124 respond_to do |format|
125 format.html { redirect_to story_path(@story.comic) }
126 format.json { head :ok }