has_many :speech_balloons, :dependent => :destroy
has_many :ground_pictures, :dependent => :destroy
has_many :ground_colors, :dependent => :destroy
- has_many :panel_colors, :dependent => :destroy
accepts_nested_attributes_for :panel_pictures, :allow_destroy => true
accepts_nested_attributes_for :speech_balloons, :allow_destroy => true
accepts_nested_attributes_for :ground_pictures, :allow_destroy => true
accepts_nested_attributes_for :ground_colors, :allow_destroy => true
- accepts_nested_attributes_for :panel_colors, :allow_destroy => true
validates :width, :presence => true, :numericality => true, :natural_number => true
validates :height, :presence => true, :numericality => true, :natural_number => true
page_size
end
+ def self.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
- opt = {}
- opt.merge!(self.list_opt)
- opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
- opt.merge!({:conditions => 'panels.publish > 0', :order => 'panels.updated_at desc'})
- Panel.find(:all, opt)
+ Panel.where(self.list_where()).includes(Panel.list_opt).order('panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
+ end
+
+ def self.mylist au, page = 1, page_size = Author.default_panel_page_size
+ Panel.where(self.mylist_where(au)).includes(Panel.list_opt).order('panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
+ end
+
+ def self.himlist au, page = 1, page_size = Author.default_panel_page_size
+ Panel.where(self.himlist_where(au)).includes(Panel.list_opt).order('panels.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(Panel.where(self.list_where()).count, nil)).page(page).per(page_size)
+ end
+
+ def self.mylist_paginate au, page = 1, page_size = Author.default_panel_page_size
+ Kaminari.paginate_array(Array.new(Panel.where(self.mylist_where(au)).count, nil)).page(page).per(page_size)
+ end
+
+ def self.himlist_paginate au, page = 1, page_size = Author.default_panel_page_size
+ Kaminari.paginate_array(Array.new(Panel.where(self.himlist_where(au)).count, nil)).page(page).per(page_size)
end
def self.list_opt
- {:include => {
+ {
:panel_pictures => {
:picture => {:artist => {}, :license => {}}
},
:picture => {:artist => {}, :license => {}}
},
:ground_colors => {
- :color => {}
- },
- :panel_colors => {
},
:author => {}
- }}
- end
-
- def self.mylist au, page = 1, page_size = Author.default_panel_page_size
- opt = {}
- opt.merge!(self.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 => 'panels.updated_at desc'})
- Panel.find(:all, opt)
+ }
end
def self.show rid, roles
:picture => {:artist => {}, :license => {}}
},
:ground_colors => {
- :color => {}
- },
- :panel_colors => {
},
:author => {}
}}
end
def grounds
- ((self.ground_colors || []) + (self.ground_pictures || []) + (self.panel_colors || [])).compact
+ ((self.ground_colors || []) + (self.ground_pictures || [])).compact
end
def panel_elements
:picture => {:artist => {}, :license => {}}
},
'GroundColor' => {
- :color => {}
},
- 'PanelColor' => {
- }
}
def self.elm_json_opt e
def self.collect_element_value elements, name
elements.map {|e|
e.map {|o|
- o[name]
- }
+ if o['_destroy'] or o[:_destroy]
+ nil
+ else
+ o[name]
+ end
+ }.compact
}.flatten
end
self.overwrite au
res = false
Panel.transaction do
+ res = self.save
unless validate_child
self.errors.add :base, I18n.t('errors.invalid_t')
raise ActiveRecord::Rollback
end
- res = self.save
end
res
end