OSDN Git Service

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