1 class Balloon < ActiveRecord::Base
2 belongs_to :speech_balloon
3 belongs_to :system_picture
5 validates :speech_balloon_id, :numericality => {:allow_blank => true}
6 validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
7 validates :x, :presence => true, :numericality => true
8 validates :y, :presence => true, :numericality => true
9 validates :width, :presence => true, :numericality => true, :natural_number => true
10 validates :height, :presence => true, :numericality => true, :natural_number => true
11 validates :r, :presence => true, :numericality => true
12 # validates :caption, :presence => true
13 # validates :settings, :presence => true
15 before_validation :valid_encode
18 ['settings'].each do |a|
19 next if attributes[a] == nil
20 raise Pettanr::BadRequest unless attributes[a].valid_encoding?
25 '/system_pictures/' + self.system_picture.filename
29 if MagicNumber['run_mode'] == 0
30 return false unless guest_role_check(roles)
32 return false unless reader_role_check(roles)
34 return true if self.speech_balloon.panel.own?(roles)
35 self.speech_balloon.panel.visible? roles
38 def self.default_page_size
42 def self.max_page_size
46 def self.page prm = nil
52 def self.page_size prm = self.default_page_size
54 page_size = self.max_page_size if page_size > self.max_page_size
55 page_size = self.default_page_size if page_size < 1
59 def self.list page = 1, page_size = self.default_page_size
61 opt.merge!(Balloon.list_opt)
62 opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
63 opt.merge!({:conditions => 'panels.publish > 0', :order => 'balloons.updated_at desc'})
64 Balloon.find(:all, opt)
68 {:include => {:speech_balloon => {:panel => {:author => {}}, :speeches => {}, :speech_balloon_template => {} }}}
71 def self.list_json_opt
72 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speeches => {}, :speech_balloon_template => {} }}}}
77 opt.merge!(Balloon.show_opt)
78 res = Balloon.find(cid, opt)
79 raise ActiveRecord::Forbidden unless res.visible?(au)
84 {:include => {:speech_balloon => {:panel => {:author => {}}, :speeches => {}, :speech_balloon_template => {} }}}
87 def self.show_json_opt
88 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speeches => {}, :speech_balloon_template => {} }}}}
95 '<p>' + ERB::Util.html_escape(self.caption) + '</p>'