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.json { render json: @ground_picture.to_json(GroundPicture.show_json_opt) }
34 raise Pettanr::NotWork unless @author.working_panel
35 @picture = Picture.show params[:picture_id], @author
36 raise ActiveRecord::Forbidden unless @picture.enable?
37 @panel = Panel.edit(@author.working_panel, @author)
39 @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
40 @ground_picture.supply_default
42 respond_to do |format|
44 format.json { render :json => @ground_picture.to_json(GroundPicture.show_json_opt) }
49 @ground_picture = GroundPicture.show(params[:id], @author)
50 @panel = Panel.edit(@ground_picture.panel.id, @author)
52 respond_to do |format|
58 raise Pettanr::NotWork unless @author.working_panel
59 @panel = Panel.edit(@author.working_panel, @author)
61 @ground_picture = GroundPicture.new
62 @ground_picture.attributes = params[:ground_picture]
63 @ground_picture.overwrite @panel.id
65 @picture = Picture.show @ground_picture.picture_id, @author
66 raise ActiveRecord::Forbidden unless @picture.enable?
68 respond_to do |format|
69 if @ground_picture.valid?
70 if @ground_picture.store @author
71 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
72 format.html { redirect_to @panel }
73 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
75 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
76 format.html { render action: "new" }
77 format.json { render json: @panel.errors, status: :unprocessable_entity }
80 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
81 format.html { render action: "new" }
82 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
88 @ground_picture = GroundPicture.show(params[:id], @author)
89 @ground_picture.attributes = params[:ground_picture]
90 @panel = Panel.edit(@ground_picture.panel.id, @author)
91 @ground_picture.overwrite @panel.id
93 @picture = Picture.show @ground_picture.picture_id, @author
94 raise ActiveRecord::Forbidden unless @picture.enable?
96 respond_to do |format|
97 if @ground_picture.store @author
98 flash[:notice] = I18n.t('flash.notice.updated', :model => GroundPicture.model_name.human)
99 format.html { redirect_to @ground_picture }
100 format.json { head :ok }
102 flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundPicture.model_name.human)
103 format.html { render action: "edit" }
104 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
110 @ground_picture = GroundPicture.show(params[:id], @author)
111 @panel = Panel.edit(@ground_picture.panel.id, @author)
113 respond_to do |format|
114 if @ground_picture.remove @author
115 flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundPicture.model_name.human)
116 format.html { redirect_to @panel }
117 format.json { head :ok }
119 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundPicture.model_name.human)
120 format.html { redirect_to @ground_picture }
121 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }