OSDN Git Service

t#31223:add them contents list for author and artist
[pettanr/pettanr.git] / app / controllers / home_controller.rb
index 8466eb3..6d4babc 100644 (file)
@@ -1,14 +1,11 @@
 class HomeController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
-  before_filter :authenticate_user!, :only => [
+  before_filter :authenticate_user, :only => [
     :index, :show, :profile, :configure, :create_token, :delete_token, 
-    :comic, :story, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
+    :comic, :story, :panel, :resource_picture, :panel_picture, :panel_color, :ground_picture, :ground_color
   ]
-  before_filter :authenticate_author, :only => [
-    :index, :show, :profile, :configure, :create_token, :delete_token, 
-    :comic, :story, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
-  ]
-  before_filter :authenticate_artist, :only => [:picture]
+  before_filter :authenticate_author, :only => [:comic, :story, :panel, :panel_picture, :panel_color, :ground_picture, :ground_color]
+  before_filter :authenticate_artist, :only => [:resource_picture]
   
   def index
   end
@@ -20,19 +17,26 @@ class HomeController < ApplicationController
   end
   
   def create_token
-    respond_to do |format|
-      if @user.create_token
-        format.html { redirect_to({:action => :configure}, {:notice => 'user token was successfully created.'}) }
-      else
-        format.html { render action: "auth_token" }
+    if @user.create_token
+      respond_to do |format|
+        flash[:notice] = I18n.t('flash.notice.created', :model => User.human_attribute_name(:authentication_token))
+        format.html { redirect_to({:action => :configure}) }
       end
+    else
+      flash[:notice] = I18n.t('flash.notice.not_created', :model => User.human_attribute_name(:authentication_token))
+      format.html { render action: "configure" }
     end
   end
   
   def delete_token
-    @user.delete_token
-    respond_to do |format|
-      format.html { redirect_to :action => :configure}
+    if @user.delete_token
+      respond_to do |format|
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => User.human_attribute_name(:authentication_token))
+        format.html { redirect_to :action => :configure}
+      end
+    else
+      flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => User.human_attribute_name(:authentication_token))
+      format.html { render action: "configure" }
     end
   end
   
@@ -82,7 +86,7 @@ class HomeController < ApplicationController
   
   def panel_color
     @page = Author.page params[:page]
-    @page_size = Author.panel_page_size params[:page_size]
+    @page_size = Author.panel_colorl_page_size params[:page_size]
     @panel_colors = PanelColor.mylist(@author, @page, @page_size)
 
     respond_to do |format|
@@ -93,7 +97,7 @@ class HomeController < ApplicationController
   
   def ground_picture
     @page = Author.page params[:page]
-    @page_size = Author.panel_page_size params[:page_size]
+    @page_size = Author.ground_picture_page_size params[:page_size]
     @ground_pictures = GroundPicture.mylist(@author, @page, @page_size)
 
     respond_to do |format|
@@ -104,7 +108,7 @@ class HomeController < ApplicationController
   
   def ground_color
     @page = Author.page params[:page]
-    @page_size = Author.panel_page_size params[:page_size]
+    @page_size = Author.ground_color_page_size params[:page_size]
     @ground_colors = GroundColor.mylist(@author, @page, @page_size)
 
     respond_to do |format|
@@ -113,4 +117,15 @@ class HomeController < ApplicationController
     end
   end
   
+  def resource_picture
+    @page = Author.page params[:page]
+    @page_size = Author.resource_picture_page_size params[:page_size]
+    @resource_pictures = ResourcePicture.mylist(@artist, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render json: @resource_pictures.to_json(ResourcePicture.list_json_opt) }
+    end
+  end
+  
 end