OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[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, :by_speech_balloon_template, :count, :count_by_panel, :count_by_author, :count_by_speech_balloon_template
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 by_speech_balloon_template
30     filer_list
31   end
32   
33   def show_html_format format
34     format.html {
35       @item.boosts 'post'
36       @speech_balloon = @item
37     }
38   end
39   
40   def show
41     set_show
42     respond_to do |format|
43       show_html_format format
44       show_prof_format format
45       show_json_format format
46     end
47   end
48   
49   def count
50     list_count
51   end
52   
53   def count_by_panel
54     list_count
55   end
56   
57   def count_by_author
58     list_count
59   end
60   
61   def count_by_speech_balloon_template
62     list_count
63   end
64   
65   def new
66     form_new
67   end
68   
69   def edit
70     form_edit
71   end
72   
73   def create
74     raise Pettanr::NotWork unless @operators.author.working_panel
75     SpeechBalloon.fold_extend_settings params
76     @panel = Panel.edit(@operators.author.working_panel, @operators)
77     @speech_balloon = SpeechBalloon.new 
78     @speech_balloon.attributes = params[:speech_balloon]
79     
80     @speech_balloon_template = @speech_balloon.speech_balloon_template
81     @speech_balloon.boost
82     
83     params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.get_balloon.select_system_picture 
84     
85     @speech_balloon.overwrite @panel.id
86     
87     respond_to do |format|
88       if @speech_balloon.valid? and @speech_balloon.store(@operators, params[:speech_balloon])
89         flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
90         format.html { redirect_to @panel }
91         format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
92       else
93         flash[:notice] = I18n.t('flash.notice.not_created', :model => SpeechBalloon.model_name.human)
94         format.html {
95           render @speech_balloon_template.engine_name + '/speech_balloons/new'
96         }
97         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
98       end
99     end
100   end
101
102   def update
103     @item = SpeechBalloon.show(params[:id], @operators)
104     @speech_balloon = @item
105     @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
106     @form.fold_extend_settings params
107     @speech_balloon.attributes = params[:speech_balloon]
108     
109     @speech_balloon_template = @speech_balloon.speech_balloon_template
110     
111     params[:speech_balloon][:balloon_attributes][:system_picture_id] = @speech_balloon.balloon.select_system_picture 
112     
113     @panel = Panel.edit(@speech_balloon.panel.id, @operators)
114     @speech_balloon.overwrite @panel.id
115     
116     respond_to do |format|
117       if @speech_balloon.save
118         flash[:notice] = I18n.t('flash.notice.updated', :model => SpeechBalloon.model_name.human)
119         format.html { redirect_to @speech_balloon }
120         format.json { head :ok }
121       else
122         flash[:notice] = I18n.t('flash.notice.not_updated', :model => SpeechBalloon.model_name.human)
123         format.html {
124           render @speech_balloon.speech_balloon_template.engine_name + '/speech_balloons/edit'
125         }
126         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
127       end
128     end
129   end
130
131   def destroy
132     @speech_balloon = SpeechBalloon.show(params[:id], @operators)
133     @panel = Panel.edit(@speech_balloon.panel.id, @operators)
134     
135     respond_to do |format|
136       if @speech_balloon.remove @operators.author
137         flash[:notice] = I18n.t('flash.notice.destroyed', :model => SpeechBalloon.model_name.human)
138         format.html { redirect_to @panel }
139         format.json { head :ok }
140       else
141         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SpeechBalloon.model_name.human)
142         format.html { redirect_to @speech_balloon }
143         format.json { render json: @speech_balloon.errors, status: :unprocessable_entity }
144       end
145     end
146   end
147   
148 end