class StoriesController < ApplicationController
layout 'test' if MagicNumber['test_layout']
if MagicNumber['run_mode'] == 0
- before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy]
+ before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
else
- before_filter :authenticate_user!, :only => [:index, :show, :comic, :new, :create, :edit, :update, :destroy]
- before_filter :authenticate_author, :only => [:index, :show, :comic, :new, :create, :edit, :update, :destroy]
+ before_filter :authenticate_reader, :only => [:index, :show, :comic]
+ before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+ before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
end
before_filter :authenticate_admin!, :only => [:list, :browse]
end
def show
- @story = Story.show(params[:id], @author)
+ @story = Story.show(params[:id], [@user, @admin])
respond_to do |format|
format.html # show.html.erb
end
def comic
- @comic = Comic.show(params[:id], @author)
+ @comic = Comic.show(params[:id], [@user, @admin])
cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
@offset = Story.offset cnt, params[:offset]
@panel_count = Story.panel_count cnt, params[:count]
@stories = Story.play_list(@comic, @author, @offset, @panel_count)
respond_to do |format|
- format.html # index.html.erb
+ format.html {
+ if @author
+ @new_panels = Panel.mylist(@author, 0, 5)
+ end
+ }
format.json {render text: Story.list_as_json_text(@stories, @author)}
format.jsonp {
render :json => "callback(" + @stories.to_json_list + ");"
end
end
- # GET /stories/new
- # GET /stories/new.js
- # GET /stories/new.json
def new
@story = Story.new
@story.supply_default
end
end
- # GET /stories/1/edit
- # GET /stories/1.js/edit
def edit
@story = Story.edit(params[:id], @author)
respond_to do |format|
end
end
- # POST /stories
- # POST /stories.json
def create
@story = Story.new
@story.supply_default
respond_to do |format|
if @story.store
+ flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
format.html { redirect_to action: :comic, id: @story.comic_id }
format.json { render json: @story.story_as_json(@author) }
else
end
end
- # PUT /stories/1
- # PUT /stories/1.json
def update
@story = Story.edit(params[:id], @author)
ot = @story.t
@story.overwrite @author
respond_to do |format|
if @story.store ot
+ flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
format.html { redirect_to action: :comic, id: @story.comic_id }
format.json { head :ok }
else
end
end
- # DELETE /stories/1
- # DELETE /stories/1.js
- # DELETE /stories/1.json
def destroy
@story = Story.edit(params[:id], @author)
- Story.transaction do
- @story.destroy_and_shorten
- end
respond_to do |format|
- format.html { redirect_to story_path(@story.comic) }
- format.json { head :ok }
+ if @story.destroy_and_shorten
+ flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
+ format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
+ format.json { head :ok }
+ else
+ flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
+ format.html { redirect_to story_path(@story) }
+ format.json { render json: @story.errors, status: :unprocessable_entity }
+ end
end
end
end