Class: DSMediaLibrary::FormHelper::MediaLibrary

Inherits:
Struct
  • Object
show all
Defined in:
app/helpers/ds_media_library/form_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dimensionsObject

Returns the value of attribute dimensions

Returns:

  • (Object)

    the current value of dimensions



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def dimensions
  @dimensions
end

#fieldObject

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def field
  @field
end

#helptextObject

Returns the value of attribute helptext

Returns:

  • (Object)

    the current value of helptext



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def helptext
  @helptext
end

#idsObject

Returns the value of attribute ids

Returns:

  • (Object)

    the current value of ids



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def ids
  @ids
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def label
  @label
end

#multipleObject

Returns the value of attribute multiple

Returns:

  • (Object)

    the current value of multiple



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def multiple
  @multiple
end

#optionalObject

Returns the value of attribute optional

Returns:

  • (Object)

    the current value of optional



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def optional
  @optional
end

#previewObject

Returns the value of attribute preview

Returns:

  • (Object)

    the current value of preview



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def preview
  @preview
end

#requiredObject

Returns the value of attribute required

Returns:

  • (Object)

    the current value of required



11
12
13
# File 'app/helpers/ds_media_library/form_helper.rb', line 11

def required
  @required
end

Class Method Details

.from_params(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/ds_media_library/form_helper.rb', line 12

def self.from_params params
  new(
    Array(params[:ids] || []).map(&:to_i),
    params[:field],
    params[:label],
    params[:multiple] == "true",
    params[:optional] == "true",
    params[:dimensions],
    params[:helptext],
    params[:preview] == "true",
    params[:required] == "true",
  )
end

Instance Method Details

#field_id_nameObject



42
43
44
45
46
47
48
# File 'app/helpers/ds_media_library/form_helper.rb', line 42

def field_id_name
  if multiple
    :"#{single_field}_ids"
  else
    :"#{field}_id"
  end
end

#field_typeObject



50
51
52
# File 'app/helpers/ds_media_library/form_helper.rb', line 50

def field_type
  multiple ? "checkbox" : "radio"
end

#file_field_nameObject



34
35
36
37
38
39
40
# File 'app/helpers/ds_media_library/form_helper.rb', line 34

def file_field_name
  if multiple
    :"new_#{single_field}_files"
  else
    :"#{field}_file"
  end
end

#heightObject



70
71
72
# File 'app/helpers/ds_media_library/form_helper.rb', line 70

def height
  dimensions.split("x").last if dimensions
end

#html_idObject



54
55
56
# File 'app/helpers/ds_media_library/form_helper.rb', line 54

def html_id
  "media-modal-#{field}"
end

#label_css_classObject



58
59
60
# File 'app/helpers/ds_media_library/form_helper.rb', line 58

def label_css_class
  "optional" if optional
end

#rootObject



74
75
76
# File 'app/helpers/ds_media_library/form_helper.rb', line 74

def root
  @root ||= Folder.root
end

#root_foldersObject



78
79
80
# File 'app/helpers/ds_media_library/form_helper.rb', line 78

def root_folders
  root.children
end

#root_resourcesObject



82
83
84
# File 'app/helpers/ds_media_library/form_helper.rb', line 82

def root_resources
  root.resources
end

#selected_resourcesObject



26
27
28
# File 'app/helpers/ds_media_library/form_helper.rb', line 26

def selected_resources
  DSNode::Resource.find(ids)
end

#single_fieldObject



30
31
32
# File 'app/helpers/ds_media_library/form_helper.rb', line 30

def single_field
  field.to_s.singularize.to_sym
end

#widthObject



66
67
68
# File 'app/helpers/ds_media_library/form_helper.rb', line 66

def width
  dimensions.split("x").first if dimensions
end