1 class PanelPicturesController < 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]
11 before_filter :authenticate_admin!, :only => [:list, :browse]
14 @page = PanelPicture.page params[:page]
15 @page_size = PanelPicture.page_size params[:page_size]
16 @panel_pictures = PanelPicture.list(@page, @page_size)
18 respond_to do |format|
20 @paginate = PanelPicture.list_paginate(@page, @page_size)
21 render :template => 'system/filer', :locals => {
22 :items => @panel_pictures, :model => PanelPicture,
23 :roles => [@user, @admin], :pager => @paginate
26 format.json { render :json => @panel_pictures.to_json(PanelPicture.list_json_opt) }
31 @item = PanelPicture.show(params[:id], [@user, @admin])
33 respond_to do |format|
36 format.json { render :json => @item.to_json(PanelPicture.show_json_opt) }
41 @panel_pictures = PanelPicture.all
43 respond_to do |format|
44 format.html { render layout: 'system' }
45 format.json { render json: @panel_pictures }
50 @panel_picture = PanelPicture.find(params[:id])
52 respond_to do |format|
53 format.html { render layout: 'system' }
54 format.json { render json: @panel_picture}
59 raise Pettanr::NotWork unless @author.working_panel
60 @picture = Picture.show params[:picture_id], @author
61 raise ActiveRecord::Forbidden unless @picture.enable?
62 @panel = Panel.edit(@author.working_panel, @author)
64 @panel_picture = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
65 @panel_picture.supply_default
67 respond_to do |format|
69 format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
74 @panel_picture = PanelPicture.show(params[:id], @author)
75 @panel = Panel.edit(@panel_picture.panel.id, @author)
77 respond_to do |format|
83 raise Pettanr::NotWork unless @author.working_panel
84 @panel = Panel.edit(@author.working_panel, @author)
86 @panel_picture = PanelPicture.new
87 @panel_picture.attributes = params[:panel_picture]
88 @panel_picture.overwrite @panel.id
90 @picture = Picture.show @panel_picture.picture_id, @author
91 raise ActiveRecord::Forbidden unless @picture.enable?
93 respond_to do |format|
94 if @panel_picture.valid?
95 if @panel_picture.store @author
96 flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
97 format.html { redirect_to @panel }
98 format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
100 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
101 format.html { render action: "new" }
102 format.json { render json: @panel.errors, status: :unprocessable_entity }
105 flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
106 format.html { render action: "new" }
107 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
113 @panel_picture = PanelPicture.show(params[:id], @author)
114 @panel_picture.attributes = params[:panel_picture]
115 @panel = Panel.edit(@panel_picture.panel.id, @author)
116 @panel_picture.overwrite @panel.id
118 @picture = Picture.show @panel_picture.picture_id, @author
119 raise ActiveRecord::Forbidden unless @picture.enable?
121 respond_to do |format|
122 if @panel_picture.store @author
123 flash[:notice] = I18n.t('flash.notice.updated', :model => PanelPicture.model_name.human)
124 format.html { redirect_to @panel_picture }
125 format.json { head :ok }
127 flash[:notice] = I18n.t('flash.notice.not_updated', :model => PanelPicture.model_name.human)
128 format.html { render action: "edit" }
129 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }
135 @panel_picture = PanelPicture.show(params[:id], @author)
136 @panel = Panel.edit(@panel_picture.panel.id, @author)
138 respond_to do |format|
139 if @panel_picture.remove @author
140 flash[:notice] = I18n.t('flash.notice.destroyed', :model => PanelPicture.model_name.human)
141 format.html { redirect_to @panel }
142 format.json { head :ok }
144 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => PanelPicture.model_name.human)
145 format.html { redirect_to @panel_picture }
146 format.json { render json: @panel_picture.errors, status: :unprocessable_entity }