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)
20 render :template => 'system/filer', :locals => {
21 :items => @ground_colors, :model => GroundColor,
22 :roles => [@user, @admin], :pager => @paginate
25 format.json { render :json => @ground_colors.to_json(GroundColor.list_json_opt) }
30 @item = GroundColor.show(params[:id], [@user, @admin])
31 respond_to do |format|
36 format.json { render json: @item.to_json(GroundColor.show_json_opt) }
41 raise Pettanr::NotWork unless @author.working_panel
42 @panel = Panel.edit(@author.working_panel, @author)
43 @ground_color = GroundColor.new :panel_id => @panel.id, :code => params[:code].to_i
44 @ground_color.supply_default
46 respond_to do |format|
48 format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) }
53 @ground_color = GroundColor.show(params[:id], @author)
54 @panel = Panel.edit(@ground_color.panel.id, @author)
56 respond_to do |format|
62 raise Pettanr::NotWork unless @author.working_panel
63 @panel = Panel.edit(@author.working_panel, @author)
65 @ground_color = GroundColor.new
66 @ground_color.attributes = params[:ground_color]
67 @ground_color.overwrite @panel.id
69 respond_to do |format|
70 if @ground_color.valid?
71 if @ground_color.store @author
72 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
73 format.html { redirect_to @panel }
74 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
76 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
77 format.html { render action: "new" }
78 format.json { render json: @ground_color.errors, status: :unprocessable_entity }
81 flash[:notice] = I18n.t('flash.notice.not_created', :model => GroundColor.model_name.human)
82 format.html { render action: "new" }
83 format.json { render json: @ground_color.errors, status: :unprocessable_entity }
89 @ground_color = GroundColor.show(params[:id], @author)
90 @ground_color.attributes = params[:ground_color]
91 @panel = Panel.edit(@ground_color.panel.id, @author)
92 @ground_color.overwrite @panel.id
94 respond_to do |format|
95 if @ground_color.store @author
96 flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human)
97 format.html { redirect_to @ground_color }
98 format.json { head :ok }
100 flash[:notice] = I18n.t('flash.notice.not_updated', :model => GroundColor.model_name.human)
101 format.html { render action: "edit" }
102 format.json { render json: @ground_color.errors, status: :unprocessable_entity }
108 @ground_color = GroundColor.show(params[:id], @author)
109 @panel = Panel.edit(@ground_color.panel.id, @author)
111 respond_to do |format|
112 if @ground_color.remove @author
113 flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human)
114 format.html { redirect_to @panel }
115 format.json { head :ok }
117 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human)
118 format.html { redirect_to @ground_color }
119 format.json { render json: @ground_color.errors, status: :unprocessable_entity }