1 class StoriesController < ApplicationController
2 layout 'test' if MagicNumber['test_layout']
3 if MagicNumber['run_mode'] == 0
4 before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
5 before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
7 before_filter :authenticate_reader, :only => [:index, :show, :comic]
8 before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
9 before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
11 before_filter :authenticate_admin!, :only => [:list, :browse]
14 @page = Story.page params[:page]
15 @page_size = Story.page_size params[:page_size]
16 @stories = Story.list(@page, @page_size)
18 respond_to do |format|
19 format.html # index.html.erb
20 format.json { render :json => @stories.to_json(Story.list_json_opt) }
25 @story = Story.show(params[:id], [@user, @admin])
27 respond_to do |format|
28 format.html # show.html.erb
29 format.json { render json: @story.story_as_json(@author) }
34 @comic = Comic.show(params[:id], [@user, @admin])
35 cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
36 @offset = Story.offset cnt, params[:offset]
37 @panel_count = Story.panel_count cnt, params[:count]
38 @stories = Story.play_list(@comic, @author, @offset, @panel_count)
39 respond_to do |format|
40 format.html # index.html.erb
41 format.json {render text: Story.list_as_json_text(@stories, @author)}
43 render :json => "callback(" + @stories.to_json_list + ");"
51 respond_to do |format|
52 format.html { render layout: 'system' }# index.html.erb
53 format.json { render json: @stories }
58 @story = Story.find(params[:id])
60 respond_to do |format|
61 format.html { render layout: 'system' } # show.html.erb
62 format.json { render json: @story }
69 respond_to do |format|
70 format.html # new.html.erb
72 format.json { render json: @story.story_as_json(@author) }
77 @story = Story.edit(params[:id], @author)
78 respond_to do |format|
87 @story.attributes = params[:story]
88 @story.overwrite @author
89 @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
90 @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
92 respond_to do |format|
94 flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
95 format.html { redirect_to action: :comic, id: @story.comic_id }
96 format.json { render json: @story.story_as_json(@author) }
98 format.html { render action: "new" }
99 format.json { render json: @story.errors, status: :unprocessable_entity }
105 @story = Story.edit(params[:id], @author)
107 @story.attributes = params[:story]
108 @story.overwrite @author
109 respond_to do |format|
111 flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
112 format.html { redirect_to action: :comic, id: @story.comic_id }
113 format.json { head :ok }
115 format.html { render action: "edit" }
116 format.json { render json: @story.errors, status: :unprocessable_entity }
122 @story = Story.edit(params[:id], @author)
123 respond_to do |format|
124 if @story.destroy_and_shorten
125 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
126 format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
127 format.json { head :ok }
129 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
130 format.html { redirect_to story_path(@story) }
131 format.json { render json: @story.errors, status: :unprocessable_entity }