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
30 self.root.own? operators
33 def visible? operators
34 return false unless super
35 self.root.visible? operators
38 def self.play_list_where cid
39 ['scroll_panels.scroll_id = ?', cid]
42 def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
43 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
46 def self.play_sheet_where sid
47 ['story_sheets.story_id = ?', sid]
50 def self.play_sheet story, operators, page = 1
51 ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
54 Sheet.show(ss.sheet.id, operators)
63 def self.play_paginate story, page
64 Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
67 def self.new_t binder_id
68 r = ScrollPanel.max_t(binder_id)
69 r.blank? ? 0 : r.to_i + 1
72 def self.max_t binder_id
73 self.class..maximum(:t, :conditions => ['scroll_id = ?', binder_id])
76 def self.find_t binder_id, t
77 self.class.find(:first, :conditions => ['scroll_id = ? and t = ?', binder_id, t])
80 def self.collect_t scroll_panel
81 r = self.class.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
85 def self.top_sheet story, author
86 StorySheet.play_list(story, author).first
89 def self.collect_t story_sheet
90 r = StorySheet.find(:all, :conditions => ['story_id = ?', story_sheet.story_id], :order => 't')
96 ary.compact.sort.each do |t|
97 break false unless t == i
100 ary.compact.size == i
103 def self.validate_t scroll_panel
104 ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
108 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
111 def lesser_shift old_t
112 self.t = 0 if self.t < 0
113 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
116 def higher_shift old_t
117 nf = ScrollPanel.find_t(self.scroll_id, self.t)
118 max_t = ScrollPanel.max_t(self.scroll_id).to_i
119 self.t = max_t if self.t > max_t
120 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
123 def update_shift old_t
131 def rotate old_t = nil
134 self.t = ScrollPanel.new_t self.scroll_id
141 self.update_shift old_t
147 return nil if self.scroll_id == nil or self.panel_id == nil
148 self.scroll.own?(operators) and self.panel.usable?(operators)
151 def destroy_and_shorten
153 ScrollPanel.transaction do
154 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ?)', self.scroll_id, self.t])
155 raise ActiveRecord::Rollback unless self.destroy