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_user!, :only => [:index, :show, :comic, :new, :create, :edit, :update, :destroy]
8 before_filter :authenticate_author, :only => [:index, :show, :comic, :new, :create, :edit, :update, :destroy]
10 before_filter :authenticate_admin!, :only => [:list, :browse]
13 @page = Story.page params[:page]
14 @page_size = Story.page_size params[:page_size]
15 @stories = Story.list(@page, @page_size)
17 respond_to do |format|
18 format.html # index.html.erb
19 format.json { render :json => @stories.to_json(Story.list_json_opt) }
24 @story = Story.show(params[:id], @author)
26 respond_to do |format|
27 format.html # show.html.erb
28 format.json { render json: @story.story_as_json(@author) }
33 @comic = Comic.show(params[:id], @author)
34 cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
35 @offset = Story.offset cnt, params[:offset]
36 @panel_count = Story.panel_count cnt, params[:count]
37 @stories = Story.play_list(@comic, @author, @offset, @panel_count)
38 respond_to do |format|
39 format.html # index.html.erb
40 format.json {render text: Story.list_as_json_text(@stories, @author)}
42 render :json => "callback(" + @stories.to_json_list + ");"
50 respond_to do |format|
51 format.html { render layout: 'system' }# index.html.erb
52 format.json { render json: @stories }
57 @story = Story.find(params[:id])
59 respond_to do |format|
60 format.html { render layout: 'system' } # show.html.erb
61 format.json { render json: @story }
68 respond_to do |format|
69 format.html # new.html.erb
71 format.json { render json: @story.story_as_json(@author) }
76 @story = Story.edit(params[:id], @author)
77 respond_to do |format|
86 @story.attributes = params[:story]
87 @story.overwrite @author
88 @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
89 @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
91 respond_to do |format|
93 flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
94 format.html { redirect_to action: :comic, id: @story.comic_id }
95 format.json { render json: @story.story_as_json(@author) }
97 format.html { render action: "new" }
98 format.json { render json: @story.errors, status: :unprocessable_entity }
104 @story = Story.edit(params[:id], @author)
106 @story.attributes = params[:story]
107 @story.overwrite @author
108 respond_to do |format|
110 flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
111 format.html { redirect_to action: :comic, id: @story.comic_id }
112 format.json { head :ok }
114 format.html { render action: "edit" }
115 format.json { render json: @story.errors, status: :unprocessable_entity }
121 @story = Story.edit(params[:id], @author)
122 respond_to do |format|
123 if @story.destroy_and_shorten
124 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
125 format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
126 format.json { head :ok }
128 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
129 format.html { redirect_to story_path(@story) }
130 format.json { render json: @story.errors, status: :unprocessable_entity }