X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fscrolls_controller.rb;h=943d7d27e636c458cb4f6c9ddec096641d43f636;hb=6a9125ccbacea489311fc4cc548ac03e7d0b412d;hp=f183bd5dc6f5f7935bdbed64f1464c1e64e36be5;hpb=a62696b8377211ed0324839867d5ff9b2f3d58db;p=pettanr%2Fpettanr.git diff --git a/app/controllers/scrolls_controller.rb b/app/controllers/scrolls_controller.rb index f183bd5d..943d7d27 100644 --- a/app/controllers/scrolls_controller.rb +++ b/app/controllers/scrolls_controller.rb @@ -1,174 +1,87 @@ class ScrollsController < ApplicationController - 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] + if Manifest.manifest.magic_numbers['run_mode'] == 0 + before_action :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] + before_action :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] else - before_filter :authenticate_reader, :only => [:top, :index, :show, :play] - before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] - before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] + before_action :authenticate_reader, :only => [ + :top, :index, :show, :play, :by_panel, :by_author + ] + before_action :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] + before_action :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] end - before_filter :authenticate_admin!, :only => [:list, :browse] - + def index - @page = Scroll.page params[:page] - @page_size = Scroll.page_size params[:page_size] - @scrolls = Scroll.list(@page, @page_size) - respond_to do |format| - format.html { - @paginate = Scroll.list_paginate(@page, @page_size) - render :template => 'system/filer', :locals => { - :items => @scrolls, :model => Scroll, - :roles => [@user, @admin], :pager => @paginate - } - } - format.json { render json: @scrolls.to_json(Scroll.list_json_opt) } - format.atom - format.rss - end + filer_list end - - def show - @item = Scroll.show(params[:id], [@user, @admin]) - - respond_to do |format| - format.html { - @scroll = @item - if @author - @new_panels = Panel.mylist(@author, 1, 5) - end - } - format.json { render json: @item.to_json(Scroll.show_json_opt) } - format_prof format - format.atom - format.rss - end + + def by_author + filer_list param: params[:id] 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) - 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 - 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 + ");" - } - end + + def by_panel + filer_list param: params[:id] end - def count - @scroll = {:count => Scroll.visible_count} - respond_to do |format| - format.json { render json: @scroll.to_json } - end + def show_html_format format + format.html { + @play_list = Locmare::ListGroup.list( + 'scroll_panels', 'by_scroll', @operators, + {:id => @item.id, :page_size => -1} # set no limit options} + ) + } end - def list - @scrolls = Scroll.all - + def show + set_show respond_to do |format| - format.html { render layout: 'system' }# index.html.erb - format.json { render json: @scrolls } + show_html_format format + show_prof_format format + show_json_format format end end - - def browse - @scroll = Scroll.find(params[:id]) - + + def play + set_play + play_list respond_to do |format| - format.html { render layout: 'system' } # show.html.erb - format.json { render json: @scroll } + format.html { + if @item.own? @operators + @fresh_panel_items = assist_items('panels', 'index') + @new_panel_items = assist_items('home', 'panels', finder: :find_private, param: @operators) + end + } + list_json_format @finder, format end 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 = @item.permit_params params + @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 = @item.permit_params params + @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