+++ /dev/null
-class SpeachBalloonTemplatesController < 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
- end
-
- public
- # GET /speach_balloon_templates
- # GET /speach_balloon_templates.json
- def index
- @speach_balloon_templates = SpeachBalloon.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @speach_balloon_templates }
- end
- end
-
- # GET /speach_balloon_templates/1
- # GET /speach_balloon_templates/1.json
- def show
- @speach_balloon_template = SpeachBalloon.find(params[:id], include: {:balloon_templates => :speach_templates})
-
- respond_to do |format|
- format.html # show.html.erb
- format.json {
- render :json => @speach_balloon_template.to_json(include: {
- :balloon_templates => {:include => :speach_templates}
- })
- }
- format.jsonp {
- render :json => "callback(" + @speach_balloon_template.to_json(include: {
- :balloon_templates => {:include => :speach_templates}
- }) + ")"
- }
- end
- end
-
- def list
- @speach_balloon_templates = SpeachBalloon.all
-
- respond_to do |format|
- format.html { render layout: 'system' }
- format.json { render json: @speach_balloon_templates }
- end
- end
-
- def browse
- @speach_balloon_template = SpeachBalloon.find(params[:id])
-
- respond_to do |format|
- format.html { render layout: 'system' }
- format.json { render json: @speach_balloon_template }
- end
- end
-
- # POST /speach_balloon_templates
- # POST /speach_balloon_templates.json
- def create
- @speach_balloon_template = SpeachBalloon.new(params[:speach_balloon_template])
- if em = validate_param(params[:speach_balloon_template])
- respond_to do |format|
- format.json { render json: em, status: :unprocessable_entity }
- end
- else
- respond_to do |format|
- if @speach_balloon_template.save
- format.html { redirect_to @speach_balloon_template, notice: 'Speach balloon was successfully created.' }
- format.json { render json: @speach_balloon_template, status: :created, location: @speach_balloon_template }
- else
- format.html { render action: "new" }
- format.json { render json: @speach_balloon_template.errors, status: :unprocessable_entity }
- end
- end
- end
- end
-
- # DELETE /speach_balloon_templates/1
- # DELETE /speach_balloon_templates/1.json
- def destroy
- @speach_balloon_template = SpeachBalloon.find(params[:id])
- @speach_balloon_template.destroy
-
- respond_to do |format|
- format.html { redirect_to speach_balloon_templates_url }
- format.json { head :ok }
- end
- end
-end