class PanelsController < ApplicationController
- layout 'test' if Pettanr::TestLayout
- before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
- before_filter :authenticate_admin!, :only => [:list, :browse]
-
- public
+ if Manifest.manifest.magic_numbers['run_mode'] == 0
+ before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
+ before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
+ else
+ before_filter :authenticate_reader, :only => [
+ :index, :show, :by_scroll, :by_sheet, :by_author, :by_speech_balloon_template, :count, :count_by_scroll, :count_by_sheet, :count_by_author, :count_by_speech_balloon_template
+ ]
+ before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
+ before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
+ end
+
+ def self.model
+ Panel
+ end
- # GET /panels
- # GET /panels.json
def index
- @page = Panel.page params[:page]
- @page_size = Panel.page_size params[:page_size]
- @panels = Panel.list({}, @page, @page_size)
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @panels.to_json(Panel.list_json_opt) }
- end
+ filer_list
end
-
- # GET /panels/1
- # GET /panels/1.json
+
+ def by_scroll
+ filer_list
+ end
+
+ def by_sheet
+ filer_list
+ end
+
+ def by_author
+ filer_list
+ end
+
+ def by_speech_balloon_template
+ filer_list
+ end
+
+ def show_html_format format
+ format.html {
+ @panel = @item
+ if @operators.author
+ @new_scroll_items = assist_items('scroll', 'private')
+ #@new_scroll_filer = assist_filer 'scroll', @new_scroll_items
+ @fresh_scroll_items = assist_items('scroll_panel', 'private').map {|sp| sp.scroll}
+ #@fresh_scroll_filer = assist_filer 'scroll', @fresh_scroll_items
+
+ @new_sheet_items = assist_items('sheet', 'private')
+ #@new_sheet_filer = assist_filer 'sheet', @new_sheet_items
+ @fresh_sheet_items = assist_items('sheet_panel', 'private').map {|sp| sp.sheet}
+ #@fresh_sheet_filer = assist_filer 'sheet', @fresh_sheet_items
+ end
+ }
+ end
+
def show
- @panel = Panel.show(params[:id], @author)
-
+ set_show
respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @panel.to_json(Panel.show_json_include_opt) }
- format.jsonp {
- render :json => "callback(" + @panel.to_json(Panel.show_json_include_opt) + ");"
- }
+ show_html_format format
+ show_prof_format format
+ show_json_format format
end
end
def count
- @panel = {:count => Panel.visible_count}
- respond_to do |format|
- format.json { render json: @panel.to_json }
- end
+ list_count
end
- def list
- @panels = Panel.all :order => 'updated_at'
-
- respond_to do |format|
- format.html { render layout: 'system' }
- format.json { render json: @panels }
- end
+ def count_by_scroll
+ list_count
end
-
- def browse
- @panel = Panel.find(params[:id])
-
- respond_to do |format|
- format.html { render layout: 'system' }
- end
+
+ def count_by_sheet
+ list_count
end
-
+
+ def count_by_author
+ list_count
+ end
+
+ def count_by_speech_balloon_template
+ list_count
+ end
+
def new
@panel = Panel.new
+ @panel.boosts 'post'
@panel.supply_default
-
respond_to do |format|
- format.html # new.html.erb
+ format.html {
+ @editor = Editor::PanelEditor.new @panel, @operators
+ render :template => @editor.template_name, :locals => {
+ :editor => @editor
+ }
+ }
format.js
- format.json { render json: @panel }
+ format.json { render json: @panel.panel_elements_as_json }
end
end
def edit
- @panel = Panel.show(params[:id], @author)
+ @panel = Panel.edit(params[:id], @operators)
respond_to do |format|
- format.html
+ format.html {
+ @editor = Editor::PanelEditor.new @panel, @operators
+ render :template => @editor.template_name, :locals => {
+ :editor => @editor
+ }
+ }
format.js
end
end
- # POST /panels
- # POST /panels.json
def create
@panel = Panel.new
- @panel.supply_default
+# @panel.boosts 'post'
+ jsn = nil
if params[:json]
- jsn = JSON.parse(params[:json])
+ jsn = JSON.parse_no_except(params[:json])
end
- @prm = params[:panel] || jsn
- @panel.attributes = @prm
- @panel.overwrite @author
+ @prm = if params[:panel] == nil or params[:panel].empty?
+ jsn
+ else
+ params[:panel]
+ end
+ @panel.class.fold_extend_settings @prm
+ #@panel.refresh
respond_to do |format|
- if @panel.store
- format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
- format.json { render json: @panel, status: :created, location: @panel }
+ if @panel.store @prm, @operators
+ flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
+ format.html { redirect_to @panel }
+ format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
else
- format.html { render action: "new" }
+ format.html {
+ @editor = Editor::PanelEditor.new @panel, @operators
+ render :template => @editor.template_name, :locals => {
+ :editor => @editor
+ }
+ }
format.json { render json: @panel.errors, status: :unprocessable_entity }
end
end
end
- # PUT /panels/1
- # PUT /panels/1.json
def update
- @panel = Panel.show(params[:id], @author)
+ @panel = Panel.edit(params[:id], @operators)
+ @panel.boost
+ jsn = nil
if params[:json]
jsn = JSON.parse(params[:json])
end
@prm = params[:panel] || jsn
+ self.model.fold_extend_settings @prm
@panel.attributes = @prm
- @panel.overwrite @author
+ @panel.refresh
respond_to do |format|
- if @panel.store
- format.html { redirect_to @panel, notice: 'Panel was successfully updated.' }
+ if @panel.store @panel.packed_attributes, @operators
+ flash[:notice] = I18n.t('flash.notice.updated', :model => Panel.model_name.human)
+ format.html { redirect_to @panel }
format.json { head :ok }
else
format.html { render action: "edit" }
end
end
- # DELETE /panels/1
- # DELETE /panels/1.json
def destroy
- @panel = Panel.find(params[:id])
- if @panel.own? @author
- respond_to do |format|
- Panel.transaction do
- @panel.destroy_and_shorten
- format.html { redirect_to panels_url }
- format.json { head :ok }
- end
- end
- else
- format.html { render action: "edit" }
- format.json { render json: @panel.errors, status: :unprocessable_entity }
- end
- end
-
- def move
- @panel = Panel.find(params[:id])
- @new_seq = params[:panel][:t].to_i
+ @panel = Panel.edit(params[:id], @operators)
respond_to do |format|
Panel.transaction do
- if @panel.move_to(@new_t)
- format.html { redirect_to @panel, notice: 'Panel was successfully moved.' }
+ if @panel.destroy_with_elements
+ flash[:notice] = I18n.t('flash.notice.destroyed', :model => Panel.model_name.human)
+ format.html { redirect_to '/home/panels' }
format.json { head :ok }
else
- format.html { render action: "show" }
+ flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Panel.model_name.human)
+ format.html { redirect_to @panel }
format.json { render json: @panel.errors, status: :unprocessable_entity }
end
end
end
end
+ def catch
+ @panel = Panel.edit(params[:id], @operators)
+
+ respond_to do |format|
+ @operators.author.working_panel_id = @panel.id
+ if @operators.author.save
+ format.html { redirect_to @panel }
+ else
+ end
+ end
+ end
+
end