class Balloon < ActiveRecord::Base
+ include ElementPart
belongs_to :speech_balloon
belongs_to :system_picture
validates :y, :presence => true, :numericality => true
validates :width, :presence => true, :numericality => true, :natural_number => true
validates :height, :presence => true, :numericality => true, :natural_number => true
+ validates :r, :presence => true, :numericality => true
# validates :caption, :presence => true
-# validates :settings, :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
self.speech_balloon.panel.visible? roles
end
+ def supply_default
+ self.x = 0
+ self.y = 0
+ self.width = 100
+ self.height = 100
+ self.r = 0
+self.system_picture_id = 1
+ 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
page_size
end
+ def self.list_where
+ 'panels.publish > 0'
+ end
+
def self.list page = 1, page_size = self.default_page_size
- opt = {}
- opt.merge!(Balloon.list_opt)
- opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
- opt.merge!({:conditions => 'panels.publish > 0', :order => 'balloons.updated_at desc'})
- Balloon.find(:all, opt)
+ 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_opt
- {:include => {:speech_balloon => {:panel => {:author => {}}, :speeches => {}, :speech_balloon_template => {} }}}
+ {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
end
def self.list_json_opt
- {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speeches => {}, :speech_balloon_template => {} }}}}
+ {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
end
def self.show cid, au
end
def self.show_opt
- {:include => {:speech_balloon => {:panel => {:author => {}}, :speeches => {}, :speech_balloon_template => {} }}}
+ {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
end
def self.show_json_opt
- {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speeches => {}, :speech_balloon_template => {} }}}}
+ {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
+ end
+
+ def copy_attributes
+ r = self.attributes
+ r.delete 'id'
+ r.delete 'speech_balloon_id'
+ r.delete 'created_at'
+ r.delete 'updated_at'
+ r
+ end
+
+ def self.panelize balloon_attributes
+ {'balloon_attributes' => balloon_attributes}
+ end
+
+ def scenario
+ end
+
+ def plain_scenario
end
end