class CckForms::ParameterTypeClass::Album
Represents an ordered collection of photos (Image types).
Public Class Methods
demongoize_value(value, parameter_type_class=nil)
click to toggle source
Converts input array of attr hashes or IDs to array if Neofiles::Image (possibly lazy loadable)
# File lib/cck_forms/parameter_type_class/album.rb, line 23 def self.demongoize_value(value, parameter_type_class=nil) if value.respond_to? :each value = value.values if value.respond_to? :values value.map { |x| neofiles_mock_or_load(x) }.compact else [] end end
Public Instance Methods
build_form(form_builder, options)
click to toggle source
options:
value - current value (ID or Neofiles::Album) with_desc - if true, show the description edit richtext (default false)
# File lib/cck_forms/parameter_type_class/album.rb, line 36 def build_form(form_builder, options) set_value_in_hash options options = { }.merge options the_value = options[:value].is_a?(Array) ? options[:value] : [] input_name_prefix = form_builder.object_name + '[value][]' widget_id_prefix = form_builder_name_to_id form_builder, '_value_' file_forms = [] the_value.each do |image_id| image_id = image_id.is_a?(::Neofiles::File) ? image_id.id : image_id file_forms << cck_image_type.create_load_form( helper: self, file: image_id, input_name: input_name_prefix, append_create: false, clean_remove: true, widget_id: widget_id_prefix + file_forms.length.to_s, multiple: true, with_desc: options[:with_desc]) end add_file_form = cck_image_type.create_load_form( helper: self, file: nil, input_name: input_name_prefix, append_create: true, clean_remove: true, widget_id: widget_id_prefix + file_forms.length.to_s, multiple: true, with_desc: options[:with_desc]) id = form_builder_name_to_id form_builder, rand(1...1_000_000).to_s <<HTML <div class="neofiles-album-compact" id="#{id}"> #{add_file_form if Rails.application.config.neofiles.album_append_create_side == :left} #{file_forms.join} #{add_file_form if Rails.application.config.neofiles.album_append_create_side == :right} </div> <script type="text/javascript"> $(function() { $("##{id}").album(); }); </script> HTML end
cck_image_type()
click to toggle source
# File lib/cck_forms/parameter_type_class/album.rb, line 86 def cck_image_type CckForms::ParameterTypeClass::Image end
mongoize()
click to toggle source
Converts input array of Neofiles::Image or IDs to array of hashes (denormalized image data) or IDs
# File lib/cck_forms/parameter_type_class/album.rb, line 8 def mongoize the_value = value.is_a?(Hash) ? value['value'] : value result = [] if the_value.respond_to? :each the_value.each do |image| image = image[1] if the_value.respond_to? :each_value result.push self.class.neofiles_attrs_or_id(image, ::Neofiles::Image) end end result.compact end
to_diff_value(options = {})
click to toggle source
Returns a collection of 64x64 IMGs
# File lib/cck_forms/parameter_type_class/album.rb, line 97 def to_diff_value(options = {}) view_context = options[:view_context] images_html_list = (value || []).map(&:presence).compact.map do |elem| id = elem.is_a?(BSON::Document) ? elem['_id'] : elem "<img style='width: 64px; height: 64px;' src='#{view_context.neofiles_image_path(id: id, format: '64x64', crop: 1)}'>" end images_html_list.join.html_safe if images_html_list.any? end
to_s(options = nil)
click to toggle source
Returns empty string
# File lib/cck_forms/parameter_type_class/album.rb, line 92 def to_s(options = nil) '' end