OSDN Git Service

t#30200:update i18n devise
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
index ae1459d..df4e9fd 100644 (file)
@@ -1,26 +1,15 @@
 class ComicsController < ApplicationController
-  layout 'test' if Pettanr::TestLayout
-  if Const.run_mode == 0
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['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 => [:top, :index, :show, :play, :new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_user!, :only => [:top, :index, :show, :new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:top, :index, :show, :new, :create, :edit, :update, :destroy]
   end
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
-  private
-  
-  def treat_param comic
-    comic.author_id = @author.id
-  end
-  
-  public
-  
   def top
-    @new_comics = Comic.find(:all, 
-      :include => :author, :conditions => ['visible > 0'], :order => 'updated_at desc', :limit => 5
-    )
-    @new_pictures = OriginalPicture.list @artist.id
-
     respond_to do |format|
       format.html # index.html.erb
     end
@@ -31,7 +20,7 @@ class ComicsController < ApplicationController
   def index
     @page = Comic.page params[:page]
     @page_size = Comic.page_size params[:page_size]
-    @comics = Comic.list({}, @page, @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) }
@@ -45,7 +34,7 @@ class ComicsController < ApplicationController
 
     respond_to do |format|
       format.html # show.html.erb
-      format.json { render json: @comic.to_json(Comic.show_json_include_opt) }
+      format.json { render json: @comic.to_json(Comic.show_json_opt) }
     end
   end
 
@@ -82,14 +71,14 @@ class ComicsController < ApplicationController
     respond_to do |format|
       format.html # new.html.erb
       format.js
+      format.json { render json: @comic.to_json(Comic.show_json_opt) }
     end
   end
 
   # GET /comics/1/edit
   # GET /comics/1.js/edit
   def edit
-    @comic = Comic.show(params[:id], @author)
-    @comic.supply_default
+    @comic = Comic.edit(params[:id], @author)
     respond_to do |format|
       format.html 
       format.js
@@ -99,14 +88,15 @@ class ComicsController < ApplicationController
   # POST /comics
   # POST /comics.json
   def create
-    params[:comic].merge! author_id: @author.id
-    @comic = Comic.new params[:comic]
+    @comic = Comic.new
     @comic.supply_default 
+    @comic.attributes = params[:comic]
+    @comic.overwrite @author
 
     respond_to do |format|
       if @comic.save
         format.html { redirect_to @comic, notice: 'Comic was successfully created.' }
-        format.json { render json: Comic.show(@comic.id, @author).to_json(Comic.show_json_include_opt), status: :created, location: @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 }
@@ -117,10 +107,11 @@ class ComicsController < ApplicationController
   # PUT /comics/1
   # PUT /comics/1.json
   def update
-    params[:comic].merge! author_id: @author.id
-    @comic = Comic.show(params[:id], @author)
+    @comic = Comic.edit(params[:id], @author)
+    @comic.attributes = params[:comic]
+    @comic.overwrite @author
     respond_to do |format|
-      if @comic.update_attributes(params[:comic])
+      if @comic.save
         format.html { redirect_to @comic, notice: 'Comic was successfully updated.' }
         format.json { head :ok }
       else
@@ -133,16 +124,11 @@ class ComicsController < ApplicationController
   # DELETE /comics/1
   # DELETE /comics/1.json
   def destroy
-    @comic = Comic.find(params[:id])
-    if @comic.own? @author
-      @comic.destroy
-      respond_to do |format|
-        format.html { redirect_to comics_url }
-        format.json { head :ok }
-      end
-    else
-      format.html { render action: "edit" }
-      format.json { render json: @comic.errors, status: :unprocessable_entity }
+    @comic = Comic.edit(params[:id], @author)
+    @comic.destroy
+    respond_to do |format|
+      format.html { redirect_to comics_url }
+      format.json { head :ok }
     end
   end
 end