OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / models / balloon.rb
1 class Balloon < Peta::Element
2   load_manifest
3   belongs_to :speech_balloon
4   belongs_to :speech_balloon_template
5   belongs_to :system_picture
6   
7   validates :speech_balloon_id, :numericality => {:allow_blank => true}
8   validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => {:both => false}
9   validates :speech_balloon_template_module_name, :presence => true, :length => {:maximum => 50}
10   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
11   validates :x, :presence => true, :numericality => true
12   validates :y, :presence => true, :numericality => true
13   validates :width, :presence => true, :numericality => true, :natural_number => true
14   validates :height, :presence => true, :numericality => true, :natural_number => true
15   validates :r, :presence => true, :numericality => true
16 #  validates :caption, :presence => true
17   validates :speech_balloon_template_settings, :boost => {:boost_name => :speech_balloon_template}
18
19   scope :with_panel, -> do
20     includes(speech_balloon: :panel)
21   end
22   
23   scope :with_speech_balloon_template, -> do
24     includes(:speech_balloon_template)
25   end
26   
27   scope :find_index, -> do
28     with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
29   end
30   
31   scope :find_private, -> (operators) do 
32     with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
33   end
34   
35   scope :find_by_panel, -> (panel_id) do 
36     find_index.where(panel_id: panel_id).references(:panel)
37   end
38   
39   scope :find_by_speech_balloon, -> (speech_balloon_id) do 
40     find_index.where(speech_balloon_id: speech_balloon_id).references(:panel)
41   end
42   
43   scope :find_by_speech_balloon_template, -> (speech_balloon_template_id) do 
44     find_index.where(speech_balloon_template_id: speech_balloon_template_id).references(:panel)
45   end
46   
47   scope :find_by_system_picture, -> (system_picture_id) do 
48     find_index.where(system_picture_id: system_picture_id).references(:panel)
49   end
50   
51   scope :find_by_author, -> (author_id) do 
52     find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
53   end
54   
55   def y
56     self.attributes['y']
57   end
58   
59   def url
60     '/system_pictures/' + self.system_picture.filename
61   end
62   
63   def supply_default
64     self.x = 0
65     self.y = 0
66     self.width = 100
67     self.height = 100
68     self.r = 0
69 self.system_picture_id = 1
70   end
71   
72   def symbol_option
73     self.speech_balloon.speech_balloon_template.symbol_option
74   end
75   
76   def self.public_list_where list
77     'panels.publish > 0'
78   end
79   
80   def self.by_author_list_includes
81     {
82       :speech_balloon => {
83         :panel => {
84           :author => {}
85         }
86       }
87     }
88   end
89   
90   def self.show_opt
91     {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
92   end
93   
94   def style
95     {
96       'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
97       'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px'
98     }
99   end
100   
101   def scenario
102   end
103   
104   def plain_scenario
105   end
106   
107 end