X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fpanel_picture.rb;h=c64149af3a55f8a2913aa52ae363424df3cb1923;hb=5204ac22e62cbed768f27d5e7ea42cc85123f1c2;hp=ccb5cd07f16b961d3415fceea35b4a90be07767b;hpb=9e6a7b976f22e15609976da5194ea6344e71ea4d;p=pettanr%2Fpettanr.git diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index ccb5cd07..c64149af 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -1,6 +1,5 @@ -class PanelPicture < Pettanr::Item - include Element - include ElementInspire +class PanelPicture < Peta::Element + load_manifest belongs_to :panel belongs_to :picture @@ -14,29 +13,10 @@ class PanelPicture < Pettanr::Item validates :z, :presence => true, :numericality => {:greater_than => 0} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - def self.singular - 'PanelPicture' - end - - def self.plural - 'PanelPictures' - end - - def self.valid_encode_columns - super.merge ['link', 'caption'] - end - - def self.owner_type - :author - end - - def self.colum_structures - @@colum_structures ||= { - :width => { - :helper => 'panels/size_helper' - }, - :height => { - :helper => 'panels/size_helper' + def self.by_author_list_includes + { + :panel => { + :author => {} } } end @@ -67,16 +47,6 @@ class PanelPicture < Pettanr::Item true 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.panel.own?(roles) - self.panel.visible? roles - end - def supply_default self.x = 0 self.y = 0 @@ -114,10 +84,11 @@ class PanelPicture < Pettanr::Item 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 @@ -129,76 +100,12 @@ class PanelPicture < Pettanr::Item self.picture.symbol_option end - def boost - end - - def tag_element_type - 'panel_picture' - 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 + def self.public_list_where 'panels.publish > 0' end - def self.mylist_where au - ['panels.author_id = ?', au.id] - end - - def self.himlist_where au - ['panels.author_id = ? and panels.publish > 0', au.id] - end - - def self.list page = 1, page_size = self.default_page_size - PanelPicture.where(self.list_where()).includes(PanelPicture.list_opt).order('panel_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size) - end - - def self.mylist au, page = 1, page_size = Author.default_panel_picture_page_size - PanelPicture.where(self.mylist_where(au)).includes(PanelPicture.list_opt).order('panel_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size) - end - - def self.himlist au, page = 1, page_size = Author.default_panel_picture_page_size - PanelPicture.where(self.himlist_where(au)).includes(PanelPicture.list_opt).order('panel_pictures.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(PanelPicture.where(self.list_where()).includes(PanelPicture.list_opt).count, nil)).page(page).per(page_size) - end - - def self.mylist_paginate au, page = 1, page_size = Author.default_panel_picture_page_size - Kaminari.paginate_array(Array.new(PanelPicture.where(self.mylist_where(au)).includes(PanelPicture.list_opt).count, nil)).page(page).per(page_size) - end - - def self.himlist_paginate au, page = 1, page_size = Author.default_panel_picture_page_size - Kaminari.paginate_array(Array.new(PanelPicture.where(self.himlist_where(au)).includes(PanelPicture.list_opt).count, nil)).page(page).per(page_size) - end - - def self.list_by_panel_where panel_id - ['panel_pictures.panel_id = ?', panel_id] - end - - def self.list_by_panel panel_id, roles, page = 1, page_size = self.default_page_size - self.where(self.list_by_panel_where(panel_id)).includes(self.list_opt).order('panel_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size) + def self.list_order + 'panel_pictures.updated_at desc' end def self.list_opt @@ -209,14 +116,6 @@ class PanelPicture < Pettanr::Item {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }} 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 @@ -225,7 +124,7 @@ class PanelPicture < Pettanr::Item {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }} end - def store au + def store operators if self.new_record? self.panel.panel_pictures.build(self.attributes) else @@ -237,11 +136,11 @@ class PanelPicture < Pettanr::Item break end end - self.panel.store({}, au) + self.panel.store({}, operators) end - def remove au - self.panel.remove_element(self, au) + def remove operators + self.panel.remove_element(self, operators) end def scenario