X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fpanel_picture.rb;h=80cf323f195e7cbcbd31388a9605a1c80eecb707;hb=29654349cc488148f053ec0bc973cd537cd6aaa8;hp=e74806cf48638202c8533ae2ac07fa7050c69070;hpb=6fb8bc9e0e2b4ee9840f42e2915598db46b9a4b8;p=pettanr%2Fpettanr.git diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index e74806cf..80cf323f 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -1,6 +1,5 @@ -class PanelPicture < Pettanr::Content - include Element - include ElementInspire +class PanelPicture < Peta::Element + load_manifest belongs_to :panel belongs_to :picture @@ -9,61 +8,40 @@ class PanelPicture < Pettanr::Content validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')} validates :x, :presence => true, :numericality => true validates :y, :presence => true, :numericality => true - validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => true, :sync_vh => true - validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => true, :sync_vh => true + validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true + validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true validates :z, :presence => true, :numericality => {:greater_than => 0} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - def self.owner_model - Panel + def self.pickup_item_name + Picture.item_name end - def self.valid_encode_columns - super + ['link', 'caption'] + def self.pickup_column_name + self.pickup_item_name + '_id' end - def self.colum_structures - @@colum_structures ||= { - :width => { - :helper => 'panels/size_helper' - }, - :height => { - :helper => 'panels/size_helper' - } - } + def pickup_id + # get :picture_id if head revision + self.attributes[self.pickup_column_name] end - def self.list_opt_for_panel - { - :panel_pictures => { - :picture => {:artist => {}, :license => {}} - } - } + def y + self.attributes['y'] end - def self.show_opt_for_panel + def self.by_author_list_includes { - :panel_pictures => { - :picture => {:artist => {}, :license => {}} + :panel => { + :author => {} } } end - 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 @@ -83,12 +61,14 @@ class PanelPicture < Pettanr::Content def flip res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h') - res += '/' unless res.empty? + res = res # format of /1.png?subdir=v + # res += '/' unless res.empty? # format of /v/1.png res end def filename - self.flip + self.picture.filename + q = self.flip.empty? ? '' : '?subdir=' + self.flip + self.picture.filename + q end def url @@ -101,10 +81,11 @@ class PanelPicture < Pettanr::Content def opt_img_tag spot = nil, opacity = 20 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : '' - {:id => self.tag_id(:img), :panel_id => self.tag_panel_id, :element_id => self.tag_element_id, :element_type => self.tag_element_type, - :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}"} + 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 @@ -116,56 +97,14 @@ class PanelPicture < Pettanr::Content self.picture.symbol_option end - def boost - end - - def tag_element_type - 'panel_picture' - end - - def self.list_where + def self.public_list_where list 'panels.publish > 0' end - def self.list_order - 'panel_pictures.updated_at desc' - end - - def self.list_opt - {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} } - end - - def self.list_json_opt - {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }} - end - def self.show_opt {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}} end - def self.show_json_opt - {: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? ''