diff --git a/app/models/asset_collection.rb b/app/models/asset_collection.rb index 272d7db5..dcf3ce0a 100644 --- a/app/models/asset_collection.rb +++ b/app/models/asset_collection.rb @@ -5,21 +5,15 @@ class AssetCollection ## fields ## field :name, :type => String - field :slug, :type => String - # field :asset_fields_counter, :type => Integer, :default => 0 # FIXME (custom fields) - + field :slug, :type => String ## associations ## belongs_to_related :site - embeds_many :assets #, :custom_fields => true # FIXME (custom fields) - - # embeds_many :asset_fields # FIXME (custom fields) + embeds_many :assets ## behaviours ## custom_fields_for :assets - # accepts_nested_attributes_for :asset_fields, :allow_destroy => true # FIXME (custom fields) - ## callbacks ## before_validate :normalize_slug before_save :store_asset_positions! @@ -42,8 +36,8 @@ class AssetCollection @assets_order = order end - def ordered_asset_fields # FIXME (custom fields) - self.asset_fields.sort { |a, b| (a.position || 0) <=> (b.position || 0) } + def ordered_asset_custom_fields # FIXME (custom fields) + self.asset_custom_fields.sort { |a, b| (a.position || 0) <=> (b.position || 0) } end protected diff --git a/app/models/asset_field.rb b/app/models/asset_field.rb deleted file mode 100644 index dd31fa8f..00000000 --- a/app/models/asset_field.rb +++ /dev/null @@ -1,62 +0,0 @@ -class AssetField - include Mongoid::Document - include Mongoid::Timestamps - - ## fields ## - field :label, :type => String - field :_alias, :type => String # need it for instance in: > asset.description (description being a custom field) - field :_name, :type => String - field :kind, :type => String - field :position, :type => Integer, :default => 0 - - ## validations ## - validates_presence_of :label, :kind - - embedded_in :asset_collection, :inverse_of => :asset_custom_fields - - ## methods ## - - def field_type - case self.kind - when 'String', 'Text', 'Email' then String - else - self.kind.constantize - end - end - - def apply(object, association_name) - # puts "applying...#{self._name} / #{self._alias}" - object.class.send(:set_field, self._name, { :type => self.field_type }) - object.class_eval <<-EOF - alias :#{self.safe_alias} :#{self._name} - alias :#{self.safe_alias}= :#{self._name}= - EOF - end - - def safe_alias - self.set_alias - self._alias - end - - protected - - def set_unique_name! - self._name = "custom_field_#{self.increment_counter!}" - end - - def set_alias - return if self.label.blank? && self._alias.blank? - self._alias ||= self.label.clone - self._alias.slugify!(:downcase => true, :underscore => true) - end - - def increment_counter! - next_value = (self._parent.send(:"#{self.association_name}_counter") || 0) + 1 - self._parent.send(:"#{self.association_name}_counter=", next_value) - next_value - end - - def siblings - self._parent.associations[self.association_name] - end -end \ No newline at end of file diff --git a/app/views/admin/asset_collections/_custom_fields.html.haml b/app/views/admin/asset_collections/_custom_fields.html.haml index 81aa4038..f0844093 100644 --- a/app/views/admin/asset_collections/_custom_fields.html.haml +++ b/app/views/admin/asset_collections/_custom_fields.html.haml @@ -1,6 +1,6 @@ = f.foldable_inputs :name => :custom_fields, :class => 'editable-list fields off' do - - f.object.ordered_asset_fields.each do |field| - = f.fields_for :asset_fields, field, :child_index => field._index do |g| + - f.object.ordered_asset_custom_fields.each do |field| + = f.fields_for :asset_custom_fields, field, :child_index => field._index do |g| %li{ :class => "item added #{'error' unless field.errors.empty?}"} %span.handle = image_tag 'admin/form/icons/drag.png' @@ -20,7 +20,7 @@ %span.actions = link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('admin.messages.confirm') - = f.fields_for :asset_fields, @collection.asset_fields.build(:label => 'field name'), :child_index => '-1' do |g| + = f.fields_for :asset_custom_fields, @collection.asset_custom_fields.build(:label => 'field name'), :child_index => '-1' do |g| %li{ :class => 'item template' } %span.handle = image_tag 'admin/form/icons/drag.png' diff --git a/doc/TODO b/doc/TODO index 37b74cc4..03d0f6df 100644 --- a/doc/TODO +++ b/doc/TODO @@ -51,11 +51,11 @@ x domain scoping when authenticating - remove old files if new one - custom fields: x renaming fields - - ui - - rename asset_field - - apply in asset_field - - extract a plugin from custom fields - - field position + x extract a plugin from custom fields + x ui + x field position + x rename asset_field + - apply in asset_field - nested attributes - keep tracks of all custom fields (adding / editing assets) - custom fields -> metadata keys