Class: Decidim::Assemblies::Admin::AssemblyImportForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Assemblies::Admin::AssemblyImportForm
- Includes:
- HasUploadValidations, TranslatableAttributes
- Defined in:
- app/forms/decidim/assemblies/admin/assembly_import_form.rb
Overview
A form object used to import an assembly from the admin dashboard.
Constant Summary collapse
- JSON_MIME_TYPE =
"application/json"
- ACCEPTED_TYPES =
Accepted mime types keys: are used for dynamic help text on admin form. values: are used to validate the file format of imported document.
WARNING: consider adding/removing the relative translation key at decidim.assemblies.admin.new_import.accepted_types when modifying this hash
{ json: JSON_MIME_TYPE }.freeze
Instance Method Summary collapse
- #document_text ⇒ Object
- #document_type ⇒ Object
- #document_type_must_be_valid ⇒ Object
- #i18n_invalid_document_type_text ⇒ Object
- #i18n_valid_mime_types_text ⇒ Object
-
#valid_mime_types ⇒ Object
Return ACCEPTED_MIME_TYPES plus ‘text/plain` for better markdown support.
Instance Method Details
#document_text ⇒ Object
42 43 44 |
# File 'app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 42 def document_text @document_text ||= document&.download end |
#document_type ⇒ Object
57 58 59 |
# File 'app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 57 def document_type document.content_type end |
#document_type_must_be_valid ⇒ Object
46 47 48 49 50 |
# File 'app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 46 def document_type_must_be_valid return if valid_mime_types.include?(document_type) errors.add(:document, i18n_invalid_document_type_text) end |
#i18n_invalid_document_type_text ⇒ Object
61 62 63 64 65 |
# File 'app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 61 def i18n_invalid_document_type_text I18n.t("allowed_file_content_types", scope: "activemodel.errors.models.assembly.attributes.document", types: i18n_valid_mime_types_text) end |
#i18n_valid_mime_types_text ⇒ Object
67 68 69 70 71 |
# File 'app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 67 def i18n_valid_mime_types_text ACCEPTED_TYPES.keys.map do |mime_type| I18n.t(mime_type, scope: "decidim.assemblies.admin.new_import.accepted_types") end.join(", ") end |
#valid_mime_types ⇒ Object
Return ACCEPTED_MIME_TYPES plus ‘text/plain` for better markdown support
53 54 55 |
# File 'app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 53 def valid_mime_types ACCEPTED_TYPES.values end |