OSDN Git Service

temp
[pettanr/pettanr.git] / app / controllers / speech_balloon_templates_controller.rb
index cbb2d5b..c89db4b 100644 (file)
@@ -1,58 +1,33 @@
 class SpeechBalloonTemplatesController < ApplicationController
-  before_filter :authenticate_user!, :only => [:index, :show]
-  before_filter :authenticate_admin!, :only => [:list, :browse, :import, :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
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => []
+  else
+    before_filter :authenticate_reader, :only => [:index, :show]
+    before_filter :authenticate_user, :only => []
   end
-  
-  public
-  # GET /speech_balloon_templates
-  # GET /speech_balloon_templates.json
+  before_filter :authenticate_admin!, :only => [:list, :browse, :destroy]
+
+  @@model = SpeechBalloonTemplate
   def index
-    @speech_balloon_templates = SpeechBalloonTemplate.all
+    set_filer
 
     respond_to do |format|
-      format.html # index.html.erb
-      format.json { render json: @speech_balloon_templates }
+      format_filer format
+      format.json { render json: @items.to_json(@@model.list_json_opt) }
     end
   end
 
-  # GET /speech_balloon_templates/1
-  # GET /speech_balloon_templates/1.json
   def show
-    @speech_balloon_template = SpeechBalloonTemplate.find(params[:id])
+    @item = SpeechBalloonTemplate.show(params[:id], @operators)
 
     respond_to do |format|
-      format.html # show.html.erb
-      format.json {
-        render :json => @speech_balloon_template.to_json()
+      format.html {
+        @speech_balloon_template = @item
       }
-      format.jsonp {
-        render :json => "callback(" + @speech_balloon_template.to_json() + ")"
+      format_prof format
+      format.json {
+        render :json => @item.to_json(SpeechBalloonTemplate.show_json_opt)
       }
     end
   end
@@ -75,29 +50,6 @@ class SpeechBalloonTemplatesController < ApplicationController
     end
   end
 
-  # POST /speech_balloon_templates
-  # POST /speech_balloon_templates.json
-  def create
-    @speech_balloon_template = SpeechBalloonTemplate.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
-  end
-
-  # DELETE /speech_balloon_templates/1
-  # DELETE /speech_balloon_templates/1.json
   def destroy
     @speech_balloon_template = SpeechBalloonTemplate.find(params[:id])
     @speech_balloon_template.destroy