X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fpanel_pictures_controller.rb;h=3ae4dac9c218eb26b4f58116b1a71c659d89f00e;hb=d6d237012089604cdbc61943856d42c0a0472dc7;hp=b48915b6a1809591c6711ef2e0140bfc08d79db8;hpb=d8b50c09ff9034a9abd9cf10ae839e0402df0e7c;p=pettanr%2Fpettanr.git diff --git a/app/controllers/panel_pictures_controller.rb b/app/controllers/panel_pictures_controller.rb index b48915b6..3ae4dac9 100644 --- a/app/controllers/panel_pictures_controller.rb +++ b/app/controllers/panel_pictures_controller.rb @@ -1,150 +1,39 @@ class PanelPicturesController < ApplicationController - 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] + if Manifest.manifest.magic_numbers['run_mode'] == 0 + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] else - before_filter :authenticate_reader, :only => [:index, :show] - before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy] + before_filter :authenticate_reader, :only => [ + :index, :show, :by_panel, :by_author + ] + before_filter :authenticate_user, :only => [] + before_filter :authenticate_author, :only => [] end - before_filter :authenticate_admin!, :only => [:list, :browse] - + def index - @page = PanelPicture.page params[:page] - @page_size = PanelPicture.page_size params[:page_size] - @panel_pictures = PanelPicture.list(@page, @page_size) - - respond_to do |format| - format.html { - @paginate = PanelPicture.list_paginate(@page, @page_size) - render :template => 'system/filer', :locals => { - :items => @panel_pictures, :model => PanelPicture, - :roles => [@user, @admin], :pager => @paginate - } - } - format.json { render :json => @panel_pictures.to_json(PanelPicture.list_json_opt) } - end - end - - def show - @panel_picture = PanelPicture.show(params[:id], [@user, @admin]) - - respond_to do |format| - format.html - format.prof { render :template => 'top/prof', :layout => true } - format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) } - end + filer_list end - - def list - @panel_pictures = PanelPicture.all - - respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @panel_pictures } - end - end - - def browse - @panel_picture = PanelPicture.find(params[:id]) - - respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @panel_picture} - end - end - - def new - raise Pettanr::NotWork unless @author.working_panel - @picture = Picture.show params[:picture_id], @author - raise ActiveRecord::Forbidden unless @picture.enable? - @panel = Panel.edit(@author.working_panel, @author) - - @panel_picture = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id - @panel_picture.supply_default - - respond_to do |format| - format.html - format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) } - end - end - - def edit - @panel_picture = PanelPicture.show(params[:id], @author) - @panel = Panel.edit(@panel_picture.panel.id, @author) - - respond_to do |format| - format.html - end + + def by_panel + filer_list end - - def create - raise Pettanr::NotWork unless @author.working_panel - @panel = Panel.edit(@author.working_panel, @author) - - @panel_picture = PanelPicture.new - @panel_picture.attributes = params[:panel_picture] - @panel_picture.overwrite @panel.id - - @picture = Picture.show @panel_picture.picture_id, @author - raise ActiveRecord::Forbidden unless @picture.enable? - - respond_to do |format| - if @panel_picture.valid? - if @panel_picture.store @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 - flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human) - format.html { render action: "new" } - format.json { render json: @panel.errors, status: :unprocessable_entity } - end - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human) - format.html { render action: "new" } - format.json { render json: @panel_picture.errors, status: :unprocessable_entity } - end - end + + def by_author + filer_list end - - def update - @panel_picture = PanelPicture.show(params[:id], @author) - @panel_picture.attributes = params[:panel_picture] - @panel = Panel.edit(@panel_picture.panel.id, @author) - @panel_picture.overwrite @panel.id - - @picture = Picture.show @panel_picture.picture_id, @author - raise ActiveRecord::Forbidden unless @picture.enable? - - respond_to do |format| - if @panel_picture.store @author - flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human) - format.html { redirect_to @panel_picture } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human) - format.html { render action: "edit" } - format.json { render json: @panel_picture.errors, status: :unprocessable_entity } - end - end + + def show_html_format format + format.html { + @panel_picture = @item + } end - - def destroy - @panel_picture = PanelPicture.show(params[:id], @author) - @panel = Panel.edit(@panel_picture.panel.id, @author) - + + def show + set_show respond_to do |format| - if @panel_picture.remove @author - flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human) - format.html { redirect_to @panel } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human) - format.html { redirect_to @panel_picture } - format.json { render json: @panel_picture.errors, status: :unprocessable_entity } - end + show_html_format format + show_prof_format format + show_json_format format end end