OSDN Git Service

fix prof
[pettanr/pettanr.git] / app / controllers / panel_pictures_controller.rb
index 7c91306..728215c 100644 (file)
 class PanelPicturesController < ApplicationController
-  layout 'test' if MagicNumber['test_layout']
-  if MagicNumber['run_mode'] == 0
+  if Manifest.manifest.magic_numbers['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_reader, :only => [:index, :show]
+    before_filter :authenticate_reader, :only => [
+      :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author
+    ]
     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
   end
-  before_filter :authenticate_admin!, :only => [:list, :browse]
 
+  def self.model
+    PanelPicture
+  end
+  
   def index
-    @page = PanelPicture.page params[:page]
-    @page_size = PanelPicture.page_size params[:page_size]
-    @panel_pictures = PanelPicture.list(@page, @page_size)
-
-    respond_to do |format|
-      format.html # index.html.erb
-      format.json { render :json => @panel_pictures.to_json(PanelPicture.list_json_opt) }
-    end
+    filer_list
   end
-
+  
+  def by_panel
+    filer_list
+  end
+  
+  def by_author
+    filer_list
+  end
+  
+  def show_html_format format
+    format.html {
+      @panel_picture = @item
+    }
+  end
+  
   def show
-    @panel_picture = PanelPicture.show(params[:id], [@user, @admin])
-
+    set_show
     respond_to do |format|
-      format.html
-      format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
+      show_html_format format
+      show_prof_format format
+      show_json_format format
     end
   end
 
-  def list
-    @panel_pictures = PanelPicture.all
-
-    respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @panel_pictures }
-    end
+  def count
+    list_count
   end
-
-  def browse
-    @panel_picture = PanelPicture.find(params[:id])
-
-    respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @panel_picture}
-    end
+  
+  def count_by_panel
+    list_count
   end
-
+  
+  def count_by_author
+    list_count
+  end
+  
   def new
-    @panel_picture = PanelPicture.new params[:panel_picture]
-    @panel_picture.supply_default
-    @panel = @panel_picture.panel
-
+    raise Pettanr::NotWork unless @operators.author.working_panel
+    @picture = Picture.show params[:picture_id], @operators
+    raise ActiveRecord::Forbidden unless @picture.enable?
+    @panel = Panel.edit(@operators.author.working_panel, @operators)
+    
+    @item = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
+    @item.supply_default
     respond_to do |format|
-      format.html
+      format.html {
+        mounted = 1
+        form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
+        @form = form_manager.open @item, @operators, mounted
+      }
       format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
     end
   end
 
   def edit
-    @panel_picture = PanelPicture.show(params[:id], @author)
-    @panel = Panel.edit(@panel_picture.panel.id, @author)
+    @item = PanelPicture.show(params[:id], @operators)
+    @panel = Panel.edit(@item.panel.id, @operators)
     
     respond_to do |format|
-      format.html
+      format.html {
+        mounted = 1
+        form_manager = Pettanr::Application::manifest.form_managers[@item.form_name]
+        @form = form_manager.open @item, @operators, mounted
+      }
     end
   end
 
   def create
-    @panel_picture = PanelPicture.new params[:panel_picture]
-    @panel_picture.supply_default
-    @panel_picture.overwrite 
-    @panel = Panel.edit(@panel_picture.panel.id, @author)
+    raise Pettanr::NotWork unless @operators.author.working_panel
+    @panel = Panel.edit(@operators.author.working_panel, @operators)
+    
+    @panel_picture = PanelPicture.new 
+    @panel_picture.attributes = params[:panel_picture]
+    @panel_picture.overwrite @panel.id
+    
+    @picture = Picture.show @panel_picture.picture_id, @operators
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
       if @panel_picture.valid?
-        if @panel_picture.store @author
+        if @panel_picture.store @operators
           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: "panels/new" }
+          flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
+          format.html { render action: "new" }
           format.json { render json: @panel.errors, status: :unprocessable_entity }
         end
       else
+        flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
         format.html { render action: "new" }
         format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
       end
@@ -92,17 +115,21 @@ class PanelPicturesController < ApplicationController
   end
 
   def update
-    @panel_picture = PanelPicture.show(params[:id], @author)
+    @panel_picture = PanelPicture.show(params[:id], @operators)
     @panel_picture.attributes = params[:panel_picture]
-    @panel_picture.overwrite 
-    @panel = Panel.edit(@panel_picture.panel.id, @author)
+    @panel = Panel.edit(@panel_picture.panel.id, @operators)
+    @panel_picture.overwrite @panel.id
+    
+    @picture = Picture.show @panel_picture.picture_id, @operators
+    raise ActiveRecord::Forbidden unless @picture.enable?
     
     respond_to do |format|
-      if @panel_picture.store @author
+      if @panel_picture.store @operators
         flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
         format.html { redirect_to @panel_picture }
         format.json { head :ok }
       else
+        flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
         format.html { render action: "edit" }
         format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
       end
@@ -110,11 +137,11 @@ class PanelPicturesController < ApplicationController
   end
 
   def destroy
-    @panel_picture = PanelPicture.show(params[:id], @author)
-    @panel = Panel.edit(@panel_picture.panel.id, @author)
+    @panel_picture = PanelPicture.show(params[:id], @operators)
+    @panel = Panel.edit(@panel_picture.panel.id, @operators)
     
     respond_to do |format|
-      if @panel_picture.remove @author
+      if @panel_picture.remove @operators
         flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
         format.html { redirect_to @panel }
         format.json { head :ok }