3 self.abstract_class = true
10 pm = Manifest.manifest.models[self.my_peta.parent_model_name].classify
11 define_singleton_method("parent_model") do
26 self.__send__ self.class.root_model.item_name
29 def visible? operators
30 return false unless super
31 self.root.visible? operators
34 def self.play_list_where cid
35 ['scroll_panels.scroll_id = ?', cid]
38 def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
39 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
42 def self.play_sheet_where sid
43 ['story_sheets.story_id = ?', sid]
46 def self.play_sheet story, operators, page = 1
47 ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
50 Sheet.show(ss.sheet.id, operators)
59 def self.play_paginate story, page
60 Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
63 def self.new_t binder_id
64 r = ScrollPanel.max_t(binder_id)
65 r.blank? ? 0 : r.to_i + 1
68 def self.max_t binder_id
69 self.class..maximum(:t, :conditions => ['scroll_id = ?', binder_id])
72 def self.find_t binder_id, t
73 self.class.find(:first, :conditions => ['scroll_id = ? and t = ?', binder_id, t])
76 def self.collect_t scroll_panel
77 r = self.class.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
81 def self.top_sheet story, author
82 StorySheet.play_list(story, author).first
85 def self.collect_t story_sheet
86 r = StorySheet.find(:all, :conditions => ['story_id = ?', story_sheet.story_id], :order => 't')
92 ary.compact.sort.each do |t|
93 break false unless t == i
99 def self.validate_t scroll_panel
100 ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
104 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
107 def lesser_shift old_t
108 self.t = 0 if self.t < 0
109 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
112 def higher_shift old_t
113 nf = ScrollPanel.find_t(self.scroll_id, self.t)
114 max_t = ScrollPanel.max_t(self.scroll_id).to_i
115 self.t = max_t if self.t > max_t
116 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
119 def update_shift old_t
127 def rotate old_t = nil
130 self.t = ScrollPanel.new_t self.scroll_id
137 self.update_shift old_t
143 return nil if self.scroll_id == nil or self.panel_id == nil
144 self.scroll.own?(operators) and self.panel.usable?(operators)
147 def destroy_and_shorten
149 ScrollPanel.transaction do
150 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ?)', self.scroll_id, self.t])
151 raise ActiveRecord::Rollback unless self.destroy