X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fscrolls_controller.rb;h=3c88b607fb7e6d6918b0b8d078f886182032a1ff;hb=665761e56525215946e2547a70c82c603d5047af;hp=3ee8fb23d938181e09725251d2fce062bf6f2dc5;hpb=2aa1323f37c9fb76373328c25e251291aa9addac;p=pettanr%2Fpettanr.git diff --git a/app/controllers/scrolls_controller.rb b/app/controllers/scrolls_controller.rb index 3ee8fb23..3c88b607 100644 --- a/app/controllers/scrolls_controller.rb +++ b/app/controllers/scrolls_controller.rb @@ -3,144 +3,101 @@ class ScrollsController < ApplicationController before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] else - before_filter :authenticate_reader, :only => [:top, :index, :show, :play, :scroll_panels, :panels, :by_author, :by_panel] + before_filter :authenticate_reader, :only => [ + :top, :index, :show, :play, :by_panel, :by_author + ] before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] end - def self.model - Scroll - end - def index - public_list - end - - def scroll_panels - has_many_list - end - - def panels - has_many_list + filer_list end def by_author - filter_list + filer_list end def by_panel - filter_list + filer_list + end + + def show_html_format format + format.html { + play_list = Locmare::ListGroup.list( + 'scroll_panels', 'by_scroll', @operators, + {:id => @item.id, :my_play => @item.own?(@operators)} + ) + @play_count = play_list.count(@operators) + } end def show - @item = Scroll.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - if @operators.author - @new_panel_items = assist_items('panel', 'private_list') - @new_panel_filer = assist_filer 'panel', @new_panel_items - end - } - format.json { render json: @item.to_json(Scroll.show_json_opt) } - format_prof format - format.atom - format.rss + show_html_format format + show_prof_format format + show_json_format format end end - + def play - @item = self.class.model.show(params[:id], @operators) - action_name = params[:action] - @action = self.class.controller.open(action_name, params, @operators) - @items = @action.list.items @item + set_play + play_list respond_to do |format| format.html { - @count = @action.list.count @item - @prev_offset = @action.list.prev_offset @item - @next_offset = @action.list.next_offset @item - if @operators.author - @new_panel_items = assist_items('panel', 'private_list') - @new_panel_filer = assist_filer 'panel', @new_panel_items + if @item.own? @operators + @fresh_panel_items = assist_items('panels', 'index') + @new_panel_items = assist_items('home', 'panels') end } - format.json { render json: @items.to_json(self.class.model.list_json_opt) } + format.json { render json: @items.to_json } end end def count - @scroll = {:count => Scroll.visible_count} - respond_to do |format| - format.json { render json: @scroll.to_json } - end + list_count + end + + def count_by_author + list_count + end + + def count_by_panel + list_count + end + + def count_play + list_count end def new - @scroll = Scroll.new - @scroll.supply_default - respond_to do |format| - format.html - format.js - format.json { render json: @scroll.to_json(Scroll.show_json_opt) } - end + form_new end - + def edit - @scroll = Scroll.edit(params[:id], @operators) - respond_to do |format| - format.html - format.js - end + form_edit end - + def create - @scroll = Scroll.new - @scroll.supply_default - @scroll.attributes = params[:scroll] - @scroll.overwrite @operators - - respond_to do |format| - if @scroll.save - flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human) - format.html { redirect_to @scroll } - format.json { render json: @scroll.to_json(Scroll.show_json_opt), status: :created, location: @scroll } - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human) - format.html { render action: "new" } - format.json { render json: @scroll.errors, status: :unprocessable_entity } - end - end + set_model + @item = @my_model_class.new + @item.supply_default + @item.attributes = params[@my_model_class.item_name] + @item.overwrite @operators + render_create end - + def update - @scroll = Scroll.edit(params[:id], @operators) - @scroll.attributes = params[:scroll] - @scroll.overwrite @operators - respond_to do |format| - if @scroll.save - flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human) - format.html { redirect_to @scroll } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human) - format.html { render action: "edit" } - format.json { render json: @scroll.errors, status: :unprocessable_entity } - end - end + set_edit + @item.attributes = params[@my_model_class.item_name] + @item.overwrite @operators + render_update end - + def destroy - @scroll = Scroll.edit(params[:id], @operators) - respond_to do |format| - if @scroll.destroy_with_scroll_panel - flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human) - format.html { redirect_to '/home/scrolls' } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Scroll.model_name.human) - format.html { redirect_to @scroll } - format.json { render json: @scroll.errors, status: :unprocessable_entity } - end - end + set_model + @item = @my_model_class.edit(params[:id], @operators) + render_destroy '/home/' + @item.path_name end end