OSDN Git Service

test sb extend data
[pettanr/pettanr.git] / app / controllers / speech_balloons_controller.rb
1 class SpeechBalloonsController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
4     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
5   else
6     before_filter :authenticate_reader, :only => [
7       :index, :show, :by_panel, :by_author, :count, :count_by_panel, :count_by_author
8     ]
9     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
10     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
11   end
12
13   def self.model
14     SpeechBalloon
15   end
16   
17   def index
18     filer_list
19   end
20   
21   def by_panel
22     filer_list
23   end
24   
25   def by_author
26     filer_list
27   end
28   
29   def show_html_format format
30     format.html {
31       @item.boosts 'post'
32       @speech_balloon = @item
33     }
34   end
35   
36   def show
37     set_show
38     respond_to do |format|
39       show_html_format format
40       show_prof_format format
41       show_json_format format
42     end
43   end
44   
45   def count
46     list_count
47   end
48   
49   def count_by_panel
50     list_count
51   end
52   
53   def count_by_author
54     list_count
55   end
56   
57   def new
58     form_new
59   end
60   
61   def edit
62     form_edit
63   end
64   
65   def create
66     raise Pettanr::NotWork unless @operators.author.working_panel
67     SpeechBalloon.fold_extend_settings params
68     @panel = Panel.edit(@operators.author.working_panel, @operators)
69     @speech_balloon = SpeechBalloon.new 
70     @speech_balloon.attributes = params[:speech_balloon]
71     
72     @speech_balloon_template = @speech_balloon.speech_balloon_template
73     @speech_balloon.boost
74     
75     params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture 
76     
77     @speech_balloon.overwrite @panel.id
78     
79     respond_to do |format|
80       if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon])
81         flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
82         format.html { redirect_to @panel }
83         format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
84       else
85         flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
86         format.html {
87           render @speech_balloon_template.engine_name + '/speech_balloons/new'
88         }
89         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
90       end
91     end
92   end
93
94   def update
95     SpeechBalloon.fold_extend_settings params
96     @speech_balloon = SpeechBalloon.show(params[:id], @operators)
97     @speech_balloon.attributes = params[:speech_balloon]
98     
99     @speech_balloon_template = @speech_balloon.speech_balloon_template
100     @speech_balloon.boost
101     
102     params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture 
103     
104     @panel = Panel.edit(@speech_balloon.panel.id, @operators)
105     @speech_balloon.overwrite @panel.id
106     
107     respond_to do |format|
108       if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon])
109         flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
110         format.html { redirect_to @speech_balloon }
111         format.json { head :ok }
112       else
113         flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
114         format.html {
115           render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
116         }
117         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
118       end
119     end
120   end
121
122   def destroy
123     @speech_balloon = SpeechBalloon.show(params[:id], @operators)
124     @panel = Panel.edit(@speech_balloon.panel.id, @operators)
125     
126     respond_to do |format|
127       if @speech_balloon.remove @operators.author
128         flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
129         format.html { redirect_to @panel }
130         format.json { head :ok }
131       else
132         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
133         format.html { redirect_to @speech_balloon }
134         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
135       end
136     end
137   end
138   
139 end