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]
6 before_filter :authenticate_reader, :only => [:index, :show, :comic]
7 before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
9 before_filter :authenticate_admin!, :only => [:list, :browse]
12 @page = Story.page params[:page]
13 @page_size = Story.page_size params[:page_size]
14 @stories = Story.list(@page, @page_size)
16 respond_to do |format|
17 format.html # index.html.erb
18 format.json { render :json => @stories.to_json(Story.list_json_opt) }
23 @story = Story.show(params[:id], @author)
25 respond_to do |format|
26 format.html # show.html.erb
27 format.json { render json: @story.story_as_json(@author) }
32 @comic = Comic.show(params[:id], @author)
33 cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
34 @offset = Story.offset cnt, params[:offset]
35 @panel_count = Story.panel_count cnt, params[:count]
36 @stories = Story.play_list(@comic, @author, @offset, @panel_count)
37 respond_to do |format|
38 format.html # index.html.erb
39 format.json {render text: Story.list_as_json_text(@stories, @author)}
41 render :json => "callback(" + @stories.to_json_list + ");"
49 respond_to do |format|
50 format.html { render layout: 'system' }# index.html.erb
51 format.json { render json: @stories }
56 @story = Story.find(params[:id])
58 respond_to do |format|
59 format.html { render layout: 'system' } # show.html.erb
60 format.json { render json: @story }
67 respond_to do |format|
68 format.html # new.html.erb
70 format.json { render json: @story.story_as_json(@author) }
75 @story = Story.edit(params[:id], @author)
76 respond_to do |format|
85 @story.attributes = params[:story]
86 @story.overwrite @author
87 @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
88 @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
90 respond_to do |format|
92 flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
93 format.html { redirect_to action: :comic, id: @story.comic_id }
94 format.json { render json: @story.story_as_json(@author) }
96 format.html { render action: "new" }
97 format.json { render json: @story.errors, status: :unprocessable_entity }
103 @story = Story.edit(params[:id], @author)
105 @story.attributes = params[:story]
106 @story.overwrite @author
107 respond_to do |format|
109 flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
110 format.html { redirect_to action: :comic, id: @story.comic_id }
111 format.json { head :ok }
113 format.html { render action: "edit" }
114 format.json { render json: @story.errors, status: :unprocessable_entity }
120 @story = Story.edit(params[:id], @author)
121 respond_to do |format|
122 if @story.destroy_and_shorten
123 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
124 format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
125 format.json { head :ok }
127 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
128 format.html { redirect_to story_path(@story) }
129 format.json { render json: @story.errors, status: :unprocessable_entity }