X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fscroll_panel.rb;h=12fab0f6ad789ebc7ece2eae52b79d7773012337;hb=29654349cc488148f053ec0bc973cd537cd6aaa8;hp=3db39656efd27f34dd18aa2cfbb50a2f2a6e29e8;hpb=f2201d3750a46b2ace05fef4c61eee3e6c9156f5;p=pettanr%2Fpettanr.git diff --git a/app/models/scroll_panel.rb b/app/models/scroll_panel.rb index 3db39656..12fab0f6 100644 --- a/app/models/scroll_panel.rb +++ b/app/models/scroll_panel.rb @@ -6,7 +6,6 @@ class ScrollPanel < Peta::Leaf validates :scroll_id, :presence => true, :numericality => true, :existence => {:both => false} validates :panel_id, :presence => true, :numericality => true, :existence => {:both => false} - validates :author_id, :presence => true, :numericality => true, :existence => {:both => false} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} def supply_default @@ -16,15 +15,9 @@ class ScrollPanel < Peta::Leaf end def overwrite operators - return false unless operators.author - self.author_id = operators.author.id end - def self.public_list_order - 'scroll_panels.updated_at desc' - end - - def self.list_where + def self.public_list_where list 'scrolls.visible > 0' end @@ -36,79 +29,16 @@ class ScrollPanel < Peta::Leaf } end - def self.play_list_where cid - ['scroll_panels.scroll_id = ?', cid] - end - - def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size - ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit) - end - - def self.list_opt - { - :author => {}, - :scroll => { - :author => {} - }, - :panel => { - :author => {}, - :panel_pictures => {:picture => {:artist => {}, :license => {}}}, - :speech_balloons =>{:balloon => {}, :speech => {}} - } - } - end - - def self.list_json_opt - {:include => { - :author => {}, - :scroll => { - :author => {} - }, - :panel => { - :author => {}, - :panel_pictures => {:picture => {:artist => {}, :license => {}}}, - :speech_balloons =>{:balloon => {}, :speech => {}} - } - }} - end - def self.show_opt {:include => { - :author => {}, :scroll => { :author => {} }, - :panel => { - :author => {}, - :panel_pictures => {:picture => {:artist => {}, :license => {}}}, - :speech_balloons =>{:balloon => {}, :speech => {}} - } }} end - def elements - self.panel.elements - end - - def scroll_panel_as_json au - panel_include = if self.panel and self.panel.visible?(au) - {:include => {:author => {}}, :methods => :elements} - else - {:include => {:author => {}}} - end - self.to_json({:include => {:scroll => {:include => {:author => {}}}, :author => {}, :panel => panel_include}}) - end - - def self.list_as_json_text ary, au - '[' + ary.map {|i| i.scroll_panel_as_json(au) }.join(',') + ']' - end - def self.licensed_pictures scroll_panels - r = {} - scroll_panels.each do |scroll_panel| - r.merge!(scroll_panel.panel.licensed_pictures) if scroll_panel.panel - end - r + Panel.licensed_pictures scroll_panels.select {|sp| sp.panel }.map {|sp| sp.panel } end def allow? operators @@ -116,25 +46,4 @@ class ScrollPanel < Peta::Leaf self.scroll.own?(operators) and self.panel.usable?(operators) end - def store operators, old_t = nil - res = false - self.class.transaction do - case self.allow? operators - when true - self.rotate old_t - when false - raise ActiveRecord::Forbidden - else - end - res = self.save - raise ActiveRecord::Rollback unless res - res = self.class.validate_t(self.scroll_id) - unless res - self.errors.add :t, 'unserialized' - raise ActiveRecord::Rollback - end - end - res - end - end