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|
42 @new_panels = Panel.mylist(@author, 0, 5)
45 format.json {render text: Story.list_as_json_text(@stories, @author)}
47 render :json => "callback(" + @stories.to_json_list + ");"
55 respond_to do |format|
56 format.html { render layout: 'system' }# index.html.erb
57 format.json { render json: @stories }
62 @story = Story.find(params[:id])
64 respond_to do |format|
65 format.html { render layout: 'system' } # show.html.erb
66 format.json { render json: @story }
73 respond_to do |format|
74 format.html # new.html.erb
76 format.json { render json: @story.story_as_json(@author) }
81 @story = Story.edit(params[:id], @author)
82 respond_to do |format|
91 @story.attributes = params[:story]
92 @story.overwrite @author
93 @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
94 @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
96 respond_to do |format|
98 flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
99 format.html { redirect_to action: :comic, id: @story.comic_id }
100 format.json { render json: @story.story_as_json(@author) }
102 format.html { render action: "new" }
103 format.json { render json: @story.errors, status: :unprocessable_entity }
109 @story = Story.edit(params[:id], @author)
111 @story.attributes = params[:story]
112 @story.overwrite @author
113 respond_to do |format|
115 flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
116 format.html { redirect_to action: :comic, id: @story.comic_id }
117 format.json { head :ok }
119 format.html { render action: "edit" }
120 format.json { render json: @story.errors, status: :unprocessable_entity }
126 @story = Story.edit(params[:id], @author)
127 respond_to do |format|
128 if @story.destroy_and_shorten
129 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
130 format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
131 format.json { head :ok }
133 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
134 format.html { redirect_to story_path(@story) }
135 format.json { render json: @story.errors, status: :unprocessable_entity }