X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fcomics_controller.rb;h=617439a690de035877bdf29a9b20ba1ca2fb1512;hb=02ea4fc4bbe7a54dd576c1cd700aa9e32710abf8;hp=18055980ae4e6b9f031ebe35786816b38d2a5f06;hpb=261d481751fff922dcdfc391aa7932d344fb447c;p=pettanr%2Fpettanr.git diff --git a/app/controllers/comics_controller.rb b/app/controllers/comics_controller.rb index 18055980..617439a6 100644 --- a/app/controllers/comics_controller.rb +++ b/app/controllers/comics_controller.rb @@ -1,52 +1,37 @@ class ComicsController < ApplicationController - if Const.run_mode == 0 - before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy] + layout 'test' if MagicNumber['test_layout'] + if MagicNumber['run_mode'] == 0 + before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] + before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] else - before_filter :authenticate_user!, :only => [:top, :index, :show, :play, :new, :create, :edit, :update, :destroy] + before_filter :authenticate_reader, :only => [:top, :index, :show] + before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] + before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] end before_filter :authenticate_admin!, :only => [:list, :browse] - private - - def treat_param comic - comic.author_id = @author.id - end - - public - - def top - @new_comics = Comic.find(:all, - :include => :author, :conditions => ['visible > 0'], :order => 'updated_at desc', :limit => 5 - ) - @new_pictures = OriginalPicture.find(:all, - :include => [:artist, :license, :resource_picture], :order => 'updated_at', :limit => 5 - ) - - respond_to do |format| - format.html # index.html.erb - end - end - - # GET /comics - # GET /comics.json + @@model = Comic def index - @page = Comic.page params[:page] - @page_size = Comic.page_size params[:page_size] - @comics = Comic.list({}, @page, @page_size) + set_filer + respond_to do |format| - format.html # index.html.erb - format.json { render json: @comics.to_json(Comic.list_json_opt) } + format_filer format + format.json { render json: @items.to_json(@@model.list_json_opt) } + format.atom + format.rss end end - # GET /comics/1 - # GET /comics/1.json def show - @comic = Comic.show(params[:id], @author) - + @item = Comic.show(params[:id], @operators) respond_to do |format| - format.html # show.html.erb - format.json { render json: @comic.to_json(Comic.show_json_include_opt) } + format.html { + @comic = @item + } + format_prof format + format.json { render json: @item.to_json(Comic.show_json_opt) } + format.atom + format.rss end end @@ -57,23 +42,6 @@ class ComicsController < ApplicationController end end - def play - c = Comic.show(params[:id], @author) - cnt = Panel.count(:conditions => ['comic_id = ?', c.id]).to_i - @offset = Comic.offset cnt, params[:offset] - @panel_count = Comic.panel_count cnt, params[:count] - @comic = Comic.play(params[:id]) - respond_to do |format| - format.html # index.html.erb - format.json { - render :json => @comic.to_json_play - } - format.jsonp { - render :json => "callback(" + @comic.to_json_play + ");" - } - end - end - def list @comics = Comic.all @@ -92,76 +60,72 @@ class ComicsController < ApplicationController end end - # GET /comics/new - # GET /comics/new.js def new @comic = Comic.new @comic.supply_default respond_to do |format| format.html # new.html.erb format.js + format.json { render json: @comic.to_json(Comic.show_json_opt) } end end - # GET /comics/1/edit - # GET /comics/1.js/edit def edit - @comic = Comic.show(params[:id], @author) - @comic.supply_default + @comic = Comic.edit(params[:id], @author) respond_to do |format| format.html format.js end end - # POST /comics - # POST /comics.json def create - params[:comic].merge! author_id: @author.id - @comic = Comic.new params[:comic] + @comic = Comic.new @comic.supply_default + @comic.attributes = params[:comic] + @comic.overwrite @author respond_to do |format| if @comic.save - format.html { redirect_to @comic, notice: 'Comic was successfully created.' } - format.json { render json: Comic.show(@comic.id, @author).to_json(Comic.show_json_include_opt), status: :created, location: @comic } + flash[:notice] = I18n.t('flash.notice.created', :model => Comic.model_name.human) + format.html { redirect_to @comic } + format.json { render json: @comic.to_json(Comic.show_json_opt), status: :created, location: @comic } else + flash[:notice] = I18n.t('flash.notice.not_created', :model => Comic.model_name.human) format.html { render action: "new" } format.json { render json: @comic.errors, status: :unprocessable_entity } end end end - # PUT /comics/1 - # PUT /comics/1.json def update - params[:comic].merge! author_id: @author.id - @comic = Comic.show(params[:id], @author) + @comic = Comic.edit(params[:id], @author) + @comic.attributes = params[:comic] + @comic.overwrite @author respond_to do |format| - raise ActiveRecord::Forbidden unless @comic.own?(@author) - if @comic.update_attributes(params[:comic]) - format.html { redirect_to @comic, notice: 'Comic was successfully updated.' } + if @comic.save + flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human) + format.html { redirect_to @comic } format.json { head :ok } else + flash[:notice] = I18n.t('flash.notice.not_updated', :model => Comic.model_name.human) format.html { render action: "edit" } format.json { render json: @comic.errors, status: :unprocessable_entity } end end end - # DELETE /comics/1 - # DELETE /comics/1.json def destroy - @comic = Comic.find(params[:id]) - if @comic.own? @author - @comic.destroy - respond_to do |format| - format.html { redirect_to comics_url } + @comic = Comic.edit(params[:id], @author) + respond_to do |format| + if @comic.destroy_with_story + flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human) + format.html { redirect_to '/home/comics' } format.json { head :ok } + else + flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human) + format.html { redirect_to @comic } + format.json { render json: @comic.errors, status: :unprocessable_entity } end - else - format.html { render action: "edit" } - format.json { render json: @comic.errors, status: :unprocessable_entity } end end end