X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fscrolls_controller.rb;h=62dd4b3c4767ca4b177cd166594a068143f13011;hb=6cbe57ca7a9cac83fad2f3c66fa097055c1fe803;hp=581d8b301ce7115910b9f5325ee88a6e7afe3d03;hpb=c5c2d866ddd974f3e8f36c2879a54bf39de028c3;p=pettanr%2Fpettanr.git diff --git a/app/controllers/scrolls_controller.rb b/app/controllers/scrolls_controller.rb index 581d8b30..62dd4b3c 100644 --- a/app/controllers/scrolls_controller.rb +++ b/app/controllers/scrolls_controller.rb @@ -3,7 +3,9 @@ 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, :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 @@ -26,11 +28,10 @@ class ScrollsController < ApplicationController def show_html_format format format.html { - @scroll = @item - if @operators.author - @new_panel_items = assist_items('panel', 'private_list') - #@new_panel_filer = assist_filer 'panel', @new_panel_items - end + play_list = Locmare::ListGroup.list 'scroll_panel', 'play' + @play_count = play_list.count(@operators, + {:id => @item.id, :my_play => @item.own?(@operators)} + ) } end @@ -42,23 +43,18 @@ class ScrollsController < ApplicationController 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('panel', 'public') + @new_panel_items = assist_items('panel', 'private') end } - format.json { render json: @items.to_json(self.class.model.list_json_opt) } + format.json { render json: @items.to_json } end end @@ -77,63 +73,30 @@ class ScrollsController < ApplicationController def new 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