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|
19 @paginate = GroundColor.list_paginate(@page, @page_size)
21 format.json { render :json => @ground_colors.to_json(GroundColor.list_json_opt) }
26 @ground_color = GroundColor.show(params[:id], [@user, @admin])
27 respond_to do |format|
28 format.html # show.html.erb
29 format.json { render json: @ground_color.to_json(GroundColor.show_json_opt) }
34 @ground_color = GroundColor.new params[:ground_color]
35 @ground_color.supply_default
36 @panel = @author.working_panel
38 respond_to do |format|
40 format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) }
45 @ground_color = GroundColor.show(params[:id], @author)
46 @panel = Panel.edit(@ground_color.panel.id, @author)
48 respond_to do |format|
54 @ground_color = GroundColor.new params[:ground_color]
55 @ground_color.supply_default
56 @panel = Panel.edit(@author.working_panel, @author)
57 @ground_color.overwrite @panel.id
59 respond_to do |format|
60 if @ground_color.valid?
61 if @ground_color.store @author
62 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
63 format.html { redirect_to @panel }
64 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
66 format.html { render action: "panels/new" }
67 format.json { render json: @panel.errors, status: :unprocessable_entity }
70 format.html { render action: "new" }
71 format.json { render json: @ground_color.errors, status: :unprocessable_entity }
77 @ground_color = GroundColor.show(params[:id], @author)
78 @ground_color.attributes = params[:ground_color]
79 @panel = Panel.edit(@ground_color.panel.id, @author)
80 @ground_color.overwrite @panel.id
82 respond_to do |format|
83 if @ground_color.store @author
84 flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human)
85 format.html { redirect_to @ground_color }
86 format.json { head :ok }
88 format.html { render action: "edit" }
89 format.json { render json: @ground_color.errors, status: :unprocessable_entity }
95 @ground_color = GroundColor.show(params[:id], @author)
96 @panel = Panel.edit(@ground_color.panel.id, @author)
98 respond_to do |format|
99 if @ground_color.remove @author
100 flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human)
101 format.html { redirect_to @panel }
102 format.json { head :ok }
104 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human)
105 format.html { redirect_to @ground_color }
106 format.json { render json: @ground_color.errors, status: :unprocessable_entity }