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 @paginate = Story.play_list_paginate(@comic, @offset, @panel_count)
45 @new_panels = Panel.mylist(@author, 0, 5)
48 format.json {render text: Story.list_as_json_text(@stories, @author)}
50 render :json => "callback(" + @stories.to_json_list + ");"
58 respond_to do |format|
59 format.html { render layout: 'system' }# index.html.erb
60 format.json { render json: @stories }
65 @story = Story.find(params[:id])
67 respond_to do |format|
68 format.html { render layout: 'system' } # show.html.erb
69 format.json { render json: @story }
76 respond_to do |format|
77 format.html # new.html.erb
79 format.json { render json: @story.story_as_json(@author) }
84 @story = Story.edit(params[:id], @author)
85 respond_to do |format|
94 @story.attributes = params[:story]
95 @story.overwrite @author
96 @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
97 @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
99 respond_to do |format|
101 flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
102 format.html { redirect_to action: :comic, id: @story.comic_id }
103 format.json { render json: @story.story_as_json(@author) }
105 flash[:notice] = I18n.t('flash.notice.not_created', :model => Story.model_name.human)
106 format.html { render action: "new" }
107 format.json { render json: @story.errors, status: :unprocessable_entity }
113 @story = Story.edit(params[:id], @author)
115 @story.attributes = params[:story]
116 @story.overwrite @author
117 respond_to do |format|
119 flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
120 format.html { redirect_to action: :comic, id: @story.comic_id }
121 format.json { head :ok }
123 flash[:notice] = I18n.t('flash.notice.not_updated', :model => Story.model_name.human)
124 format.html { render action: "edit" }
125 format.json { render json: @story.errors, status: :unprocessable_entity }
131 @story = Story.edit(params[:id], @author)
132 respond_to do |format|
133 if @story.destroy_and_shorten
134 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
135 format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
136 format.json { head :ok }
138 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
139 format.html { redirect_to story_path(@story) }
140 format.json { render json: @story.errors, status: :unprocessable_entity }