X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fscrolls_controller.rb;h=3c88b607fb7e6d6918b0b8d078f886182032a1ff;hb=665761e56525215946e2547a70c82c603d5047af;hp=825e1533514758a3c990250031470d1cf780598d;hpb=02ea4fc4bbe7a54dd576c1cd700aa9e32710abf8;p=pettanr%2Fpettanr.git diff --git a/app/controllers/scrolls_controller.rb b/app/controllers/scrolls_controller.rb index 825e1533..3c88b607 100644 --- a/app/controllers/scrolls_controller.rb +++ b/app/controllers/scrolls_controller.rb @@ -1,168 +1,103 @@ class ScrollsController < ApplicationController - layout 'test' if MagicNumber['test_layout'] - if MagicNumber['run_mode'] == 0 + if Manifest.manifest.magic_numbers['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_reader, :only => [:top, :index, :show, :play] + 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 - before_filter :authenticate_admin!, :only => [:list, :browse] - - @@model = Scroll + def index - set_filer - - respond_to do |format| - format_filer format - format.json { render json: @items.to_json(@@model.list_json_opt) } - format.atom - format.rss - end + filer_list + end + + def by_author + filer_list end - + + def by_panel + 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 { - @scroll = @item - if @operators.author - @new_panels = Panel.mylist(@operators.author, 1, 5) - 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 - @scroll = Scroll.show(params[:id], [@user, @admin]) - cnt = ScrollPanel.count(:conditions => ['scroll_id = ?', @scroll.id]).to_i - @offset = ScrollPanel.offset cnt, params[:offset] - @panel_count = ScrollPanel.panel_count cnt, params[:count] - @scroll_panels = ScrollPanel.play_list(@scroll, @author, @offset, @panel_count) + set_play + play_list respond_to do |format| format.html { - @prev_offset = if @offset > 0 - if @offset - @panel_count < 0 - 0 - else - @offset - @panel_count - end - else - nil - end - @next_offset = if @offset + @panel_count > cnt - nil - else - @offset + @panel_count + if @item.own? @operators + @fresh_panel_items = assist_items('panels', 'index') + @new_panel_items = assist_items('home', 'panels') end - if @author - @new_panels = Panel.mylist(@author, 1, 5) - end - } - format.json {render text: ScrollPanel.list_as_json_text(@scroll_panels, @author)} - format.jsonp { - render :json => "callback(" + @scroll_panels.to_json_list + ");" } + 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 list - @scrolls = Scroll.all - - respond_to do |format| - format.html { render layout: 'system' }# index.html.erb - format.json { render json: @scrolls } - end + def count_by_author + list_count end - - def browse - @scroll = Scroll.find(params[:id]) - - respond_to do |format| - format.html { render layout: 'system' } # show.html.erb - format.json { render json: @scroll } - 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 # new.html.erb - format.js - format.json { render json: @scroll.to_json(Scroll.show_json_opt) } - end + form_new end - + def edit - @scroll = Scroll.edit(params[:id], @author) - 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 @author - - 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], @author) - @scroll.attributes = params[:scroll] - @scroll.overwrite @author - 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], @author) - 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