X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fpanel.rb;h=cc1dc823c58ea82a8bf767d7abd8b167c6c14f2b;hb=2bd5f6aca898d5227ba35115a6cf0a09cffb1746;hp=919443bce54788142b3b98a135e24097aa3ebea3;hpb=4a6e0f4d50891db192d5f477f61b7448c1d90a02;p=pettanr%2Fpettanr.git diff --git a/app/models/panel.rb b/app/models/panel.rb index 919443bc..cc1dc823 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -2,7 +2,7 @@ class Panel < ActiveRecord::Base belongs_to :author belongs_to :resource_picture - has_many :stories + has_many :scroll_panels has_many :panel_pictures, :dependent => :destroy has_many :speech_balloons, :dependent => :destroy has_many :ground_pictures, :dependent => :destroy @@ -15,9 +15,6 @@ class Panel < ActiveRecord::Base validates :width, :presence => true, :numericality => true, :natural_number => true validates :height, :presence => true, :numericality => true, :natural_number => true validates :border, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - validates :x, :numericality => {:allow_blank => true} - validates :y, :numericality => {:allow_blank => true} - validates :z, :numericality => {:allow_blank => true, :greater_than => 0} validates :author_id, :presence => true, :numericality => true, :existence => {:both => false} validates :publish, :presence => true, :numericality => true @@ -74,6 +71,7 @@ class Panel < ActiveRecord::Base return false unless reader_role_check(roles) end return true if self.own?(roles) + return true if self.new_record? self.publish? end @@ -85,8 +83,8 @@ class Panel < ActiveRecord::Base self.publish > 0 end - def tag_id - 'panel' + self.tag_panel_id + def tag_id c = nil + 'panel' + self.tag_panel_id + c.to_s end def tag_panel_id @@ -97,8 +95,32 @@ class Panel < ActiveRecord::Base self.tag_id + f.to_s end - def field_tree f - 'panels-' + tag_panel_id + '-' + f.to_s + def tag_attributes column = nil, opt = {} + { + :id => self.field_tag_id(column), :panel_id => self.tag_panel_id + }.merge(opt) + end + + def select_tag_attributes(selected, column, opt = {}) + [ + :last, :first, + {:html => {:selected => selected}}, + self.field_tag_attributes(column, opt) + ] + end + + def field_tag_attributes column, opt = {} + self.tag_attributes(column).merge( + {:column => column} + ).merge(opt) + end + + def tag_attr column = nil, opt = {} + self.tag_attributes(column, opt).to_attr + end + + def field_tag_attr column, no_attr, opt = {} + self.field_tag_attributes(column, no_attr, opt).to_attr end def self.default_page_size @@ -312,6 +334,16 @@ class Panel < ActiveRecord::Base Panel.validate_elements_serial validate_serial_list end + def boost + @new_element_index = 0 + self.panel_elements.each do |elm| + if elm.new_record? + elm.new_index = @new_element_index + @new_element_index += 1 + end + end + end + def store attr, au if attr == false self.errors.add :base, I18n.t('errors.invalid_json') @@ -323,6 +355,7 @@ class Panel < ActiveRecord::Base Panel.transaction do self.panel_elements.each do |elm| elm.new_panel = self + elm.boost end #self.publish = nil res = self.save