OSDN Git Service

temp
[pettanr/pettanr.git] / app / controllers / panels_controller.rb
index abae3f7..e3c14a9 100644 (file)
@@ -1,34 +1,42 @@
 class PanelsController < ApplicationController
-  layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
+    before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
+  else
+    before_filter :authenticate_reader, :only => [:index, :show]
+    before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
+    before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
+  end
   before_filter :authenticate_admin!, :only => [:list, :browse]
-
-  public
   
-  # GET /panels
-  # GET /panels.json
+  @@model = Panel
   def index
-    @page = Panel.page params[:page]
-    @page_size = Panel.page_size params[:page_size]
-    @panels = Panel.list({}, @page, @page_size)
+    set_filer
 
     respond_to do |format|
-      format.html # index.html.erb
-      format.json { render json: @panels.to_json(Panel.list_json_opt) }
+      format_filer format
+      format.json { render text: @@model.list_as_json_text(@items) }
+      format.atom 
+      format.rss { render :layout => false }
     end
   end
 
-  # GET /panels/1
-  # GET /panels/1.json
   def show
-    @panel = Panel.show(params[:id], @author)
+    @item = Panel.show(params[:id], @operators)
 
     respond_to do |format|
-      format.html # show.html.erb
-      format.json { render json: @panel.to_json(Panel.show_json_include_opt) }
-      format.jsonp {
-        render :json => "callback(" + @panel.to_json(Panel.show_json_include_opt) + ");"
+      format.html {
+        @panel = @item
+        if @operators.author
+          @new_scrolls = Scroll.mylist(@operators.author, 1, 5)
+          @fresh_scrolls = ScrollPanel.mylist(@operators.author, 1, 5).map {|sp| sp.scroll}
+          @new_sheets = Sheet.mylist(@operators.author, 1, 5)
+          @fresh_sheets = SheetPanel.mylist(@operators.author, 1, 5).map {|sp| sp.sheet}
+        end
       }
+      format_prof format
+      format.json { render json: @item.panel_elements_as_json }
     end
   end
 
@@ -61,35 +69,33 @@ class PanelsController < ApplicationController
     @panel.supply_default
 
     respond_to do |format|
-      format.html # new.html.erb
+      format.html
       format.js
-      format.json { render json: @panel }
+      format.json { render json: @panel.panel_elements_as_json }
     end
   end
 
   def edit
-    @panel = Panel.show(params[:id], @author)
+    @panel = Panel.edit(params[:id], @author)
     respond_to do |format|
       format.html
       format.js
     end
   end
 
-  # POST /panels
-  # POST /panels.json
   def create
     @panel = Panel.new
     @panel.supply_default
+    jsn = nil
     if params[:json]
-      jsn = JSON.parse(params[:json])
+      jsn = JSON.parse_no_except(params[:json])
     end
     @prm = params[:panel] || jsn
-    @panel.attributes = @prm
-    @panel.overwrite @author
     respond_to do |format|
-      if @panel.store
-        format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
-        format.json { render json: @panel, status: :created, location: @panel }
+      if @panel.store @prm, @author
+        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" }
         format.json { render json: @panel.errors, status: :unprocessable_entity }
@@ -97,19 +103,17 @@ class PanelsController < ApplicationController
     end
   end
 
-  # PUT /panels/1
-  # PUT /panels/1.json
   def update
     @panel = Panel.edit(params[:id], @author)
+    jsn = nil
     if params[:json]
       jsn = JSON.parse(params[:json])
     end
     @prm = params[:panel] || jsn
-    @panel.attributes = @prm
-    @panel.overwrite @author
     respond_to do |format|
-      if @panel.store
-        format.html { redirect_to @panel, notice: 'Panel was successfully updated.' }
+      if @panel.store @prm, @author
+        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" }
@@ -118,33 +122,33 @@ 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 }
-      end
-    end
-  end
-  
-  def move
-    @panel = Panel.find(params[:id])
-    @new_seq = params[:panel][:t].to_i
-    respond_to do |format|
-      Panel.transaction do
-        if @panel.move_to(@new_t)
-          format.html { redirect_to @panel, notice: 'Panel was successfully moved.' }
+        if @panel.destroy_with_elements
+          flash[:notice] = I18n.t('flash.notice.destroyed', :model => Panel.model_name.human)
+          format.html { redirect_to '/home/panels' }
           format.json { head :ok }
         else
-          format.html { render action: "show" }
+          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
   
+  def catch
+    @panel = Panel.edit(params[:id], @author)
+
+    respond_to do |format|
+      @author.working_panel_id = @panel.id
+      if @author.save
+        format.html { redirect_to @panel }
+      else
+      end
+    end
+  end
+
 end