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)
20 render :template => 'system/filer', :locals => {
21 :items => @ground_pictures, :model => GroundPicture,
22 :roles => [@user, @admin], :pager => @paginate
25 format.json { render :json => @ground_pictures.to_json(GroundPicture.list_json_opt) }
30 @ground_picture = GroundPicture.show(params[:id], [@user, @admin])
31 respond_to do |format|
32 format.html # show.html.erb
33 format.prof { render :template => 'top/prof', :layout => true }
34 format.json { render json: @ground_picture.to_json(GroundPicture.show_json_opt) }
39 raise Pettanr::NotWork unless @author.working_panel
40 @picture = Picture.show params[:picture_id], @author
41 raise ActiveRecord::Forbidden unless @picture.enable?
42 @panel = Panel.edit(@author.working_panel, @author)
44 @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
45 @ground_picture.supply_default
47 respond_to do |format|
49 format.json { render :json => @ground_picture.to_json(GroundPicture.show_json_opt) }
54 @ground_picture = GroundPicture.show(params[:id], @author)
55 @panel = Panel.edit(@ground_picture.panel.id, @author)
57 respond_to do |format|
63 raise Pettanr::NotWork unless @author.working_panel
64 @panel = Panel.edit(@author.working_panel, @author)
66 @ground_picture = GroundPicture.new
67 @ground_picture.attributes = params[:ground_picture]
68 @ground_picture.overwrite @panel.id
70 @picture = Picture.show @ground_picture.picture_id, @author
71 raise ActiveRecord::Forbidden unless @picture.enable?
73 respond_to do |format|
74 if @ground_picture.valid?
75 if @ground_picture.store @author
76 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
77 format.html { redirect_to @panel }
78 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
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: @panel.errors, status: :unprocessable_entity }
85 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
86 format.html { render action: "new" }
87 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
93 @ground_picture = GroundPicture.show(params[:id], @author)
94 @ground_picture.attributes = params[:ground_picture]
95 @panel = Panel.edit(@ground_picture.panel.id, @author)
96 @ground_picture.overwrite @panel.id
98 @picture = Picture.show @ground_picture.picture_id, @author
99 raise ActiveRecord::Forbidden unless @picture.enable?
101 respond_to do |format|
102 if @ground_picture.store @author
103 flash[:notice] = I18n.t('flash.notice.updated', :model => GroundPicture.model_name.human)
104 format.html { redirect_to @ground_picture }
105 format.json { head :ok }
107 flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundPicture.model_name.human)
108 format.html { render action: "edit" }
109 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
115 @ground_picture = GroundPicture.show(params[:id], @author)
116 @panel = Panel.edit(@ground_picture.panel.id, @author)
118 respond_to do |format|
119 if @ground_picture.remove @author
120 flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundPicture.model_name.human)
121 format.html { redirect_to @panel }
122 format.json { head :ok }
124 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundPicture.model_name.human)
125 format.html { redirect_to @ground_picture }
126 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }