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|
20 @paginate = Story.list_paginate(@page, @page_size)
22 format.json { render :json => @stories.to_json(Story.list_json_opt) }
27 @story = Story.show(params[:id], [@user, @admin])
29 respond_to do |format|
30 format.html # show.html.erb
31 format.json { render json: @story.story_as_json(@author) }
36 @comic = Comic.show(params[:id], [@user, @admin])
37 cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
38 @offset = Story.offset cnt, params[:offset]
39 @panel_count = Story.panel_count cnt, params[:count]
40 @stories = Story.play_list(@comic, @author, @offset, @panel_count)
41 respond_to do |format|
43 @prev_offset = if @offset > 0
44 if @offset - @panel_count < 0
47 @offset - @panel_count
52 @next_offset = if @offset + @panel_count > cnt
55 @offset + @panel_count
58 @new_panels = Panel.mylist(@author, 1, 5)
61 format.json {render text: Story.list_as_json_text(@stories, @author)}
63 render :json => "callback(" + @stories.to_json_list + ");"
71 respond_to do |format|
72 format.html { render layout: 'system' }# index.html.erb
73 format.json { render json: @stories }
78 @story = Story.find(params[:id])
80 respond_to do |format|
81 format.html { render layout: 'system' } # show.html.erb
82 format.json { render json: @story }
89 respond_to do |format|
90 format.html # new.html.erb
92 format.json { render json: @story.story_as_json(@author) }
97 @story = Story.edit(params[:id], @author)
98 respond_to do |format|
106 @story.supply_default
107 @story.attributes = params[:story]
108 @story.overwrite @author
109 @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
110 @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
112 respond_to do |format|
114 flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
115 format.html { redirect_to action: :comic, id: @story.comic_id }
116 format.json { render json: @story.story_as_json(@author) }
118 flash[:notice] = I18n.t('flash.notice.not_created', :model => Story.model_name.human)
119 format.html { render action: "new" }
120 format.json { render json: @story.errors, status: :unprocessable_entity }
126 @story = Story.edit(params[:id], @author)
128 @story.attributes = params[:story]
129 @story.overwrite @author
130 respond_to do |format|
132 flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
133 format.html { redirect_to action: :comic, id: @story.comic_id }
134 format.json { head :ok }
136 flash[:notice] = I18n.t('flash.notice.not_updated', :model => Story.model_name.human)
137 format.html { render action: "edit" }
138 format.json { render json: @story.errors, status: :unprocessable_entity }
144 @story = Story.edit(params[:id], @author)
145 respond_to do |format|
146 if @story.destroy_and_shorten
147 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
148 format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
149 format.json { head :ok }
151 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
152 format.html { redirect_to story_path(@story) }
153 format.json { render json: @story.errors, status: :unprocessable_entity }