3 self.abstract_class = true
10 pm = Manifest.manifest.models[self.my_peta.parent_model_name].classify
11 define_singleton_method("parent_model") do
25 def visible? operators
26 return false unless super
27 self.class.root_model.visible? operators
30 def self.play_list_where cid
31 ['scroll_panels.scroll_id = ?', cid]
34 def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
35 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
38 def self.play_sheet_where sid
39 ['story_sheets.story_id = ?', sid]
42 def self.play_sheet story, operators, page = 1
43 ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
46 Sheet.show(ss.sheet.id, operators)
55 def self.play_paginate story, page
56 Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
59 def self.new_t binder_id
60 r = ScrollPanel.max_t(binder_id)
61 r.blank? ? 0 : r.to_i + 1
64 def self.max_t binder_id
65 self.class..maximum(:t, :conditions => ['scroll_id = ?', binder_id])
68 def self.find_t binder_id, t
69 self.class.find(:first, :conditions => ['scroll_id = ? and t = ?', binder_id, t])
72 def self.collect_t scroll_panel
73 r = self.class.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
77 def self.top_sheet story, author
78 StorySheet.play_list(story, author).first
81 def self.collect_t story_sheet
82 r = StorySheet.find(:all, :conditions => ['story_id = ?', story_sheet.story_id], :order => 't')
88 ary.compact.sort.each do |t|
89 break false unless t == i
95 def self.validate_t scroll_panel
96 ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
100 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
103 def lesser_shift old_t
104 self.t = 0 if self.t < 0
105 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
108 def higher_shift old_t
109 nf = ScrollPanel.find_t(self.scroll_id, self.t)
110 max_t = ScrollPanel.max_t(self.scroll_id).to_i
111 self.t = max_t if self.t > max_t
112 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
115 def update_shift old_t
123 def rotate old_t = nil
126 self.t = ScrollPanel.new_t self.scroll_id
133 self.update_shift old_t
139 return nil if self.scroll_id == nil or self.panel_id == nil
140 self.scroll.own?(operators) and self.panel.usable?(operators)
143 def destroy_and_shorten
145 ScrollPanel.transaction do
146 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ?)', self.scroll_id, self.t])
147 raise ActiveRecord::Rollback unless self.destroy