OSDN Git Service

add lg_id in resource picture
[pettanr/pettanr.git] / app / controllers / speech_balloon_templates_controller.rb
index d17ff32..96f337d 100644 (file)
 class SpeechBalloonTemplatesController < ApplicationController
-  before_filter :authenticate_user!, :only => [:index, :show]
-  before_filter :authenticate_admin!, :only => [:list, :browse, :import, :destroy]
+  if Manifest.manifest.magic_numbers['run_mode'] == 0
+    before_filter :authenticate_user, :only => []
+  else
+    before_filter :authenticate_reader, :only => [
+      :index, :show, :by_panel, :by_system_picture, :count, :count_by_panel, :count_by_system_picture
+    ]
+    before_filter :authenticate_user, :only => []
+  end
+  before_filter :authenticate_admin, :only => [:new, :create, :edit, :update, :destroy]
 
-  private
-  
-  def validate_param(ft)
-    res = nil
-    bl = ft[:size_count].to_i
-    tl = ft[:tail_count].to_i
-    if bl * tl == ft[:balloon_templates_attributes].size
-      flag = []
-      bl.times do |i|
-        flag[i] = []
-        tl.times do |j|
-          flag[i][j] = true
-        end
-      end
-      ft[:balloon_templates_attributes].each do |k, t|
-        flag[t[:size].to_i - 1][t[:tail].to_i - 1] = nil
-      end
-      if flag.flatten.compact.size == 0
-      else
-        res = "invalid variation"
-      end
-    else
-      res = "invalid template size"
-    end
-    res
+  def self.model
+    SpeechBalloonTemplate
   end
   
-  public
-  # GET /speech_balloon_templates
-  # GET /speech_balloon_templates.json
   def index
-    @speech_balloon_templates = SpeechBalloon.all
-
-    respond_to do |format|
-      format.html # index.html.erb
-      format.json { render json: @speech_balloon_templates }
-    end
+    filer_list
   end
-
-  # GET /speech_balloon_templates/1
-  # GET /speech_balloon_templates/1.json
+  
+  def by_panel
+    filer_list
+  end
+  
+  def by_system_picture
+    filer_list
+  end
+  
+  def show_html_format format
+    format.html {
+    }
+  end
+  
   def show
-    @speech_balloon_template = SpeechBalloon.find(params[:id], include: {:balloon_templates => :speech_templates})
-
+    set_show
     respond_to do |format|
-      format.html # show.html.erb
-      format.json {
-        render :json => @speech_balloon_template.to_json(include: {
-          :balloon_templates => {:include => :speech_templates}
-        })
-      }
-      format.jsonp {
-        render :json => "callback(" + @speech_balloon_template.to_json(include: {
-          :balloon_templates => {:include => :speech_templates}
-        }) + ")"
-      }
+      show_html_format format
+      show_prof_format format
+      show_json_format format
     end
   end
-
-  def list
-    @speech_balloon_templates = SpeechBalloon.all
-
-    respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @speech_balloon_templates }
-    end
+  
+  def count
+    list_count
   end
-
-  def browse
-    @speech_balloon_template = SpeechBalloon.find(params[:id])
-
-    respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @speech_balloon_template }
-    end
+  
+  def count_by_panel
+    list_count
   end
-
-  # POST /speech_balloon_templates
-  # POST /speech_balloon_templates.json
-  def create
-    @speech_balloon_template = SpeechBalloon.new(params[:speech_balloon_template])
-    if em = validate_param(params[:speech_balloon_template])
-      respond_to do |format|
-        format.json { render json: em, status: :unprocessable_entity }
-      end
-    else
-      respond_to do |format|
-        if @speech_balloon_template.save
-          format.html { redirect_to @speech_balloon_template, notice: 'Speech balloon was successfully created.' }
-          format.json { render json: @speech_balloon_template, status: :created, location: @speech_balloon_template }
-        else
-          format.html { render action: "new" }
-          format.json { render json: @speech_balloon_template.errors, status: :unprocessable_entity }
-        end
-      end
-    end
+  
+  def count_by_system_picture
+    list_count
   end
-
-  # DELETE /speech_balloon_templates/1
-  # DELETE /speech_balloon_templates/1.json
+  
+  def new
+    form_new
+  end
+  
+  def edit
+    form_edit
+  end
+  
   def destroy
-    @speech_balloon_template = SpeechBalloon.find(params[:id])
-    @speech_balloon_template.destroy
+    @item = SpeechBalloonTemplate.find(params[:id])
+    @item.destroy
 
     respond_to do |format|
-      format.html { redirect_to speech_balloon_templates_url }
+      format.html { redirect_to :action => :list }
       format.json { head :ok }
     end
   end