#フキダシテンプレート
class SpeechBalloonTemplate < ActiveRecord::Base
has_many :speech_balloons
+ belongs_to :system_picture
validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 50}
validates :classname, :presence => true, :length => {:maximum => 50}
validates :caption, :presence => true, :length => {:maximum => 30}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :settings, :presence => true
before_validation :valid_encode
def self.store name, attr
#settingsにはHashデータが丸っと文字列化されて入る
- r = SpeechBalloonTemplate.replace_system_picture(attr["settings"] || {})
- attr["settings"] = r ? r.to_json : nil
+ r = SpeechBalloonTemplate.replace_system_picture(attr || {})
+ attr["settings"] = r["settings"] ? r["settings"].to_json : nil
r = SpeechBalloonTemplate.modify_object name, attr
r.overwrite
r.save
<ul>
<% @panel.panel_elements.each do |elm| %>
<li><a href="#elements-tabs-<%= elm.t -%>">
- <% case elm.class.to_s %>
- <% when 'PanelPicture' %>
- <%= tag(:img, elm.tmb_opt_img_tag) %>
- <% when 'SpeechBalloon' %>
- <%= h(truncate(elm.speech.content, :length => 6)) %>
- <% when 'GroundPicture' %>
- <%= tag(:img, elm.tmb_opt_img_tag) -%>
- <% when 'GroundColor' %>
- <div style="color: #<%= format("%06x", elm.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", elm.code) -%>;">
- <%= format("%06x", elm.code) %>
- </div>
- <% end %>
+ <div>
+ <% case elm.class.to_s %>
+ <% when 'PanelPicture' %>
+ <%= tag(:img, elm.tmb_opt_img_tag) %>
+ <div>
+ <%= h(truncate(elm.caption, :length => 6)) %>
+ </div>
+ <% when 'SpeechBalloon' %>
+ <%= tag(:img, elm.speech_balloon_template.system_picture.tmb_opt_img_tag) %>
+ <div>
+ <%= h(truncate(elm.speech.content, :length => 6)) %>
+ </div>
+ <% when 'GroundPicture' %>
+ <%= tag(:img, elm.tmb_opt_img_tag) -%>
+ <div>
+ <%= h(truncate(elm.caption, :length => 6)) %>
+ </div>
+ <% when 'GroundColor' %>
+ <div style="color: #<%= format("%06x", elm.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", elm.code) -%>;">
+ <%= format("%06x", elm.code) %>
+ </div>
+ <div>
+ <%= h(truncate(elm.caption, :length => 6)) %>
+ </div>
+ <% end %>
+ </div>
</a></li>
<% end %>
</ul>
</p>
<p>
+ <b><%= t_m 'SpeechBalloonTemplate.system_picture_id' -%>:</b>
+ <%= @speech_balloon_template.system_picture_id %>
+</p>
+
+<p>
<b><%= t_m 'SpeechBalloonTemplate.settings' -%>:</b>
<%= h @speech_balloon_template.settings %>
</p>
<h1><%= t '.title' -%></h1>
-<table>
- <tr>
- <th><%= t_m 'SpeechBalloonTemplate.caption' -%></th>
- </tr>
-
+<ul>
<% @speech_balloon_templates.each do |st| %>
- <tr>
- <td><%= link_to h(st.caption), speech_balloon_template_path(st) %></td>
- </tr>
+ <li>
+ <div>
+ <%= link_to tag(:img, st.system_picture.tmb_opt_img_tag), speech_balloon_template_path(st) %>
+ <div>
+ <%= link_to h(st.caption), speech_balloon_template_path(st) %>
+ </div>
+ </div>
+ </li>
<% end %>
-</table>
+</ul>
<th><%= t_m 'SpeechBalloonTemplate.classname' -%></th>
<th><%= t_m 'SpeechBalloonTemplate.caption' -%></th>
<th><%= t_m 'SpeechBalloonTemplate.t' -%></th>
+ <th><%= t_m 'SpeechBalloonTemplate.system_picture_id' -%></th>
<th><%= t_m 'SpeechBalloonTemplate.settings' -%></th>
<th><%= t_m 'SpeechBalloonTemplate.created_at' -%></th>
<th><%= t_m 'SpeechBalloonTemplate.updated_at' -%></th>
<%= speech_balloon_template.t %>
</td>
<td>
+ <%= link_to tag(:img, speech_balloon_template.system_picture.tmb_opt_img_tag), speech_balloon_template_path(speech_balloon_template.system_picture) %>
+ </td>
+ <td>
<%= h(truncate(speech_balloon_template.settings, :length => 10)) %>
</td>
<td>
<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
-<p>
- <b>caption:</b>
- <%= h @speech_balloon_template.caption %>
-</p>
+<div>
+ <%= link_to tag(:img, @speech_balloon_template.system_picture.tmb_opt_img_tag), speech_balloon_template_path(@speech_balloon_template) %>
+ <div>
+ <%= link_to h(@speech_balloon_template.caption), speech_balloon_template_path(@speech_balloon_template) %>
+ </div>
+</div>
<% if @author and @author.working? -%>
<h3><%= t('home.index.catch') -%></h3>
classname: クラス名
caption: 名前
t: 並び順
+ system_picture_id: アイコン
settings: 拡張データ
created_at: 作成
updated_at: 更新
--- /dev/null
+class AddSystemPictureIdOnSpeechBalloonTemplates < ActiveRecord::Migration
+ def up
+ add_column :speech_balloon_templates, :system_picture_id, :integer, :null => false, :default => 1
+ end
+
+ def down
+ remove_column :speech_balloon_templates, :system_picture_id
+ end
+end
sbt.classname 'Plain'
sbt.caption 'normal fuki'
sbt.t 0
+ sbt.system_picture_id 1
sbt.settings '{}'
end
@other_user = FactoryGirl.create( :user_yas)
@other_author = FactoryGirl.create :author, :user_id => @other_user.id
@other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+ @sp = FactoryGirl.create :system_picture
end
describe '検証に於いて' do
@st.should_not be_valid
end
end
+ context 'system_picture_idを検証するとき' do
+ it 'nullなら失敗する' do
+ @st.system_picture_id = nil
+ @st.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @st.system_picture_id = 'a'
+ @st.should_not be_valid
+ end
+ it '存在するシステム画像でなければ失敗する' do
+ @st.system_picture_id = 0
+ @st.should_not be_valid
+ end
+ end
context 'settingsを検証するとき' do
it 'nullなら失敗する' do
@st.settings = nil
"speech_balloon" => {"default" => 1},
"one" => {"balloon" => {"system_picture_id" => @sp.id}}
}
- @attr = {"classname" => 'store', "caption" => 'store test',
+ @attr = {"classname" => 'store', "caption" => 'store test', "system_picture_id" => @sp.id,
"settings" => @settings
}
end
context '事前チェック' do
before do
- SpeechBalloonTemplate.stub(:replace_system_picture).with(@settings).and_return(@settings)
+ SpeechBalloonTemplate.stub(:replace_system_picture).with(@attr).and_return(@attr)
SpeechBalloonTemplate.stub(:modify_object).with(any_args).and_return(@st)
SpeechBalloonTemplate.any_instance.stub(:overwrite).with(any_args).and_return(true)
SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(true)
end
it 'システム画像置換に依頼している' do
- SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@settings).exactly(1)
+ SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@attr).exactly(1)
r = SpeechBalloonTemplate.store 'circle_v01', @attr
end
it 'インポート処理のデータ更新準備に依頼している' do