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 @item = GroundPicture.show(params[:id], [@user, @admin])
31 respond_to do |format|
33 @ground_picture = @item
36 format.json { render json: @item.to_json(GroundPicture.show_json_opt) }
41 raise Pettanr::NotWork unless @author.working_panel
42 @picture = Picture.show params[:picture_id], @author
43 raise ActiveRecord::Forbidden unless @picture.enable?
44 @panel = Panel.edit(@author.working_panel, @author)
46 @ground_picture = GroundPicture.new :panel_id => @panel.id, :picture_id => @picture.id
47 @ground_picture.supply_default
49 respond_to do |format|
51 format.json { render :json => @ground_picture.to_json(GroundPicture.show_json_opt) }
56 @ground_picture = GroundPicture.show(params[:id], @author)
57 @panel = Panel.edit(@ground_picture.panel.id, @author)
59 respond_to do |format|
65 raise Pettanr::NotWork unless @author.working_panel
66 @panel = Panel.edit(@author.working_panel, @author)
68 @ground_picture = GroundPicture.new
69 @ground_picture.attributes = params[:ground_picture]
70 @ground_picture.overwrite @panel.id
72 @picture = Picture.show @ground_picture.picture_id, @author
73 raise ActiveRecord::Forbidden unless @picture.enable?
75 respond_to do |format|
76 if @ground_picture.valid?
77 if @ground_picture.store @author
78 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
79 format.html { redirect_to @panel }
80 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
82 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
83 format.html { render action: "new" }
84 format.json { render json: @panel.errors, status: :unprocessable_entity }
87 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundPicture.model_name.human)
88 format.html { render action: "new" }
89 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
95 @ground_picture = GroundPicture.show(params[:id], @author)
96 @ground_picture.attributes = params[:ground_picture]
97 @panel = Panel.edit(@ground_picture.panel.id, @author)
98 @ground_picture.overwrite @panel.id
100 @picture = Picture.show @ground_picture.picture_id, @author
101 raise ActiveRecord::Forbidden unless @picture.enable?
103 respond_to do |format|
104 if @ground_picture.store @author
105 flash[:notice] = I18n.t('flash.notice.updated', :model => GroundPicture.model_name.human)
106 format.html { redirect_to @ground_picture }
107 format.json { head :ok }
109 flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundPicture.model_name.human)
110 format.html { render action: "edit" }
111 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }
117 @ground_picture = GroundPicture.show(params[:id], @author)
118 @panel = Panel.edit(@ground_picture.panel.id, @author)
120 respond_to do |format|
121 if @ground_picture.remove @author
122 flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundPicture.model_name.human)
123 format.html { redirect_to @panel }
124 format.json { head :ok }
126 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundPicture.model_name.human)
127 format.html { redirect_to @ground_picture }
128 format.json { render json: @ground_picture.errors, status: :unprocessable_entity }