class PanelsController < ApplicationController
- before_filter :authenticate_author!, :except => [:index, :show]
-
- private
-
- def treat_param panel
- panel.author_id = current_author.id
+ layout 'test' if MagicNumber['test_layout']
+ if MagicNumber['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, :scroll_panels, :scrolls, :sheet_panels, :sheets, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors, :by_scroll, :by_sheet, :by_author]
+ before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
+ before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
end
- public
+ def self.model
+ Panel
+ end
- # GET /panels
- # GET /panels.json
def index
- @panels = Panel.all :order => 'updated_at'
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @panels }
- end
+ public_list
end
-
- # GET /panels/1
- # GET /panels/1.json
+
+ def scroll_panels
+ has_many_list
+ end
+
+ def scrolls
+ has_many_list
+ end
+
+ def sheet_panels
+ has_many_list
+ end
+
+ def sheets
+ has_many_list
+ end
+
+ def panel_pictures
+ has_many_list
+ end
+
+ def speech_balloons
+ has_many_list
+ end
+
+ def ground_pictures
+ has_many_list
+ end
+
+ def ground_colors
+ has_many_list
+ end
+
+ def by_scroll
+ filter_list
+ end
+
+ def by_sheet
+ filter_list
+ end
+
+ def by_author
+ filter_list
+ end
+
+
def show
- @panel = Panel.find(params[:id], include: [:comic, :panel_pictures => :resource_picture, :balloons => :speaches])# only: [:width, :height])
+ @item = Panel.show(params[:id], @operators)
respond_to do |format|
- format.html # show.html.erb
- format.json {
- render :json => @panel.to_json(include: {
- :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
- })
- }
- format.jsonp {
- render :json => "callback(" + @panel.to_json(include: {
- :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
- }) + ");"
+ format.html {
+ @panel = @item
+ if @operators.author
+ @new_scroll_items = assist_items('scroll', 'private_list')
+ @new_scroll_filer = assist_filer 'scroll', @new_scroll_items
+ @fresh_scroll_items = assist_items('scroll_panel', 'private_list').map {|sp| sp.scroll}
+ @fresh_scroll_filer = assist_filer 'scroll', @fresh_scroll_items
+
+ @new_sheet_items = assist_items('sheet', 'private_list')
+ @new_sheet_filer = assist_filer 'sheet', @new_sheet_items
+ @fresh_sheet_items = assist_items('sheet_panel', 'private_list').map {|sp| sp.sheet}
+ @fresh_sheet_filer = assist_filer 'sheet', @fresh_sheet_items
+ end
}
-# format.json { render :json => @frame.to_json(include: {
-# :comic => {:only => :title}, :panel_pictures => {:include => {:image => {:only => [:width]}},:only => [:width, :height, :z, :image_id]}
-# }, only: [:border]) }
- end
+ format_prof format
+ format.json { render json: @item.panel_elements_as_json }
+ end
end
- # GET /panels/new
- # GET /panels/new.json
+ def count
+ @panel = {:count => Panel.visible_count}
+ respond_to do |format|
+ format.json { render json: @panel.to_json }
+ end
+ end
+
def new
@panel = Panel.new
-
+ @panel.supply_default
respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @panel }
+ format.html {
+ @editor = Editor::Editor.new @panel, @operators
+ render :template => 'templates/r/editor/editor', :locals => {
+ :editor => @editor
+ }
+ }
+ format.js
+ format.json { render json: @panel.panel_elements_as_json }
end
end
- # GET /panels/1/edit
def edit
- @panel = Panel.find(params[:id])
+ @panel = Panel.edit(params[:id], @operators)
+ respond_to do |format|
+ format.html {
+ @editor = Editor::Editor.new @panel, @operators
+ render :template => 'templates/r/editor/editor', :locals => {
+ :editor => @editor
+ }
+ }
+ format.js
+ end
end
- # POST /panels
- # POST /panels.json
def create
- @panel = Panel.new(params[:panel])
- treat_param @panel
- @comic = Comic.find @panel.comic_id
-
+ @panel = Panel.new
+ @panel.supply_default
+ jsn = nil
+ if params[:json]
+ jsn = JSON.parse_no_except(params[:json])
+ end
+ @prm = params[:panel] || jsn
respond_to do |format|
- Panel.transaction do
- if @panel.vdt_save
- format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
- format.json { render json: @panel, status: :created, location: @panel }
- else
- format.html { render action: "new" }
- format.json { render json: @panel.errors, status: :unprocessable_entity }
- end
+ 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.json { render json: @panel.errors, status: :unprocessable_entity }
end
end
end
- # PUT /panels/1
- # PUT /panels/1.json
def update
- @panel = Panel.find(params[:id])
- if @panel.own? current_author
- respond_to do |format|
- Panel.transaction do
- if params[:panel][:t] and params[:panel][:t].to_i != @panel.t
- @panel.move_to params[:panel][:t].to_i
- end
- if @panel.update_attributes(params[:panel])
- format.html { redirect_to @panel, notice: 'Panel was successfully updated.' }
- format.json { head :ok }
- else
- format.html { render action: "edit" }
- format.json { render json: @panel.errors, status: :unprocessable_entity }
- end
- end
+ @panel = Panel.edit(params[:id], @operators)
+ jsn = nil
+ if params[:json]
+ jsn = JSON.parse(params[:json])
+ end
+ @prm = params[:panel] || jsn
+ respond_to do |format|
+ if @panel.store @prm, @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" }
+ format.json { render json: @panel.errors, status: :unprocessable_entity }
end
- else
- format.html { render action: "edit" }
- format.json { render json: @panel.errors, status: :unprocessable_entity }
end
end
- # DELETE /panels/1
- # DELETE /panels/1.json
def destroy
- @panel = Panel.find(params[:id])
- if @panel.own? current_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