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]
22 @item = Scroll.show(params[:id], @operators)
24 respond_to do |format|
28 @new_panels = Panel.mylist(@operators.author, 1, 5)
31 format.json { render json: @item.to_json(Scroll.show_json_opt) }
33 @profiler = @@profiler_manager.open(@item, @operators)
34 render :template => 'system/prof', :locals => {
35 :profiler => @profiler
44 @scroll = Scroll.show(params[:id], [@user, @admin])
45 cnt = ScrollPanel.count(:conditions => ['scroll_id = ?', @scroll.id]).to_i
46 @offset = ScrollPanel.offset cnt, params[:offset]
47 @panel_count = ScrollPanel.panel_count cnt, params[:count]
48 @scroll_panels = ScrollPanel.play_list(@scroll, @author, @offset, @panel_count)
49 respond_to do |format|
51 @prev_offset = if @offset > 0
52 if @offset - @panel_count < 0
55 @offset - @panel_count
60 @next_offset = if @offset + @panel_count > cnt
63 @offset + @panel_count
66 @new_panels = Panel.mylist(@author, 1, 5)
69 format.json {render text: ScrollPanel.list_as_json_text(@scroll_panels, @author)}
71 render :json => "callback(" + @scroll_panels.to_json_list + ");"
77 @scroll = {:count => Scroll.visible_count}
78 respond_to do |format|
79 format.json { render json: @scroll.to_json }
86 respond_to do |format|
87 format.html { render layout: 'system' }# index.html.erb
88 format.json { render json: @scrolls }
93 @scroll = Scroll.find(params[:id])
95 respond_to do |format|
96 format.html { render layout: 'system' } # show.html.erb
97 format.json { render json: @scroll }
103 @scroll.supply_default
104 respond_to do |format|
105 format.html # new.html.erb
107 format.json { render json: @scroll.to_json(Scroll.show_json_opt) }
112 @scroll = Scroll.edit(params[:id], @author)
113 respond_to do |format|
121 @scroll.supply_default
122 @scroll.attributes = params[:scroll]
123 @scroll.overwrite @operators
125 respond_to do |format|
127 flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human)
128 format.html { redirect_to @scroll }
129 format.json { render json: @scroll.to_json(Scroll.show_json_opt), status: :created, location: @scroll }
131 flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
132 format.html { render action: "new" }
133 format.json { render json: @scroll.errors, status: :unprocessable_entity }
139 @scroll = Scroll.edit(params[:id], @author)
140 @scroll.attributes = params[:scroll]
141 @scroll.overwrite @author
142 respond_to do |format|
144 flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human)
145 format.html { redirect_to @scroll }
146 format.json { head :ok }
148 flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human)
149 format.html { render action: "edit" }
150 format.json { render json: @scroll.errors, status: :unprocessable_entity }
156 @scroll = Scroll.edit(params[:id], @author)
157 respond_to do |format|
158 if @scroll.destroy_with_scroll_panel
159 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human)
160 format.html { redirect_to '/home/scrolls' }
161 format.json { head :ok }
163 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Scroll.model_name.human)
164 format.html { redirect_to @scroll }
165 format.json { render json: @scroll.errors, status: :unprocessable_entity }