class StoriesController < ApplicationController
- layout 'test' if Pettanr::TestLayout
- if Const.run_mode == 0
- before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy]
+ if Manifest.manifest.magic_numbers['run_mode'] == 0
+ 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_reader, :only => [
+ :index, :show, :play, :by_comic, :by_sheet, :by_author, :count, :count_by_comic, :count_by_sheet, :count_by_author
+ ]
+ 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]
+ def self.model
+ Story
+ end
+
+ def index
+ filer_list
+ end
+
+ def by_comic
+ filer_list
+ end
+
+ def by_sheet
+ filer_list
+ end
+
+ def by_author
+ filer_list
+ end
+
+ def show_html_format format
+ format.html {
+ play_list = Locmare::ListGroup.list 'story_sheet', 'play'
+ @play_count = play_list.count(@operators,
+ {:id => @item.id, :my_play => @item.own?(@operators)}
+ )
+ }
+ end
+
def show
- @story = Story.show(params[:id], @author)
-
+ set_show
respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @story.story_as_json(@author) }
+ show_html_format format
+ show_prof_format format
+ show_json_format format
end
end
- def comic
- @comic = Comic.show(params[:id], @author)
- 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)
+ def play
+ params[:offset] = nil
+ params[:count] = nil
+ params[:page] ||= 1
+ params[:page_size] = 1
+ @item = self.class.model.show(params[:id], @operators)
+ set_play
+ play_list
+ @sort_items = @list.items(@operators,
+ {:id => params[:id], :my_play => @item.own?(@operators)},
+ 0, -1 # no limit
+ )
respond_to do |format|
- format.html # index.html.erb
- format.json {render text: Story.list_as_json_text(@stories, @author)}
- format.jsonp {
- render :json => "callback(" + @stories.to_json_list + ");"
+ format.html {
+ if @item.own? @operators
+ @new_sheet_items = assist_items('sheet', 'private')
+ end
}
+ format.json { render json: @items.to_json }
end
end
- def list
- @stories = Story.all
-
- respond_to do |format|
- format.html { render layout: 'system' }# index.html.erb
- format.json { render json: @stories }
- end
+ def count
+ list_count
end
-
- def browse
- @story = Story.find(params[:id])
-
- respond_to do |format|
- format.html { render layout: 'system' } # show.html.erb
- format.json { render json: @story }
- end
+
+ def count_by_comic
+ list_count
+ end
+
+ def count_by_sheet
+ list_count
+ end
+
+ def count_by_author
+ list_count
end
- # GET /stories/new
- # GET /stories/new.js
- # GET /stories/new.json
def new
- @story = Story.new
- @story.supply_default
- respond_to do |format|
- format.html # new.html.erb
- format.js
- format.json { render json: @story.story_as_json(@author) }
- end
+ form_new
end
-
- # GET /stories/1/edit
- # GET /stories/1.js/edit
+
def edit
- @story = Story.edit(params[:id], @author)
- respond_to do |format|
- format.html
- format.js
- end
+ form_edit
end
-
- # POST /stories
- # POST /stories.json
+
def create
- @story = Story.new
- @story.supply_default
- @story.attributes = params[:story]
- @story.overwrite @author
- @comic = Comic.edit(@story.comic_id, @author)
- @panel = Panel.show(@story.panel_id, @author)
-
- respond_to do |format|
- if @story.store
- format.html { redirect_to action: :comic, id: @story.comic_id }
- format.json { render json: @story.story_as_json(@author) }
- else
- format.html { render action: "new" }
- format.json { render json: @story.errors, status: :unprocessable_entity }
- end
- end
+ set_model
+ @story = @item
+ @item = @my_model_class.new
+ @item.supply_default
+ @item.attributes = params[@my_model_class.item_name]
+ @item.overwrite @operators
+ render_create
end
- # PUT /stories/1
- # PUT /stories/1.json
def update
- @story = Story.edit(params[:id], @author)
- ot = @story.t
- @story.attributes = params[:story]
- @story.overwrite @author
+ set_edit
+ @story = @item
+ @item.attributes = params[@my_model_class.item_name]
+ @item.overwrite @operators
+ render_update
+ end
+
+ def destroy
+ @item = Story.edit(params[:id], @operators)
respond_to do |format|
- if @story.store ot
- format.html { redirect_to action: :comic, id: @story.comic_id }
+ if @item.destroy_with_leafs
+ flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
+ format.html { redirect_to '/home/stories' }
format.json { head :ok }
else
- format.html { render action: "edit" }
- format.json { render json: @story.errors, status: :unprocessable_entity }
+ flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
+ format.html { redirect_to @item }
+ format.json { render json: @item.errors, status: :unprocessable_entity }
end
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 }
- end
- end
+
end