1 class ScrollPanelsController < ApplicationController
2 layout 'test' if MagicNumber['test_layout']
3 if MagicNumber['run_mode'] == 0
4 before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
5 before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
7 before_filter :authenticate_reader, :only => [:index, :show, :scroll]
8 before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
9 before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
11 before_filter :authenticate_admin!, :only => [:list, :browse]
14 @page = ScrollPanel.page params[:page]
15 @page_size = ScrollPanel.page_size params[:page_size]
16 @scroll_panels = ScrollPanel.list(@page, @page_size)
18 respond_to do |format|
20 @paginate = ScrollPanel.list_paginate(@page, @page_size)
22 format.json { render :json => @scroll_panels.to_json(ScrollPanel.list_json_opt) }
27 @scroll_panel = ScrollPanel.show(params[:id], [@user, @admin])
29 respond_to do |format|
30 format.html # show.html.erb
31 format.json { render json: @scroll_panel.scroll_panel_as_json(@author) }
36 @scroll = Scroll.show(params[:id], [@user, @admin])
37 cnt = ScrollPanel.count(:conditions => ['scroll_id = ?', @scroll.id]).to_i
38 @offset = ScrollPanel.offset cnt, params[:offset]
39 @panel_count = ScrollPanel.panel_count cnt, params[:count]
40 @scroll_panels = ScrollPanel.play_list(@scroll, @author, @offset, @panel_count)
41 respond_to do |format|
43 @prev_offset = if @offset > 0
44 if @offset - @panel_count < 0
47 @offset - @panel_count
52 @next_offset = if @offset + @panel_count > cnt
55 @offset + @panel_count
58 @new_panels = Panel.mylist(@author, 1, 5)
61 format.json {render text: ScrollPanel.list_as_json_text(@scroll_panels, @author)}
63 render :json => "callback(" + @scroll_panels.to_json_list + ");"
69 @scroll_panels = ScrollPanel.all
71 respond_to do |format|
72 format.html { render layout: 'system' }# index.html.erb
73 format.json { render json: @scroll_panels }
78 @scroll_panel = ScrollPanel.find(params[:id])
80 respond_to do |format|
81 format.html { render layout: 'system' } # show.html.erb
82 format.json { render json: @scroll_panel }
87 @scroll_panel = ScrollPanel.new
88 @scroll_panel.supply_default
89 respond_to do |format|
90 format.html # new.html.erb
92 format.json { render json: @scroll_panel.scroll_panel_as_json(@author) }
97 @scroll_panel = ScrollPanel.edit(params[:id], @author)
98 respond_to do |format|
105 @scroll_panel = ScrollPanel.new
106 @scroll_panel.supply_default
107 @scroll_panel.attributes = params[:scroll_panel]
108 @scroll_panel.overwrite @author
109 @scroll = Scroll.edit(@scroll_panel.scroll_id, @author) if @scroll_panel.scroll_id
110 @panel = Panel.show(@scroll_panel.panel_id, @author) if @scroll_panel.panel_id
112 respond_to do |format|
113 if @scroll_panel.store
114 flash[:notice] = I18n.t('flash.notice.created', :model => ScrollPanel.model_name.human)
115 format.html { redirect_to action: :scroll, id: @scroll_panel.scroll_id }
116 format.json { render json: @scroll_panel.scroll_panel_as_json(@author) }
118 flash[:notice] = I18n.t('flash.notice.not_created', :model => ScrollPanel.model_name.human)
119 format.html { render action: "new" }
120 format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
126 @scroll_panel = ScrollPanel.edit(params[:id], @author)
128 @scroll_panel.attributes = params[:scroll_panel]
129 @scroll_panel.overwrite @author
130 respond_to do |format|
131 if @scroll_panel.store ot
132 flash[:notice] = I18n.t('flash.notice.updated', :model => ScrollPanel.model_name.human)
133 format.html { redirect_to action: :scroll, id: @scroll_panel.scroll_id }
134 format.json { head :ok }
136 flash[:notice] = I18n.t('flash.notice.not_updated', :model => ScrollPanel.model_name.human)
137 format.html { render action: "edit" }
138 format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
144 @scroll_panel = ScrollPanel.edit(params[:id], @author)
145 respond_to do |format|
146 if @scroll_panel.destroy_and_shorten
147 flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)
148 format.html { redirect_to :controller => 'scroll_panels', :action => :scroll, :id => @scroll_panel.scroll_id }
149 format.json { head :ok }
151 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ScrollPanel.model_name.human)
152 format.html { redirect_to scroll_panel_path(@scroll_panel) }
153 format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }