OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
index 75eade6..73851fc 100644 (file)
 class ComicsController < ApplicationController
-  layout 'test' if MagicNumber['test_layout']
-  if MagicNumber['run_mode'] == 0
-    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+  if Manifest.manifest.magic_numbers['run_mode'] == 0
+    before_action :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_action :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_reader, :only => [:top, :index, :show]
-    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
-  end
-  before_filter :authenticate_admin!, :only => [:list, :browse]
-
-  def top
-    respond_to do |format|
-      format.html 
-    end
+    before_action :authenticate_reader, :only => [
+      :index, :show, :play, :by_story, :by_author
+    ]
+    before_action :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_action :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
   
   def index
-    @page = Comic.page params[:page]
-    @page_size = Comic.page_size params[:page_size]
-    @comics = Comic.list(@page, @page_size)
-    respond_to do |format|
-      format.html # index.html.erb
-      format.json { render json: @comics.to_json(Comic.list_json_opt) }
-    end
+    filer_list
   end
-
-  def show
-    @comic = Comic.show(params[:id], @author)
-
-    respond_to do |format|
-      format.html # show.html.erb
-      format.json { render json: @comic.to_json(Comic.show_json_opt) }
-    end
+  
+  def by_story
+    filer_list param: params[:id]
   end
-
-  def count
-    @comic = {:count => Comic.visible_count}
-    respond_to do |format|
-      format.json { render json: @comic.to_json }
-    end
+  
+  def by_author
+    filer_list param: params[:id]
   end
   
-  def list
-    @comics = Comic.all
-
+  def show_html_format format
+    format.html {
+      @play_list = Locmare::ListGroup.list(
+        'comic_stories', 'by_comic', @operators, 
+        {:id => @item.id, :page_size => -1}  # set no limit options
+      )
+    }
+  end
+  
+  def show
+    set_show
     respond_to do |format|
-      format.html { render layout: 'system' }# index.html.erb
-      format.json { render json: @comics }
+      show_html_format format
+      show_prof_format format
+      show_json_format format
+      format.atom 
+      format.rss 
     end
   end
-
-  def browse
-    @comic = Comic.find(params[:id])
-
+  
+  def play
+    set_play
+    @finder.per(-1)    # no limit no pager
+    play_list
     respond_to do |format|
-      format.html { render layout: 'system' } # show.html.erb
-      format.json { render json: @comic }
+      format.html {
+        if @item.own? @operators
+          @new_story_items = assist_items('home', 'stories', finder: :find_private, param: @operators)
+        end
+      }
+      list_json_format @finder, format
     end
   end
   
   def new
-    @comic = Comic.new
-    @comic.supply_default
-    respond_to do |format|
-      format.html # new.html.erb
-      format.js
-      format.json { render json: @comic.to_json(Comic.show_json_opt) }
-    end
+    form_new
   end
-
+  
   def edit
-    @comic = Comic.edit(params[:id], @author)
-    respond_to do |format|
-      format.html 
-      format.js
-    end
+    form_edit
   end
-
+  
   def create
-    @comic = Comic.new
-    @comic.supply_default 
-    @comic.attributes = params[:comic]
-    @comic.overwrite @author
-
-    respond_to do |format|
-      if @comic.save
-        flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human)
-        format.html { redirect_to @comic }
-        format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic }
-      else
-        format.html { render action: "new" }
-        format.json { render json: @comic.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.new
+    @item.supply_default 
+    @my_model_class.fold_extend_settings params[@my_model_class.item_name]
+    @item.attributes = @item.permit_params params
+    @item.overwrite @operators
+    render_create
   end
-
+  
   def update
-    @comic = Comic.edit(params[:id], @author)
-    @comic.attributes = params[:comic]
-    @comic.overwrite @author
-    respond_to do |format|
-      if @comic.save
-        flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
-        format.html { redirect_to @comic }
-        format.json { head :ok }
-      else
-        format.html { render action: "edit" }
-        format.json { render json: @comic.errors, status: :unprocessable_entity }
-      end
-    end
+    set_edit
+    @my_model_class.fold_extend_settings params[@my_model_class.item_name]
+    @item.attributes = @item.permit_params params
+    @item.overwrite @operators
+    render_update
   end
-
+  
   def destroy
-    @comic = Comic.edit(params[:id], @author)
-    respond_to do |format|
-      if @comic.destroy_with_story
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
-        format.html { redirect_to '/home/comic' }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
-        format.html { redirect_to @comic }
-        format.json { render json: @comic.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/' + @item.path_name
   end
+  
 end