1 class ScrollsController < 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 => [:top, :index, :show, :play]
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 @@controller = Pettanr::Application::manifest.controller_managers[@@model.item_name]
15 @@profiler_manager = Pettanr::Application::manifest.profiler_managers[@@model.item_name]
18 action_name = params[:action]
19 @action = @@controller.open(action_name, params, @operators)
20 @items = @action.items
21 respond_to do |format|
23 @filer = @action.filer
24 render :template => 'system/filer', :locals => {
28 format.json { render json: @items.to_json(@@model.list_json_opt) }
35 @item = Scroll.show(params[:id], @operators)
37 respond_to do |format|
41 @new_panels = Panel.mylist(@operators.author, 1, 5)
44 format.json { render json: @item.to_json(Scroll.show_json_opt) }
46 @profiler = @@profiler_manager.open(@item, @operators)
47 render :template => 'system/prof', :locals => {
48 :profiler => @profiler
57 @scroll = Scroll.show(params[:id], [@user, @admin])
58 cnt = ScrollPanel.count(:conditions => ['scroll_id = ?', @scroll.id]).to_i
59 @offset = ScrollPanel.offset cnt, params[:offset]
60 @panel_count = ScrollPanel.panel_count cnt, params[:count]
61 @scroll_panels = ScrollPanel.play_list(@scroll, @author, @offset, @panel_count)
62 respond_to do |format|
64 @prev_offset = if @offset > 0
65 if @offset - @panel_count < 0
68 @offset - @panel_count
73 @next_offset = if @offset + @panel_count > cnt
76 @offset + @panel_count
79 @new_panels = Panel.mylist(@author, 1, 5)
82 format.json {render text: ScrollPanel.list_as_json_text(@scroll_panels, @author)}
84 render :json => "callback(" + @scroll_panels.to_json_list + ");"
90 @scroll = {:count => Scroll.visible_count}
91 respond_to do |format|
92 format.json { render json: @scroll.to_json }
99 respond_to do |format|
100 format.html { render layout: 'system' }# index.html.erb
101 format.json { render json: @scrolls }
106 @scroll = Scroll.find(params[:id])
108 respond_to do |format|
109 format.html { render layout: 'system' } # show.html.erb
110 format.json { render json: @scroll }
116 @scroll.supply_default
117 respond_to do |format|
118 format.html # new.html.erb
120 format.json { render json: @scroll.to_json(Scroll.show_json_opt) }
125 @scroll = Scroll.edit(params[:id], @author)
126 respond_to do |format|
134 @scroll.supply_default
135 @scroll.attributes = params[:scroll]
136 @scroll.overwrite @operators
138 respond_to do |format|
140 flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human)
141 format.html { redirect_to @scroll }
142 format.json { render json: @scroll.to_json(Scroll.show_json_opt), status: :created, location: @scroll }
144 flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
145 format.html { render action: "new" }
146 format.json { render json: @scroll.errors, status: :unprocessable_entity }
152 @scroll = Scroll.edit(params[:id], @author)
153 @scroll.attributes = params[:scroll]
154 @scroll.overwrite @author
155 respond_to do |format|
157 flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human)
158 format.html { redirect_to @scroll }
159 format.json { head :ok }
161 flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human)
162 format.html { render action: "edit" }
163 format.json { render json: @scroll.errors, status: :unprocessable_entity }
169 @scroll = Scroll.edit(params[:id], @author)
170 respond_to do |format|
171 if @scroll.destroy_with_scroll_panel
172 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human)
173 format.html { redirect_to '/home/scrolls' }
174 format.json { head :ok }
176 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Scroll.model_name.human)
177 format.html { redirect_to @scroll }
178 format.json { render json: @scroll.errors, status: :unprocessable_entity }