Class: CckForms::ParameterTypeClass::Album
- Inherits:
-
Object
- Object
- CckForms::ParameterTypeClass::Album
- Includes:
- NeofilesDenormalize, Base
- Defined in:
- lib/cck_forms/parameter_type_class/album.rb
Overview
Represents an ordered collection of photos (Image types).
Direct Known Subclasses
Constant Summary
Constants included from NeofilesDenormalize
NeofilesDenormalize::NEOFILES_LAZY_ATTRS
Class Method Summary collapse
-
.demongoize_value(value, parameter_type_class = nil) ⇒ Object
Converts input array of attr hashes or IDs to array if Neofiles::Image (possibly lazy loadable).
Instance Method Summary collapse
-
#build_form(form_builder, options) ⇒ Object
options:.
- #cck_image_type ⇒ Object
-
#mongoize ⇒ Object
Converts input array of Neofiles::Image or IDs to array of hashes (denormalized image data) or IDs.
-
#to_diff_value(options = {}) ⇒ Object
Returns a collection of 64x64 IMGs.
-
#to_s(options = nil) ⇒ Object
Returns empty string.
Class Method Details
.demongoize_value(value, parameter_type_class = nil) ⇒ Object
Converts input array of attr hashes or IDs to array if Neofiles::Image (possibly lazy loadable)
23 24 25 26 27 28 29 30 |
# 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 |
Instance Method Details
#build_form(form_builder, options) ⇒ Object
options:
value - current value (ID or Neofiles::Album)
with_desc - if true, show the description edit richtext (default false)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cck_forms/parameter_type_class/album.rb', line 36 def build_form(form_builder, ) set_value_in_hash = { }.merge the_value = [:value].is_a?(Array) ? [:value] : [] input_name_prefix = form_builder.object_name + '[value][]' = 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: + file_forms.length.to_s, multiple: true, with_desc: [: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: + file_forms.length.to_s, multiple: true, with_desc: [: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 ⇒ Object
86 87 88 |
# File 'lib/cck_forms/parameter_type_class/album.rb', line 86 def cck_image_type CckForms::ParameterTypeClass::Image end |
#mongoize ⇒ Object
Converts input array of Neofiles::Image or IDs to array of hashes (denormalized image data) or IDs
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 = {}) ⇒ Object
Returns a collection of 64x64 IMGs
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cck_forms/parameter_type_class/album.rb', line 97 def to_diff_value( = {}) view_context = [: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) ⇒ Object
Returns empty string
92 93 94 |
# File 'lib/cck_forms/parameter_type_class/album.rb', line 92 def to_s( = nil) '' end |