1 class GroundPicturesController < ApplicationController
2 layout 'test' if MagicNumber['test_layout']
3 if MagicNumber['run_mode'] == 0
4 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
5 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
7 before_filter :authenticate_reader, :only => [:index, :show]
8 before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
9 before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
13 @page = GroundPicture.page params[:page]
14 @page_size = GroundPicture.page_size params[:page_size]
15 @ground_pictures = GroundPicture.list(@page, @page_size)
17 respond_to do |format|
19 @paginate = GroundPicture.list_paginate(@page, @page_size)
21 format.json { render :json => @ground_pictures.to_json(GroundPicture.list_json_opt) }
26 @ground_picture = GroundPicture.show(params[:id], [@user, @admin])
27 respond_to do |format|
28 format.html # show.html.erb
29 format.prof { render :template => 'top/prof', :layout => true }
30 format.json { render json: @ground_picture.to_json(GroundPicture.show_json_opt) }
35 raise Pettanr::NotWork unless @author.working_panel
36 @picture = Picture.show params[:picture_id], @author
37 raise ActiveRecord::Forbidden unless @picture.enable?
38 @panel = Panel.edit(@author.working_panel, @author)
40 @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
41 @ground_picture.supply_default
43 respond_to do |format|
45 format.json { render :json => @ground_picture.to_json(GroundPicture.show_json_opt) }
50 @ground_picture = GroundPicture.show(params[:id], @author)
51 @panel = Panel.edit(@ground_picture.panel.id, @author)
53 respond_to do |format|
59 raise Pettanr::NotWork unless @author.working_panel
60 @panel = Panel.edit(@author.working_panel, @author)
62 @ground_picture = GroundPicture.new
63 @ground_picture.attributes = params[:ground_picture]
64 @ground_picture.overwrite @panel.id
66 @picture = Picture.show @ground_picture.picture_id, @author
67 raise ActiveRecord::Forbidden unless @picture.enable?
69 respond_to do |format|
70 if @ground_picture.valid?
71 if @ground_picture.store @author
72 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
73 format.html { redirect_to @panel }
74 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
76 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
77 format.html { render action: "new" }
78 format.json { render json: @panel.errors, status: :unprocessable_entity }
81 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
82 format.html { render action: "new" }
83 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
89 @ground_picture = GroundPicture.show(params[:id], @author)
90 @ground_picture.attributes = params[:ground_picture]
91 @panel = Panel.edit(@ground_picture.panel.id, @author)
92 @ground_picture.overwrite @panel.id
94 @picture = Picture.show @ground_picture.picture_id, @author
95 raise ActiveRecord::Forbidden unless @picture.enable?
97 respond_to do |format|
98 if @ground_picture.store @author
99 flash[:notice] = I18n.t('flash.notice.updated', :model => GroundPicture.model_name.human)
100 format.html { redirect_to @ground_picture }
101 format.json { head :ok }
103 flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundPicture.model_name.human)
104 format.html { render action: "edit" }
105 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
111 @ground_picture = GroundPicture.show(params[:id], @author)
112 @panel = Panel.edit(@ground_picture.panel.id, @author)
114 respond_to do |format|
115 if @ground_picture.remove @author
116 flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundPicture.model_name.human)
117 format.html { redirect_to @panel }
118 format.json { head :ok }
120 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundPicture.model_name.human)
121 format.html { redirect_to @ground_picture }
122 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }