1 class Sheet < Peta::Root
7 validates :caption, :presence => true, :length => {:maximum => 100}
8 validates :width, :presence => true, :numericality => true, :natural_number => true
9 validates :height, :presence => true, :numericality => true, :natural_number => true
10 validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
11 accepts_nested_attributes_for :sheet_panels, :allow_destroy => true
13 scope :find_index, -> do
14 where(arel_table[:visible].gt 0)
17 scope :find_private, -> (operators) do
18 where(author_id: operators.author.id)
21 scope :find_by_author, -> (author_id) do
22 find_index.where(author_id: author_id)
25 scope :with_panels, -> do
26 includes(sheet_panels: :panel)
29 scope :find_by_panel, -> (panel_id) do
30 with_panels.find_index.where(Panel.arel_table[:id].eq panel_id).references(:panel)
33 scope :with_stories, -> do
34 includes(story_sheets: :story)
37 scope :find_by_story, -> (story_id) do
38 with_stories.find_index.where(Story.arel_table[:id].eq story_id).references(:story)
42 def self.find_play(id)
43 SheetPanel.find_play(id)
46 # scope of find_private_play
47 def self.find_private_play(id, operators)
48 SheetPanel.find_private_play(id, operators)
52 self.visible = 0 if self.visible.blank?
56 def overwrite operators
57 return false unless operators.author
58 self.author_id = operators.author.id
61 def visible? operators
63 when nil # super return
73 self.visible? operators
79 def self.public_list_where list
84 {:include => {:sheet_panels => {:panel => {}}, :author => {}}}
87 def self.show_json_opt
88 {:include => {:sheet_panels => {:include => {:panel => {}}}, :author => {}}}
103 def licensed_pictures
105 self.scenario_elements.each do |elm|
106 r.merge!(elm.licensed_pictures)
113 self.elements_items.each do |elm|
114 next if elm.copyable?