1 class GroundColorsController < 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 = GroundColor.page params[:page]
14 @page_size = GroundColor.page_size params[:page_size]
15 @ground_colors = GroundColor.list(@page, @page_size)
17 respond_to do |format|
18 format.html # index.html.erb
19 format.json { render :json => @ground_colors.to_json(GroundColor.list_json_opt) }
24 @ground_color = GroundColor.show(params[:id], [@user, @admin])
25 respond_to do |format|
26 format.html # show.html.erb
27 format.json { render json: @ground_color.to_json(GroundColor.show_json_opt) }
32 @ground_color = GroundColor.new params[:ground_color]
33 @ground_color.supply_default
34 @panel = @author.working_panel
36 respond_to do |format|
38 format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) }
43 @ground_color = GroundColor.show(params[:id], @author)
44 @panel = Panel.edit(@ground_color.panel.id, @author)
46 respond_to do |format|
52 @ground_color = GroundColor.new params[:ground_color]
53 @ground_color.supply_default
54 @panel = Panel.edit(@author.working_panel, @author)
55 @ground_color.overwrite @panel.id
57 respond_to do |format|
58 if @ground_color.valid?
59 if @ground_color.store @author
60 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
61 format.html { redirect_to @panel }
62 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
64 format.html { render action: "panels/new" }
65 format.json { render json: @panel.errors, status: :unprocessable_entity }
68 format.html { render action: "new" }
69 format.json { render json: @ground_color.errors, status: :unprocessable_entity }
75 @ground_color = GroundColor.show(params[:id], @author)
76 @ground_color.attributes = params[:ground_color]
77 @panel = Panel.edit(@ground_color.panel.id, @author)
78 @ground_color.overwrite @panel.id
80 respond_to do |format|
81 if @ground_color.store @author
82 flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human)
83 format.html { redirect_to @ground_color }
84 format.json { head :ok }
86 format.html { render action: "edit" }
87 format.json { render json: @ground_color.errors, status: :unprocessable_entity }
93 @ground_color = GroundColor.show(params[:id], @author)
94 @panel = Panel.edit(@ground_color.panel.id, @author)
96 respond_to do |format|
97 if @ground_color.remove @author
98 flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human)
99 format.html { redirect_to @panel }
100 format.json { head :ok }
102 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human)
103 format.html { redirect_to @ground_color }
104 format.json { render json: @ground_color.errors, status: :unprocessable_entity }