X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fpanel_picture.rb;h=2943844ae716cfb2013f5fc576bb9ffe1091c213;hb=e6d20eec0a3241ee66d69a9be5c4e2e1f70b0dfc;hp=d4720cefb3fb59f662ee1f4ce8ecc8ccea9c01d8;hpb=54e3c035bc4f6737db470993dae3cd9ad9149961;p=pettanr%2Fpettanr.git diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index d4720cef..2943844a 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -1,4 +1,5 @@ -class PanelPicture < ActiveRecord::Base +class PanelPicture < Peta::Element + load_manifest belongs_to :panel belongs_to :picture @@ -12,23 +13,52 @@ class PanelPicture < ActiveRecord::Base validates :z, :presence => true, :numericality => {:greater_than => 0} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - before_validation :valid_encode + def self.list_opt_for_panel + { + :panel_pictures => { + :picture => {:artist => {}, :license => {}} + } + } + end - def valid_encode - ['link', 'caption'].each do |a| - next if attributes[a] == nil - raise Pettanr::BadRequest unless attributes[a].valid_encoding? - end + def self.show_opt_for_panel + { + :panel_pictures => { + :picture => {:artist => {}, :license => {}} + } + } end - def visible? roles - if MagicNumber['run_mode'] == 0 - return false unless guest_role_check(roles) - else - return false unless reader_role_check(roles) + def self.json_opt_for_panel + { + :picture => {:artist => {}, :license => {}} + } + end + + def self.has_picture? + true + end + + def visible? operators + return false unless super + self.owner_model.visible? operators + end + + def supply_default + self.x = 0 + self.y = 0 + if self.picture + self.width = self.picture.width + self.height = self.picture.height + end + if self.panel + self.t = self.panel.new_t + self.z = self.panel.new_z end - return true if self.panel.own?(roles) - self.panel.visible? roles + end + + def overwrite pid + self.panel_id = pid end def flip @@ -45,8 +75,17 @@ class PanelPicture < ActiveRecord::Base '/pictures/' + self.filename end - def opt_img_tag - {:src => self.url, :vPicture => self.id, :width => self.width.abs, :height => self.height.abs, :alt => self.caption, :style => "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; "} + def opt_div_style + "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;" + end + + def opt_img_tag spot = nil, opacity = 20 + o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : '' + self.tag_attributes(:img, { + :class => "panel-picture", :vPicture => self.id, + :src => self.url, :width => self.width.abs, :height => self.height.abs, :picture_id => self.picture_id, :ext => self.picture.ext, :alt => self.caption, + :style => "#{o}" + }) end def tmb_opt_img_tag @@ -54,59 +93,26 @@ class PanelPicture < ActiveRecord::Base {:src => self.url, :width => tw, :height => th, :alt => self.caption} 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 + def symbol_option + self.picture.symbol_option 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 + def self.list_where + 'panels.publish > 0' end - def self.list page = 1, page_size = self.default_page_size - opt = {} - opt.merge!(PanelPicture.list_opt) - opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 - opt.merge!({:conditions => 'panels.publish > 0', :order => 'panel_pictures.updated_at desc'}) - PanelPicture.find(:all, opt) + def self.list_order + 'panel_pictures.updated_at desc' end def self.list_opt - {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}} + {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} } end def self.list_json_opt {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }} end - def self.mylist au, page = 1, page_size = Author.default_panel_picture_page_size - opt = {} - opt.merge!(PanelPicture.list_opt) - opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 - opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panel_pictures.updated_at desc'}) - PanelPicture.find(:all, opt) - end - - def self.show cid, au - opt = {} - opt.merge!(PanelPicture.show_opt) - res = PanelPicture.find(cid, opt) - raise ActiveRecord::Forbidden unless res.visible?(au) - res - end - def self.show_opt {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}} end @@ -115,6 +121,25 @@ class PanelPicture < ActiveRecord::Base {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }} end + def store operators + if self.new_record? + self.panel.panel_pictures.build(self.attributes) + else + self.panel.panel_pictures.each do |panel_picture| + next unless panel_picture == self + attr = self.attributes + attr.delete 'id' + panel_picture.attributes = attr + break + end + end + self.panel.store({}, operators) + end + + def remove operators + self.panel.remove_element(self, operators) + end + def scenario if caption.blank? ''