X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fballoon.rb;h=b36a825ce947d8192e515b1114c1c39ec7ed2598;hb=a8af764be9b48ad0bf9eaca3e90f48af2c62ee3c;hp=110a3aab571096ccc00034a579469d9664e7f92c;hpb=d8b50c09ff9034a9abd9cf10ae839e0402df0e7c;p=pettanr%2Fpettanr.git diff --git a/app/models/balloon.rb b/app/models/balloon.rb index 110a3aab..b36a825c 100644 --- a/app/models/balloon.rb +++ b/app/models/balloon.rb @@ -1,5 +1,6 @@ -class Balloon < ActiveRecord::Base - include ElementPart +class Balloon < Peta::Content + load_manifest + include Peta::ElementPart belongs_to :speech_balloon belongs_to :system_picture @@ -13,15 +14,6 @@ class Balloon < ActiveRecord::Base # validates :caption, :presence => true validates :settings, :extend_balloon => true - before_validation :valid_encode - - def valid_encode - ['settings'].each do |a| - next if attributes[a] == nil - raise Pettanr::BadRequest unless attributes[a].valid_encoding? - end - end - def self.colum_structures @@colum_structures ||= { :r => { @@ -34,14 +26,9 @@ class Balloon < ActiveRecord::Base '/system_pictures/' + self.system_picture.filename end - def visible? roles - if MagicNumber['run_mode'] == 0 - return false unless guest_role_check(roles) - else - return false unless reader_role_check(roles) - end - return true if self.speech_balloon.panel.own?(roles) - self.speech_balloon.panel.visible? roles + def visible? operators + return false unless super + self.owner_model.visible? operators end def supply_default @@ -65,37 +52,12 @@ self.system_picture_id = 1 'balloon' end - def self.default_page_size - 25 - end - - def self.max_page_size - 100 - end - - def self.page prm = nil - page = prm.to_i - page = 1 if page < 1 - page - end - - def self.page_size prm = self.default_page_size - page_size = prm.to_i - page_size = self.max_page_size if page_size > self.max_page_size - page_size = self.default_page_size if page_size < 1 - page_size - end - def self.list_where 'panels.publish > 0' end - def self.list page = 1, page_size = self.default_page_size - Balloon.where(self.list_where()).includes(Balloon.list_opt).order('balloons.updated_at desc').offset((page -1) * page_size).limit(page_size) - end - - def self.list_paginate page = 1, page_size = self.default_page_size - Kaminari.paginate_array(Array.new(Balloon.where(self.list_where()).includes(Balloon.list_opt).count, nil)).page(page).per(page_size) + def self.list_order + 'balloons.updated_at desc' end def self.list_opt @@ -106,14 +68,6 @@ self.system_picture_id = 1 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}} end - def self.show cid, au - opt = {} - opt.merge!(Balloon.show_opt) - res = Balloon.find(cid, opt) - raise ActiveRecord::Forbidden unless res.visible?(au) - res - end - def self.show_opt {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}} end @@ -122,6 +76,13 @@ self.system_picture_id = 1 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}} end + def style + { + 'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px', + 'top' => self.y.to_s + 'px','left' => self.x.to_s + 'px' + } + end + def copy_attributes r = self.attributes r.delete 'id'