OSDN Git Service

add lg_id in resource picture
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
index 5a5312b..3ef277e 100644 (file)
@@ -3,7 +3,9 @@ class ComicsController < ApplicationController
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_reader, :only => [:index, :show, :by_author, :count, :count_by_author]
+    before_filter :authenticate_reader, :only => [
+      :index, :show, :play, :by_story, :by_author, :count, :count_by_story, :count_by_author
+    ]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
@@ -15,13 +17,21 @@ class ComicsController < ApplicationController
   def index
     filer_list
   end
-
+  
+  def by_story
+    filer_list
+  end
+  
   def by_author
     filer_list
   end
-
+  
   def show_html_format format
     format.html {
+      play_list = Locmare::ListGroup.list 'comic_story', 'play'
+      @play_count = play_list.count(@operators, 
+        {:id => @item.id, :my_play => @item.own?(@operators)}
+      )
     }
   end
   
@@ -35,11 +45,34 @@ class ComicsController < ApplicationController
       format.rss 
     end
   end
-
+  
+  def play
+    @item = self.class.model.show(params[:id], @operators)
+    set_play
+    @items = @list.items(@operators, 
+      {:id => params[:id], :my_play => @item.own?(@operators)},
+      0, -1 # no limit
+    )
+    @count = @items.count
+    # no pager
+    respond_to do |format|
+      format.html {
+        if @item.own? @operators
+          @new_story_items = assist_items('story', 'private')
+        end
+      }
+      format.json { render json: @items.to_json }
+    end
+  end
+  
   def count
     list_count
   end
   
+  def count_by_story
+    list_count
+  end
+  
   def count_by_author
     list_count
   end
@@ -53,52 +86,34 @@ class ComicsController < ApplicationController
   end
   
   def create
-    @comic = Comic.new
-    @comic.supply_default 
-    @comic.attributes = params[:comic]
-    @comic.overwrite @operators
-
-    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
-        flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human)
-        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 = params[@my_model_class.item_name]
+    @item.overwrite @operators
+    render_create
   end
-
+  
   def update
-    @comic = Comic.edit(params[:id], @operators)
-    @comic.attributes = params[:comic]
-    @comic.overwrite @operators
-    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
-        flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human)
-        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 = params[@my_model_class.item_name]
+    @item.overwrite @operators
+    render_update
   end
-
+  
   def destroy
-    @comic = Comic.edit(params[:id], @operators)
+    @item = Comic.edit(params[:id], @operators)
     respond_to do |format|
-      if @comic.destroy_with_story
+      if @item.destroy_with_leafs
         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
         format.html { redirect_to '/home/comics' }
         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 }
+        format.html { redirect_to @item }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
       end
     end
   end