-class Balloon < ActiveRecord::Base
- include ElementPart
+class Balloon < Peta::Element
+ load_manifest
belongs_to :speech_balloon
belongs_to :system_picture
# validates :caption, :presence => true
validates :settings, :extend_balloon => true
- before_validation :valid_encode
-
- def valid_encode
- ['settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
- end
-
- def self.colum_structures
- @@colum_structures ||= {
- :r => {
- :helper => 'panels/tail_angle_helper'
- }
- }
- end
-
def url
'/system_pictures/' + self.system_picture.filename
end
- def visible? roles
- if MagicNumber['run_mode'] == 0
- return false unless guest_role_check(roles)
- else
- return false unless reader_role_check(roles)
- end
- return true if self.speech_balloon.panel.own?(roles)
- self.speech_balloon.panel.visible? roles
+ def visible? operators
+ return false unless super
+ self.owner_model.visible? operators
end
def supply_default
end
def symbol_option
- self.get_parent.speech_balloon_template.symbol_option
- end
-
- def get_parent
- self.speech_balloon || @new_parent
- end
-
- def tag_element_part_type
- 'balloon'
- end
-
- def self.default_page_size
- 25
- end
-
- def self.max_page_size
- 100
- end
-
- def self.page prm = nil
- page = prm.to_i
- page = 1 if page < 1
- page
- end
-
- def self.page_size prm = self.default_page_size
- page_size = prm.to_i
- page_size = self.max_page_size if page_size > self.max_page_size
- page_size = self.default_page_size if page_size < 1
- page_size
+ self.speech_balloon.speech_balloon_template.symbol_option
end
def self.list_where
'panels.publish > 0'
end
- def self.list page = 1, page_size = self.default_page_size
- Balloon.where(self.list_where()).includes(Balloon.list_opt).order('balloons.updated_at desc').offset((page -1) * page_size).limit(page_size)
- end
-
- def self.list_paginate page = 1, page_size = self.default_page_size
- Kaminari.paginate_array(Array.new(Balloon.where(self.list_where()).includes(Balloon.list_opt).count, nil)).page(page).per(page_size)
- end
-
- def self.list_by_speech_balloon_where speech_balloon_id
- ['balloons.speech_balloon_id = ?', speech_balloon_id]
+ def self.list_order
+ 'balloons.updated_at desc'
end
- def self.list_by_speech_balloon speech_balloon_id, roles, page = 1, page_size = self.default_page_size
- self.where(self.list_by_speech_balloon_where(speech_balloon_id)).includes(self.list_opt).order('balloons.updated_at desc').offset((page -1) * page_size).limit(page_size)
+ def self.by_author_list_includes
+ {
+ :speech_balloon => {
+ :panel => {
+ :author => {}
+ }
+ }
+ }
end
def self.list_opt
{:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
end
- def self.show cid, au
- opt = {}
- opt.merge!(Balloon.show_opt)
- res = Balloon.find(cid, opt)
- raise ActiveRecord::Forbidden unless res.visible?(au)
- res
- end
-
def self.show_opt
{:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
end
{:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
end
+ def style
+ {
+ 'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
+ 'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
+ }
+ end
+
def copy_attributes
r = self.attributes
r.delete 'id'