3 self.abstract_class = true
10 self.my_manifest.associations.each_parent_model do |parent_model|
11 define_singleton_method("parent_model") do
26 def self.play_list_where cid
27 ['scroll_panels.scroll_id = ?', cid]
30 def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size
31 ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit)
34 def self.play_sheet_where sid
35 ['story_sheets.story_id = ?', sid]
38 def self.play_sheet story, operators, page = 1
39 ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
42 Sheet.show(ss.sheet.id, operators)
51 def self.play_paginate story, page
52 Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
55 def self.new_t binder_id
56 r = ScrollPanel.max_t(binder_id)
57 r.blank? ? 0 : r.to_i + 1
60 def self.max_t binder_id
61 self.class..maximum(:t, :conditions => ['scroll_id = ?', binder_id])
64 def self.find_t binder_id, t
65 self.class.find(:first, :conditions => ['scroll_id = ? and t = ?', binder_id, t])
68 def self.collect_t scroll_panel
69 r = self.class.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
73 def self.top_sheet story, author
74 StorySheet.play_list(story, author).first
77 def self.collect_t story_sheet
78 r = StorySheet.find(:all, :conditions => ['story_id = ?', story_sheet.story_id], :order => 't')
84 ary.compact.sort.each do |t|
85 break false unless t == i
91 def self.validate_t scroll_panel
92 ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
96 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
99 def lesser_shift old_t
100 self.t = 0 if self.t < 0
101 ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
104 def higher_shift old_t
105 nf = ScrollPanel.find_t(self.scroll_id, self.t)
106 max_t = ScrollPanel.max_t(self.scroll_id).to_i
107 self.t = max_t if self.t > max_t
108 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
111 def update_shift old_t
119 def rotate old_t = nil
122 self.t = ScrollPanel.new_t self.scroll_id
129 self.update_shift old_t
135 return nil if self.scroll_id == nil or self.panel_id == nil
136 self.scroll.own?(operators) and self.panel.usable?(operators)
139 def destroy_and_shorten
141 ScrollPanel.transaction do
142 ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ?)', self.scroll_id, self.t])
143 raise ActiveRecord::Rollback unless self.destroy