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) }
39 @scroll = Scroll.show(params[:id], [@user, @admin])
40 cnt = ScrollPanel.count(:conditions => ['scroll_id = ?', @scroll.id]).to_i
41 @offset = ScrollPanel.offset cnt, params[:offset]
42 @panel_count = ScrollPanel.panel_count cnt, params[:count]
43 @scroll_panels = ScrollPanel.play_list(@scroll, @author, @offset, @panel_count)
44 respond_to do |format|
46 @prev_offset = if @offset > 0
47 if @offset - @panel_count < 0
50 @offset - @panel_count
55 @next_offset = if @offset + @panel_count > cnt
58 @offset + @panel_count
61 @new_panels = Panel.mylist(@author, 1, 5)
64 format.json {render text: ScrollPanel.list_as_json_text(@scroll_panels, @author)}
66 render :json => "callback(" + @scroll_panels.to_json_list + ");"
72 @scroll = {:count => Scroll.visible_count}
73 respond_to do |format|
74 format.json { render json: @scroll.to_json }
81 respond_to do |format|
82 format.html { render layout: 'system' }# index.html.erb
83 format.json { render json: @scrolls }
88 @scroll = Scroll.find(params[:id])
90 respond_to do |format|
91 format.html { render layout: 'system' } # show.html.erb
92 format.json { render json: @scroll }
98 @scroll.supply_default
99 respond_to do |format|
100 format.html # new.html.erb
102 format.json { render json: @scroll.to_json(Scroll.show_json_opt) }
107 @scroll = Scroll.edit(params[:id], @author)
108 respond_to do |format|
116 @scroll.supply_default
117 @scroll.attributes = params[:scroll]
118 @scroll.overwrite @operators
120 respond_to do |format|
122 flash[:notice] = I18n.t('flash.notice.created', :model => Scroll.model_name.human)
123 format.html { redirect_to @scroll }
124 format.json { render json: @scroll.to_json(Scroll.show_json_opt), status: :created, location: @scroll }
126 flash[:notice] = I18n.t('flash.notice.not_created', :model => Scroll.model_name.human)
127 format.html { render action: "new" }
128 format.json { render json: @scroll.errors, status: :unprocessable_entity }
134 @scroll = Scroll.edit(params[:id], @author)
135 @scroll.attributes = params[:scroll]
136 @scroll.overwrite @author
137 respond_to do |format|
139 flash[:notice] = I18n.t('flash.notice.updated', :model => Scroll.model_name.human)
140 format.html { redirect_to @scroll }
141 format.json { head :ok }
143 flash[:notice] = I18n.t('flash.notice.not_updated', :model => Scroll.model_name.human)
144 format.html { render action: "edit" }
145 format.json { render json: @scroll.errors, status: :unprocessable_entity }
151 @scroll = Scroll.edit(params[:id], @author)
152 respond_to do |format|
153 if @scroll.destroy_with_scroll_panel
154 flash[:notice] = I18n.t('flash.notice.destroyed', :model => Scroll.model_name.human)
155 format.html { redirect_to '/home/scrolls' }
156 format.json { head :ok }
158 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Scroll.model_name.human)
159 format.html { redirect_to @scroll }
160 format.json { render json: @scroll.errors, status: :unprocessable_entity }