OSDN Git Service

add scroll player
[pettanr/pettanr.git] / app / controllers / panels_controller.rb
index 50f45f6..376c68c 100644 (file)
 class PanelsController < ApplicationController
-  layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [:index, :show, :create, :update, :destroy]
-  before_filter :authenticate_admin!, :only => [:list, :browse]
-
-  private
-  
-  def treat_param panel
-    panel.author_id = @author.id
+  if Manifest.manifest.magic_numbers['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, :by_scroll, :by_sheet, :by_author, :by_speech_balloon_template
+    ]
+    before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
+    before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
   end
   
+  private
+  def panel_list
+    set_list
+    @items = @list.items 
+    @pager = @list.page_status.pager
+    respond_to do |format|
+      format.html 
+      list_json_format @list, format
+      format.atom 
+      format.rss
+    end
+  end
   public
-  
-  # GET /panels
-  # GET /panels.json
   def index
-    @panels = Panel.find(:all, :include => [:comic, :author], :order => 'updated_at', :limit => 20)
-
-    respond_to do |format|
-      format.html # index.html.erb
-      format.json { render :json => @panels.to_json(
-        :include => [:comic, :author]
-      ) }
+    if params[:mode] == 'filer'
+      filer_list
+    else
+      panel_list
     end
   end
-
-  # GET /panels/1
-  # GET /panels/1.json
+  
+  def by_scroll
+    filer_list
+  end
+  
+  def by_sheet
+    filer_list
+  end
+  
+  def by_author
+    filer_list
+  end
+  
+  def by_speech_balloon_template
+    filer_list
+  end
+  
+  def show_html_format format
+    format.html {
+      if @operators.author
+        @new_scroll_items = assist_items('home', 'scrolls')
+        @fresh_scroll_items = assist_items('home', 'scroll_panels').map {|sp| sp.scroll}
+      end
+    }
+  end
+  
   def show
-    @panel = Panel.find(params[:id], include: [:comic, :panel_pictures => :resource_picture, :balloons => :speaches])# only: [:width, :height])
-
+    set_show
     respond_to do |format|
-      format.html # show.html.erb
-       format.json {
-        render :json => @panel.to_json(include: {
-          :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
-        })
-      }
-      format.jsonp {
-        render :json => "callback(" + @panel.to_json(include: {
-          :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
-        }) + ");"
-      }
-#      format.json { render :json => @frame.to_json(include: {
-#        :comic => {:only => :title}, :panel_pictures => {:include => {:image => {:only => [:width]}},:only => [:width, :height, :z, :image_id]}
-#      }, only: [:border]) }
+      show_html_format format
+      show_prof_format format
+      if params[:with_elements]
+        show_json_format_for_root format
+      else
+        show_json_format format
+      end
     end
   end
-
-  def list
-    @panels = Panel.all :order => 'updated_at'
-
+  
+  def new
+    set_new
     respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @panels }
+      format.html {
+        @editor = Editor::PanelEditor.new @item, @operators
+        render :template => @editor.template_name, :locals => {
+          :editor => @editor
+        }
+      }
+      format.json { render json: @item.to_json }
     end
   end
-
-  def browse
-    @panel = Panel.find(params[:id])
-
+  
+  def edit
+    set_edit
     respond_to do |format|
-      format.html { render layout: 'system' }
+      format.html {
+        @editor = Editor::PanelEditor.new @item, @operators
+        render :template => @editor.template_name, :locals => {
+          :editor => @editor
+        }
+      }
+      format.json { render json: @item.to_json }
     end
   end
-
-  # POST /panels
-  # POST /panels.json
+  
   def create
+    set_model
+    @item = @my_model_class.new
+#    @item.boosts 'post'
+    jsn = nil
     if params[:json]
-      jsn = JSON.parse(params[:json])
+      jsn = JSON.parse_no_except(params[:json])
     end
-    @prm = params[:panel] || jsn
-    @panel = Panel.new(@prm)
-    treat_param @panel
-    @comic = Comic.find @panel.comic_id
-
+    @prm = if params[:panel] == nil or params[:panel].empty?
+       jsn
+    else
+       params[:panel]
+    end
+    @item.class.fold_extend_settings @prm
+    #@item.refresh
     respond_to do |format|
-      Panel.transaction do
-        if @panel.vdt_save
-          format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
-          format.json { render json: @panel, status: :created, location: @panel }
-        else
-          format.html { render action: "new" }
-          format.json { render json: @panel.errors, status: :unprocessable_entity }
-        end
+      if @item.store @prm, @operators
+        created_html_format format
+        created_json_format format
+      else
+        format.html {
+          flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
+          @editor = Editor::PanelEditor.new @item, @operators
+          render :template => @editor.template_name, :locals => {
+            :editor => @editor
+          }
+        }
+        not_created_json_format format
       end
     end
   end
-
-  # PUT /panels/1
-  # PUT /panels/1.json
+  
   def update
-    @panel = Panel.find(params[:id])
-    if @panel.own? @author
-      respond_to do |format|
-        Panel.transaction do
-          if params[:panel][:t] and params[:panel][:t].to_i != @panel.t
-            @panel.move_to params[:panel][:t].to_i
-          end
-          if @panel.update_attributes(params[:panel])
-            format.html { redirect_to @panel, notice: 'Panel was successfully updated.' }
-            format.json { head :ok }
-          else
-            format.html { render action: "edit" }
-            format.json { render json: @panel.errors, status: :unprocessable_entity }
-          end
-        end
-      end
-    else
-      format.html { render action: "edit" }
-      format.json { render json: @panel.errors, status: :unprocessable_entity }
+    @item = Panel.edit(params[:id], @operators)
+    @item.boosts 'post'
+    jsn = nil
+    if params[:json]
+      jsn = JSON.parse(params[:json])
     end
-  end
-
-  # DELETE /panels/1
-  # DELETE /panels/1.json
-  def destroy
-    @panel = Panel.find(params[:id])
-    if @panel.own? @author
-      respond_to do |format|
-        Panel.transaction do
-          @panel.destroy_and_shorten
-          format.html { redirect_to panels_url }
-          format.json { head :ok }
-        end
+    @prm = params[:panel] || jsn
+    @item.class.fold_extend_settings @prm
+    @item.attributes = @prm
+    # @item.refresh
+    respond_to do |format|
+      if @item.store @prm, @operators
+        updated_html_format format
+        updated_json_format format
+      else
+        format.html {
+          flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
+          @editor = Editor::PanelEditor.new @item, @operators
+          render :template => @editor.template_name, :locals => {
+            :editor => @editor
+          }
+        }
+        not_updated_json_format format
       end
-    else
-      format.html { render action: "edit" }
-      format.json { render json: @panel.errors, status: :unprocessable_entity }
     end
   end
   
-  def move
-    @panel = Panel.find(params[:id])
-    @new_seq = params[:panel][:t].to_i
+  def destroy
+    @item = Panel.edit(params[:id], @operators)
     respond_to do |format|
       Panel.transaction do
-        if @panel.move_to(@new_t)
-          format.html { redirect_to @panel, notice: 'Panel was successfully moved.' }
+        if @item.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" }
-          format.json { render json: @panel.errors, status: :unprocessable_entity }
+          flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Panel.model_name.human)
+          format.html { redirect_to @item }
+          format.json { render json: @item.errors, status: :unprocessable_entity }
         end
       end
     end
   end
   
+  def catch
+    @item = Panel.edit(params[:id], @operators)
+
+    respond_to do |format|
+      @operators.author.working_panel_id = @item.id
+      if @operators.author.save
+        format.html { redirect_to @item }
+      else
+      end
+    end
+  end
+
 end