X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fscroll_panels_controller.rb;h=c11046a21794b9724277051b5995ef560cc8f762;hb=69b61b39006c1951fc8c08746e884e63e50233b3;hp=2fb8d04109e692021f4db9561e494267eb336ec9;hpb=d8b50c09ff9034a9abd9cf10ae839e0402df0e7c;p=pettanr%2Fpettanr.git diff --git a/app/controllers/scroll_panels_controller.rb b/app/controllers/scroll_panels_controller.rb index 2fb8d041..c11046a2 100644 --- a/app/controllers/scroll_panels_controller.rb +++ b/app/controllers/scroll_panels_controller.rb @@ -1,121 +1,96 @@ class ScrollPanelsController < 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 => [:index, :show, :scroll] + before_filter :authenticate_reader, :only => [ + :index, :show, :by_panel, :by_scroll, :by_author, :count, :count_by_panel, :count_by_scroll, :count_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] + def self.model + ScrollPanel + end + def index - @page = ScrollPanel.page params[:page] - @page_size = ScrollPanel.page_size params[:page_size] - @scroll_panels = ScrollPanel.list(@page, @page_size) - - respond_to do |format| - format.html { - @paginate = ScrollPanel.list_paginate(@page, @page_size) - render :template => 'system/filer', :locals => { - :items => @scroll_panels, :model => ScrollPanel, - :roles => [@user, @admin], :pager => @paginate - } - } - format.json { render :json => @scroll_panels.to_json(ScrollPanel.list_json_opt) } - end + filer_list end - + + def by_panel + filer_list + end + + def by_scroll + filer_list + end + + def by_author + filer_list + end + def show - @scroll_panel = ScrollPanel.show(params[:id], [@user, @admin]) - + set_show respond_to do |format| - format.html # show.html.erb - format.prof { render :template => 'top/prof', :layout => true } - format.json { render json: @scroll_panel.scroll_panel_as_json(@author) } + show_prof_format format + format.json { render json: @item.scroll_panel_as_json(@operators.author) } end end - def list - @scroll_panels = ScrollPanel.all - - respond_to do |format| - format.html { render layout: 'system' }# index.html.erb - format.json { render json: @scroll_panels } - end + def count + list_count end - - def browse - @scroll_panel = ScrollPanel.find(params[:id]) - - respond_to do |format| - format.html { render layout: 'system' } # show.html.erb - format.json { render json: @scroll_panel } - end + + def count_by_panel + list_count + end + + def count_by_scroll + list_count + end + + def count_by_author + list_count end def new - @scroll_panel = ScrollPanel.new - @scroll_panel.supply_default - respond_to do |format| - format.html # new.html.erb - format.js - format.json { render json: @scroll_panel.scroll_panel_as_json(@author) } - end + form_new end - + def edit - @scroll_panel = ScrollPanel.edit(params[:id], @author) - respond_to do |format| - format.html - format.js - end + form_edit end - + def create - @scroll_panel = ScrollPanel.new - @scroll_panel.supply_default - @scroll_panel.attributes = params[:scroll_panel] - @scroll_panel.overwrite @author - @scroll = Scroll.edit(@scroll_panel.scroll_id, @author) if @scroll_panel.scroll_id - @panel = Panel.show(@scroll_panel.panel_id, @author) if @scroll_panel.panel_id + @my_model_class = self.class.model + @item = @my_model_class.new + @item.supply_default + @item.attributes = params[@item.item_name] + @item.overwrite @operators + @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id + @panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id - respond_to do |format| - if @scroll_panel.store - flash[:notice] = I18n.t('flash.notice.created', :model => ScrollPanel.model_name.human) - format.html { redirect_to play_scroll_path(@scroll) } - format.json { render json: @scroll_panel.scroll_panel_as_json(@author) } - else - flash[:notice] = I18n.t('flash.notice.not_created', :model => ScrollPanel.model_name.human) - format.html { render action: "new" } - format.json { render json: @scroll_panel.errors, status: :unprocessable_entity } - end - end + leaf_render_create play_scroll_path(@binder) end def update - @scroll_panel = ScrollPanel.edit(params[:id], @author) - ot = @scroll_panel.t - @scroll_panel.attributes = params[:scroll_panel] - @scroll_panel.overwrite @author - @scroll = Scroll.edit(@scroll_panel.scroll_id, @author) if @scroll_panel.scroll_id - respond_to do |format| - if @scroll_panel.store ot - flash[:notice] = I18n.t('flash.notice.updated', :model => ScrollPanel.model_name.human) - format.html { redirect_to play_scroll_path(@scroll) } - format.json { head :ok } - else - flash[:notice] = I18n.t('flash.notice.not_updated', :model => ScrollPanel.model_name.human) - format.html { render action: "edit" } - format.json { render json: @scroll_panel.errors, status: :unprocessable_entity } - end - end + @my_model_class = self.class.model + @item = @my_model_class.edit(params[:id], @operators) + ot = @item.t + @item.attributes = params[@item.item_name] + @item.overwrite @operators + @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id + # no check permission for destination + # swapable hidden panel + #@panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id + + leaf_render_update ot, play_scroll_path(@binder) end - + def destroy - @scroll_panel = ScrollPanel.edit(params[:id], @author) - @scroll = Scroll.edit(@scroll_panel.scroll_id, @author) if @scroll_panel.scroll_id + @scroll_panel = ScrollPanel.edit(params[:id], @operators) + @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id respond_to do |format| if @scroll_panel.destroy_and_shorten flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)