Class: Decidim::Proposals::Admin::ImportParticipatoryTextForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Proposals::Admin::ImportParticipatoryTextForm
- Includes:
- HasUploadValidations, TranslatableAttributes
- Defined in:
- app/forms/decidim/proposals/admin/import_participatory_text_form.rb
Overview
A form object to be used when admin users want to import a collection of proposals from a participatory text.
Constant Summary collapse
- ACCEPTED_MIME_TYPES =
WARNING: consider adding/removing the relative translation key at decidim.assemblies.admin.new_import.accepted_types when modifying this hash
Decidim::Proposals::DocToMarkdown::ACCEPTED_MIME_TYPES
Instance Method Summary collapse
- #default_locale ⇒ Object
- #document_text ⇒ Object
- #document_type ⇒ Object
- #document_type_must_be_valid ⇒ Object
- #i18n_invalid_document_type_text ⇒ Object
- #i18n_valid_mime_types_text ⇒ Object
-
#new_participatory_text? ⇒ Boolean
Assume it is a NEW participatory_text if there are no proposals Validate document presence while CREATING proposals from document Allow skipping document validation while UPDATING title/description.
-
#valid_mime_types ⇒ Object
Return ACCEPTED_MIME_TYPES plus ‘text/plain` for better markdown support.
Instance Method Details
#default_locale ⇒ Object
58 59 60 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 58 def default_locale current_participatory_space.organization.default_locale end |
#document_text ⇒ Object
62 63 64 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 62 def document_text @document_text ||= document&.download end |
#document_type ⇒ Object
42 43 44 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 42 def document_type document.content_type end |
#document_type_must_be_valid ⇒ Object
31 32 33 34 35 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 31 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
46 47 48 49 50 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 46 def i18n_invalid_document_type_text I18n.t("allowed_file_content_types", scope: "activemodel.errors.models.participatory_text.attributes.document", types: i18n_valid_mime_types_text) end |
#i18n_valid_mime_types_text ⇒ Object
52 53 54 55 56 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 52 def i18n_valid_mime_types_text ACCEPTED_MIME_TYPES.keys.map do |mime_type| I18n.t(mime_type, scope: "decidim.proposals.admin.participatory_texts.new_import.accepted_mime_types") end.join(", ") end |
#new_participatory_text? ⇒ Boolean
Assume it is a NEW participatory_text if there are no proposals Validate document presence while CREATING proposals from document Allow skipping document validation while UPDATING title/description
27 28 29 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 27 def new_participatory_text? Decidim::Proposals::Proposal.where(component: current_component).blank? end |
#valid_mime_types ⇒ Object
Return ACCEPTED_MIME_TYPES plus ‘text/plain` for better markdown support
38 39 40 |
# File 'app/forms/decidim/proposals/admin/import_participatory_text_form.rb', line 38 def valid_mime_types ACCEPTED_MIME_TYPES.values + [Decidim::Proposals::DocToMarkdown::TEXT_PLAIN_MIME_TYPE] + ["application/octet-stream"] end |