OSDN Git Service

client is version 0.5.41, fixed Finder.ApplicationButton
[pettanr/pettanr.git] / app / controllers / panels_controller.rb
index c0cd0cf..ebbb8ba 100644 (file)
@@ -1,13 +1,16 @@
 class PanelsController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
-  before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
-  before_filter :authenticate_author, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user!, :only => [:new, :edit, :create, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
+  else
+    before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
+    before_filter :authenticate_author, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
+  end
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
   public
   
-  # GET /panels
-  # GET /panels.json
   def index
     @page = Panel.page params[:page]
     @page_size = Panel.page_size params[:page_size]
@@ -19,8 +22,6 @@ class PanelsController < ApplicationController
     end
   end
 
-  # GET /panels/1
-  # GET /panels/1.json
   def show
     @panel = Panel.show(params[:id], @author)
 
@@ -62,7 +63,7 @@ class PanelsController < ApplicationController
     @panel.supply_default
 
     respond_to do |format|
-      format.html # new.html.erb
+      format.html { render layout: 'metro' }
       format.js
       format.json { render json: @panel.panel_elements_as_json }
     end
@@ -76,8 +77,6 @@ class PanelsController < ApplicationController
     end
   end
 
-  # POST /panels
-  # POST /panels.json
   def create
     @panel = Panel.new
     @panel.supply_default
@@ -88,7 +87,8 @@ class PanelsController < ApplicationController
     @prm = params[:panel] || jsn
     respond_to do |format|
       if @panel.store @prm, @author
-        format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
+        flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
+        format.html { redirect_to @panel }
         format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
       else
         format.html { render action: "new" }
@@ -97,8 +97,6 @@ class PanelsController < ApplicationController
     end
   end
 
-  # PUT /panels/1
-  # PUT /panels/1.json
   def update
     @panel = Panel.edit(params[:id], @author)
     jsn = nil
@@ -108,7 +106,8 @@ class PanelsController < ApplicationController
     @prm = params[:panel] || jsn
     respond_to do |format|
       if @panel.store @prm, @author
-        format.html { redirect_to @panel, notice: 'Panel was successfully updated.' }
+        flash[:notice] = I18n.t('flash.notice.updated', :model => Panel.model_name.human)
+        format.html { redirect_to @panel }
         format.json { head :ok }
       else
         format.html { render action: "edit" }
@@ -117,15 +116,19 @@ class PanelsController < ApplicationController
     end
   end
 
-  # DELETE /panels/1
-  # DELETE /panels/1.json
   def destroy
     @panel = Panel.edit(params[:id], @author)
     respond_to do |format|
       Panel.transaction do
-        @panel.destroy
-        format.html { redirect_to panels_url }
-        format.json { head :ok }
+        if @panel.destroy_with_elements
+          flash[:notice] = I18n.t('flash.notice.destroyed', :model => Panel.model_name.human)
+          format.html { redirect_to '/home/panel' }
+          format.json { head :ok }
+        else
+          flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Panel.model_name.human)
+          format.html { redirect_to @panel }
+          format.json { render json: @panel.errors, status: :unprocessable_entity }
+        end
       end
     end
   end