X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fpanels_controller.rb;h=ebbb8babc8dd2942c4ca81f34c6d710401b5c7ff;hb=3e64a37b6628a081b06eb7278506fcc10d6a3d34;hp=50f45f6fbaf15d3a493dc37ed466aec5679d813f;hpb=446bb160b02df2c5966188f18e28632e70723861;p=pettanr%2Fpettanr.git diff --git a/app/controllers/panels_controller.rb b/app/controllers/panels_controller.rb index 50f45f6f..ebbb8bab 100644 --- a/app/controllers/panels_controller.rb +++ b/app/controllers/panels_controller.rb @@ -1,52 +1,46 @@ class PanelsController < ApplicationController - layout 'test' if Pettanr::TestLayout - before_filter :authenticate_user!, :only => [:index, :show, :create, :update, :destroy] + layout 'test' if MagicNumber['test_layout'] + if MagicNumber['run_mode'] == 0 + before_filter :authenticate_user!, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + else + before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy] + before_filter :authenticate_author, :only => [:index, :show, :new, :edit, :create, :update, :destroy] + end before_filter :authenticate_admin!, :only => [:list, :browse] - private - - def treat_param panel - panel.author_id = @author.id - end - public - # GET /panels - # GET /panels.json def index - @panels = Panel.find(:all, :include => [:comic, :author], :order => 'updated_at', :limit => 20) + @page = Panel.page params[:page] + @page_size = Panel.page_size params[:page_size] + @panels = Panel.list(@page, @page_size) respond_to do |format| format.html # index.html.erb - format.json { render :json => @panels.to_json( - :include => [:comic, :author] - ) } + format.json { render text: Panel.list_as_json_text(@panels) } end end - # GET /panels/1 - # GET /panels/1.json def show - @panel = Panel.find(params[:id], include: [:comic, :panel_pictures => :resource_picture, :balloons => :speaches])# only: [:width, :height]) + @panel = Panel.show(params[:id], @author) 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.json { render json: @panel.panel_elements_as_json } format.jsonp { - render :json => "callback(" + @panel.to_json(include: { - :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus} - }) + ");" + render :json => "callback(" + @panel.panel_elements_as_json + ");" } -# 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]) } end end + def count + @panel = {:count => Panel.visible_count} + respond_to do |format| + format.json { render json: @panel.to_json } + end + end + def list @panels = Panel.all :order => 'updated_at' @@ -64,83 +58,75 @@ class PanelsController < ApplicationController end end - # POST /panels - # POST /panels.json + def new + @panel = Panel.new + @panel.supply_default + + respond_to do |format| + format.html { render layout: 'metro' } + format.js + format.json { render json: @panel.panel_elements_as_json } + end + end + + def edit + @panel = Panel.edit(params[:id], @author) + respond_to do |format| + format.html + format.js + end + end + 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 = Panel.new(@prm) - treat_param @panel - @comic = Comic.find @panel.comic_id - 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 @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 } 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 + @panel = Panel.edit(params[:id], @author) + jsn = nil + if params[:json] + jsn = JSON.parse(params[:json]) + end + @prm = params[:panel] || jsn + respond_to do |format| + 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" } + format.json { render json: @panel.errors, status: :unprocessable_entity } end - else - format.html { render action: "edit" } - format.json { render json: @panel.errors, status: :unprocessable_entity } 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 - 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 + @panel = Panel.edit(params[:id], @author) 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/panel' } 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