decidim-voca 0.0.6 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +161 -161
- data/README.md +42 -133
- data/Rakefile +46 -39
- data/app/cells/decidim/footer_topics/show_overrides.erb +8 -0
- data/app/cells/decidim/meetings/dates_and_map/show_overrides.erb +23 -0
- data/app/commands/decidim/voca/admin/code_census/save_code_list.rb +34 -0
- data/app/commands/decidim/voca/code_census/confirm_code_authorization.rb +16 -0
- data/app/commands/decidim/voca/create_editor_file.rb +36 -0
- data/app/commands/decidim/voca/rack_attack_configurator.rb +244 -0
- data/app/commands/decidim/voca/sync_redis_routing.rb +120 -0
- data/app/commands/decidim/voca/user_fields_configurator.rb +40 -0
- data/app/controllers/decidim/voca/admin/application_controller.rb +4 -6
- data/app/controllers/decidim/voca/admin/code_census/code_lists_controller.rb +40 -0
- data/app/controllers/decidim/voca/application_controller.rb +4 -6
- data/app/controllers/decidim/voca/code_census/authorizations_controller.rb +53 -0
- data/app/controllers/decidim/voca/editor_files_controller.rb +47 -0
- data/app/controllers/decidim/voca/geolocation_controller.rb +32 -0
- data/app/forms/decidim/voca/admin/code_census/code_list_form.rb +21 -0
- data/app/forms/decidim/voca/admin/organization_config_form.rb +24 -0
- data/app/forms/decidim/voca/code_census/code_form.rb +41 -0
- data/app/forms/decidim/voca/editor_file_form.rb +18 -0
- data/app/jobs/decidim/voca/machine_translate_awesome_menu_label_job.rb +63 -0
- data/app/jobs/decidim/voca/machine_translate_component_setting_job.rb +58 -0
- data/app/jobs/decidim/voca/machine_translate_content_block_setting_job.rb +85 -0
- data/app/models/decidim/voca/conversation_uuid.rb +18 -0
- data/app/models/decidim/voca/editor_file.rb +18 -0
- data/app/models/decidim/voca/validation_code.rb +13 -0
- data/app/overrides/admin_add_machine_translation_flag.rb +40 -0
- data/app/overrides/insert_assets.rb +26 -0
- data/app/overrides/insert_weglot_scripts.rb +60 -0
- data/app/overrides/proposal_camera.rb +18 -0
- data/app/overrides/show_votes.rb +27 -0
- data/app/overrides/voca_footer.rb +52 -0
- data/app/packs/entrypoints/admin-decidim-voca.js +2 -0
- data/app/packs/entrypoints/admin-decidim-voca.scss +1 -0
- data/app/packs/entrypoints/decidim-voca-fixes.scss +1 -0
- data/app/packs/entrypoints/decidim-voca.js +1 -0
- data/app/packs/entrypoints/decidim-voca.scss +1 -0
- data/app/packs/images/voca-logo-primary-x3.png +0 -0
- data/app/packs/src/decidim/direct_uploads/upload_field.js +150 -0
- data/app/packs/src/decidim/voca/admin/voca.js +16 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/use_camera_button.js +39 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_current_position.js +21 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_proposal_form.js +13 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/loading.js +23 -0
- data/app/packs/src/decidim/voca/proposal_better_ux/utils/locate_coordinates.js +23 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/custom_field_renderer_override.js +152 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/editor_budget_field.js +329 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/editor_upload_field.js +85 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/proposal_custom_fields.js +96 -0
- data/app/packs/src/decidim/voca/proposal_custom_fields/render_budget_field.js +76 -0
- data/app/packs/src/decidim/voca/proposal_fields/render_budget_field.js +76 -0
- data/app/packs/src/decidim/voca/questionnaire/scroll_questionnaire_steps_to_top.js +18 -0
- data/app/packs/src/decidim/voca/voca.js +4 -0
- data/app/packs/src/decidim/voca/weglot/index.js +13 -0
- data/app/packs/src/decidim/voca/weglot/start_weglot.js +112 -0
- data/app/packs/src/decidim/voca/weglot/switcher.js +92 -0
- data/app/packs/src/decidim/voca/weglot/wait_for_weglot.js +10 -0
- data/app/packs/stylesheets/decidim/voca/_custom_proposal_fields.scss +111 -0
- data/app/packs/stylesheets/decidim/voca/_decidim_voca.scss +5 -0
- data/app/packs/stylesheets/decidim/voca/_decidim_voca_fixes.scss +25 -0
- data/app/packs/stylesheets/decidim/voca/_primary_footer.scss +77 -0
- data/app/packs/stylesheets/decidim/voca/_proposal_camera.scss +14 -0
- data/app/packs/stylesheets/decidim/voca/_weglot.scss +61 -0
- data/app/packs/stylesheets/decidim/voca/admin/_decidim_voca.scss +5 -0
- data/app/packs/stylesheets/decidim/voca/admin/_full_machine_translation.scss +34 -0
- data/app/permissions/decidim/voca/admin/permissions.rb +31 -0
- data/app/permissions/decidim/voca/permissions.rb +17 -0
- data/app/views/decidim/voca/admin/code_census/authorizations/new.html.erb +33 -0
- data/app/views/decidim/voca/admin/code_census/code_lists/edit.html.erb +27 -0
- data/app/views/decidim/voca/code_census/authorizations/new.html.erb +24 -0
- data/app/views/decidim/voca/deepl/overrides/_admin_machine_translation_alert.html.erb +14 -0
- data/app/views/decidim/voca/rack_attack/_blocked.html.erb +151 -0
- data/app/views/decidim/voca/weglot/_js_configuration.html.erb +14 -0
- data/app/views/decidim/voca/weglot/_locale_switcher.html.erb +14 -0
- data/app/views/decidim/voca/weglot/_locale_switcher_mobile.erb +14 -0
- data/app/views/decidim/voca/weglot/_topbar_locale_switcher.html.erb +14 -0
- data/config/assets.rb +12 -0
- data/config/i18n-tasks.yml +14 -5
- data/config/locales/cs.yml +94 -0
- data/config/locales/custom_fields.cs.yml +30 -0
- data/config/locales/custom_fields.en.yml +41 -0
- data/config/locales/custom_fields.fr.yml +30 -0
- data/config/locales/custom_fields.it.yml +30 -0
- data/config/locales/en.yml +97 -4
- data/config/locales/fr.yml +102 -0
- data/config/locales/it.yml +94 -0
- data/lib/decidim/voca/awesome_menu_label_machine_translation.rb +73 -0
- data/lib/decidim/voca/awesome_menu_labels.rb +28 -0
- data/lib/decidim/voca/code_census/admin_engine.rb +22 -0
- data/lib/decidim/voca/code_census/engine.rb +29 -0
- data/lib/decidim/voca/code_census/workflow.rb +7 -0
- data/lib/decidim/voca/code_census.rb +4 -0
- data/lib/decidim/voca/component_setting_manifest.rb +27 -0
- data/lib/decidim/voca/component_setting_pending_locales.rb +33 -0
- data/lib/decidim/voca/component_translated_settings_machine_translation.rb +86 -0
- data/lib/decidim/voca/configuration.rb +23 -0
- data/lib/decidim/voca/content_block_setting_manifest.rb +67 -0
- data/lib/decidim/voca/content_block_translated_settings_machine_translation.rb +100 -0
- data/lib/decidim/voca/deepl/deepl_active_job_context.rb +27 -0
- data/lib/decidim/voca/deepl/deepl_context.rb +78 -0
- data/lib/decidim/voca/deepl/deepl_form_builder_overrides.rb +82 -0
- data/lib/decidim/voca/deepl/deepl_machine_translator.rb +61 -0
- data/lib/decidim/voca/deepl/deepl_middleware.rb +83 -0
- data/lib/decidim/voca/deepl/engine_config.rb +181 -0
- data/lib/decidim/voca/deepl/settings.rb +75 -0
- data/lib/decidim/voca/deepl/translation_bar_overrides.rb +20 -0
- data/lib/decidim/voca/deepl.rb +10 -0
- data/lib/decidim/voca/engine.rb +320 -11
- data/lib/decidim/voca/export/comment_serializer_localized_csv.rb +34 -0
- data/lib/decidim/voca/export/csv_with_locale_transformer.rb +53 -0
- data/lib/decidim/voca/export/proposal_serializer_localized_csv.rb +45 -0
- data/lib/decidim/voca/export/user_answers_serializer_localized_csv.rb +54 -0
- data/lib/decidim/voca/installation.rb +33 -0
- data/lib/decidim/voca/machine_translation/translate_string.rb +121 -0
- data/lib/decidim/voca/machine_translation_human_source.rb +29 -0
- data/lib/decidim/voca/machine_translation_resource_job_voca.rb +65 -0
- data/lib/decidim/voca/organization_voca_extensions.rb +31 -0
- data/lib/decidim/voca/overrides/csv_export_serializers.rb +51 -0
- data/lib/decidim/voca/overrides/meetings/dates_and_map_cell_overrides.rb +20 -0
- data/lib/decidim/voca/overrides/menu_breadcrumb_last_activity_cache.rb +31 -0
- data/lib/decidim/voca/overrides/mod_secure/conversation_controller_overrides.rb +19 -0
- data/lib/decidim/voca/overrides/mod_secure/conversation_sanitize.rb +29 -0
- data/lib/decidim/voca/overrides/mod_secure/conversation_uuid.rb +34 -0
- data/lib/decidim/voca/overrides/mod_secure/user_conversations_redirect_overrides.rb +53 -0
- data/lib/decidim/voca/overrides/mod_secure/user_profile_verification_override.rb +31 -0
- data/lib/decidim/voca/overrides/newsletter_helper_overrides.rb +30 -0
- data/lib/decidim/voca/overrides/resource_presenter_overrides.rb +30 -0
- data/lib/decidim/voca/overrides/sanitize_helper_overrides.rb +39 -0
- data/lib/decidim/voca/sync_locales/README.md +13 -0
- data/lib/decidim/voca/sync_locales/awesome_menu_label_sync.rb +89 -0
- data/lib/decidim/voca/sync_locales/command.rb +54 -0
- data/lib/decidim/voca/sync_locales/component_setting_sync.rb +72 -0
- data/lib/decidim/voca/sync_locales/content_block_setting_sync.rb +86 -0
- data/lib/decidim/voca/sync_locales/field_hash_normalizer.rb +98 -0
- data/lib/decidim/voca/sync_locales/locale_context.rb +589 -0
- data/lib/decidim/voca/sync_locales/machine_translation_enqueuer.rb +60 -0
- data/lib/decidim/voca/sync_locales/relation_lint_runner.rb +55 -0
- data/lib/decidim/voca/sync_locales/runner.rb +352 -0
- data/lib/decidim/voca/sync_locales.rb +11 -0
- data/lib/decidim/voca/update_column_without_callbacks.rb +21 -0
- data/lib/decidim/voca/version.rb +13 -3
- data/lib/decidim/voca.rb +40 -14
- data/lib/decidim-voca.rb +5 -0
- data/lib/tasks/decidim/voca/voca_anonymize.rake +41 -0
- data/lib/tasks/decidim/voca/voca_clean_machine_translations.rake +22 -0
- data/lib/tasks/decidim/voca/voca_enhanced_invalid_record.rake +141 -0
- data/lib/tasks/decidim/voca/voca_install_migration.rake +45 -0
- data/lib/tasks/decidim/voca/voca_relation_lint.rake +12 -0
- data/lib/tasks/decidim/voca/voca_sync_locales.rake +10 -0
- data/lib/tasks/decidim/voca/voca_upgrade.rake +13 -0
- data/lib/tasks/decidim/voca/voca_webpacker.rake +58 -0
- metadata +247 -55
- data/app/assets/config/voca_manifest.js +0 -0
- data/app/assets/images/decidim/voca/icon.svg +0 -1
- data/app/commands/decidim/voca/organization/command.rb +0 -16
- data/app/commands/decidim/voca/organization/organization_command.rb +0 -17
- data/app/commands/decidim/voca/organization/update_color_command.rb +0 -35
- data/app/commands/decidim/voca/organization/update_environment_command.rb +0 -23
- data/app/commands/decidim/voca/organization/update_feature_command.rb +0 -32
- data/app/commands/decidim/voca/organization/update_file_upload_command.rb +0 -45
- data/app/commands/decidim/voca/organization/update_locale_command.rb +0 -53
- data/app/commands/decidim/voca/organization/update_naming_command.rb +0 -30
- data/app/commands/decidim/voca/organization/update_permission_command.rb +0 -31
- data/app/commands/decidim/voca/organization/update_smtp_command.rb +0 -51
- data/app/jobs/decidim/voca/command_job.rb +0 -36
- data/app/jobs/decidim/voca/webhook_notifier_job.rb +0 -57
- data/app/rpc/decidim/voca/decidim_service_controller.rb +0 -68
- data/app/rpc/decidim/voca/rpc/enum_casting.rb +0 -58
- data/app/rpc/decidim/voca/rpc/get_settings.rb +0 -144
- data/app/rpc/decidim/voca/rpc/health.rb +0 -18
- data/app/rpc/decidim/voca/rpc/seed_admin.rb +0 -75
- data/app/rpc/decidim/voca/rpc/set_settings.rb +0 -56
- data/app/rpc/decidim/voca/rpc/setup_db.rb +0 -38
- data/config/environments/development.rb +0 -6
- data/config/spring.rb +0 -2
- data/lib/decidim/voca/admin.rb +0 -10
- data/lib/decidim/voca/admin_engine.rb +0 -27
- data/lib/decidim/voca/backup/app_backup.rb +0 -169
- data/lib/decidim/voca/backup/app_decrypt_backup_file.rb +0 -50
- data/lib/decidim/voca/backup/app_encrypt_backup_file.rb +0 -49
- data/lib/decidim/voca/backup/app_upload_to_s3.rb +0 -49
- data/lib/decidim/voca/middleware/dynamic_config_middleware.rb +0 -42
- data/lib/decidim/voca/rpc/decidim_pb.rb +0 -134
- data/lib/decidim/voca/rpc/decidim_services_pb.rb +0 -30
- data/lib/decidim/voca/test/factories.rb +0 -9
- data/lib/decidim/voca/updater.rb +0 -50
- data/lib/tasks/voca.rake +0 -88
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import UploadModal from "src/decidim/direct_uploads/upload_modal";
|
|
2
|
+
import { escapeHtml } from "src/decidim/utilities/text";
|
|
3
|
+
|
|
4
|
+
const updateModalTitle = (modal) => {
|
|
5
|
+
if (modal.uploadItems.children.length === 0) {
|
|
6
|
+
modal.modalTitle.innerHTML = modal.modalTitle.dataset.addlabel;
|
|
7
|
+
} else {
|
|
8
|
+
modal.modalTitle.innerHTML = modal.modalTitle.dataset.editlabel;
|
|
9
|
+
}
|
|
10
|
+
modal.updateDropZone();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const updateActiveUploads = (modal) => {
|
|
14
|
+
// remove the default image block, if exists
|
|
15
|
+
const defaultFile = document.getElementById(`default-active-${modal.modal.id}`)
|
|
16
|
+
if (defaultFile) {
|
|
17
|
+
defaultFile.remove()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const files = document.querySelector(`[data-active-uploads=${modal.modal.id}]`)
|
|
21
|
+
const previousId = Array.from(files.querySelectorAll("[type=hidden][id]"))
|
|
22
|
+
const isMultiple = modal.options.multiple
|
|
23
|
+
const isTitled = modal.options.titled
|
|
24
|
+
|
|
25
|
+
// fastest way to clean children nodes
|
|
26
|
+
files.textContent = ""
|
|
27
|
+
|
|
28
|
+
// divide the items between those will gonna be removed, and added
|
|
29
|
+
const [removeFiles, addFiles] = [modal.items.filter(({ removable }) => removable), modal.items.filter(({ removable }) => !removable)]
|
|
30
|
+
|
|
31
|
+
addFiles.forEach((file, ix) => {
|
|
32
|
+
let title = file.name
|
|
33
|
+
|
|
34
|
+
let hidden = ""
|
|
35
|
+
if (file.hiddenField) {
|
|
36
|
+
// if there is hiddenField, this file is new
|
|
37
|
+
let fileField = null;
|
|
38
|
+
if (isMultiple) {
|
|
39
|
+
fileField = `${modal.options.resourceName}[${modal.options.addAttribute}][${ix}][file]`
|
|
40
|
+
} else if (isTitled) {
|
|
41
|
+
fileField = `${modal.options.resourceName}[${modal.options.addAttribute}][file]`
|
|
42
|
+
} else {
|
|
43
|
+
fileField = `${modal.options.resourceName}[${modal.options.addAttribute}]`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
hidden = `<input type="hidden" name="${fileField}" value="${file.hiddenField}" />`
|
|
47
|
+
} else {
|
|
48
|
+
// otherwise, we keep the attachmentId
|
|
49
|
+
let fileField = null;
|
|
50
|
+
if (isMultiple) {
|
|
51
|
+
fileField = `${modal.options.resourceName}[${modal.options.addAttribute}][${ix}][id]`;
|
|
52
|
+
} else if (isTitled) {
|
|
53
|
+
fileField = `${modal.options.resourceName}[${modal.options.addAttribute}][id]`;
|
|
54
|
+
} else {
|
|
55
|
+
fileField = `${modal.options.resourceName}[${modal.options.addAttribute}]`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// convert all node attributes to string
|
|
59
|
+
const attributes = Array.from(previousId.find(({ id }) => id === file.attachmentId).attributes).reduce((acc, { name, value }) => `${acc} ${name}="${value}"`, "")
|
|
60
|
+
hidden = `<input ${attributes} />`
|
|
61
|
+
hidden += `<input type="hidden" name="${fileField}" value="${file.attachmentId}" />`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (isTitled) {
|
|
65
|
+
const titleValue = modal.modal.querySelectorAll('input[type="text"]')[ix].value
|
|
66
|
+
// NOTE - Renaming the attachment is not supported when multiple uploader is disabled
|
|
67
|
+
const titleField = isMultiple
|
|
68
|
+
? `${modal.options.resourceName}[${modal.options.addAttribute}][${ix}][title]`
|
|
69
|
+
: `${modal.options.resourceName}[${modal.options.addAttribute}][title]`
|
|
70
|
+
hidden += `<input type="hidden" name="${titleField}" value="${escapeHtml(titleValue)}" />`
|
|
71
|
+
|
|
72
|
+
title = titleValue
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const attachmentIdOrHiddenField = file.attachmentId
|
|
76
|
+
? `data-attachment-id="${file.attachmentId}"`
|
|
77
|
+
: `data-hidden-field="${file.hiddenField}"`
|
|
78
|
+
|
|
79
|
+
const template = `
|
|
80
|
+
<div ${attachmentIdOrHiddenField} data-filename="${escapeHtml(file.name)}" data-title="${escapeHtml(title)}">
|
|
81
|
+
${(/image/).test(file.type) && "<div><img src=\"data:,\" alt=\"\" /></div>" || ""}
|
|
82
|
+
<p>${escapeHtml(title)}</p>
|
|
83
|
+
${hidden}
|
|
84
|
+
</div>
|
|
85
|
+
`
|
|
86
|
+
|
|
87
|
+
const div = document.createElement("div")
|
|
88
|
+
div.innerHTML = template.trim()
|
|
89
|
+
|
|
90
|
+
const container = div.firstChild
|
|
91
|
+
|
|
92
|
+
modal.autoloadImage(container, file)
|
|
93
|
+
|
|
94
|
+
files.appendChild(container)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
removeFiles.forEach(() => {
|
|
98
|
+
const div = document.createElement("div")
|
|
99
|
+
div.innerHTML = `<input name='${modal.options.resourceName}[remove_${modal.button.name}]' type="hidden" value="true">`
|
|
100
|
+
files.appendChild(div.firstChild)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
modal.updateAddAttachmentsButton();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const highlightDropzone = (modal) => {
|
|
107
|
+
modal.emptyItems.classList.add("is-dragover");
|
|
108
|
+
modal.uploadItems.classList.add("is-dragover");
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const resetDropzone = (modal) => {
|
|
112
|
+
modal.emptyItems.classList.remove("is-dragover");
|
|
113
|
+
modal.uploadItems.classList.remove("is-dragover");
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const registeredModals = {};
|
|
117
|
+
|
|
118
|
+
export const initializeUploadFields = function(attachmentButtons) {
|
|
119
|
+
|
|
120
|
+
attachmentButtons.forEach((attachmentButton) => {
|
|
121
|
+
|
|
122
|
+
if (attachmentButton.dataset.uploadInitialized) return;
|
|
123
|
+
attachmentButton.dataset.uploadInitialized = "true";
|
|
124
|
+
|
|
125
|
+
const modal = new UploadModal(attachmentButton);
|
|
126
|
+
|
|
127
|
+
registeredModals[attachmentButton.id] = modal;
|
|
128
|
+
|
|
129
|
+
// append to the modal items array those files already validated (only in first pageload)
|
|
130
|
+
const files = document.querySelector(`[data-active-uploads=${modal.modal.id}]`);
|
|
131
|
+
[...files.children].forEach((child) => modal.preloadFiles(child));
|
|
132
|
+
|
|
133
|
+
// whenever the input fields changes, process the files
|
|
134
|
+
modal.input.addEventListener("change", (event) => modal.uploadFiles(event.target.files));
|
|
135
|
+
|
|
136
|
+
// update the modal title if there are files uploaded and load files (if previously deleted after clicking cancel)
|
|
137
|
+
modal.button.addEventListener("click", (event) => event.preventDefault() || (modal.items.length === 0 && [...files.children].forEach((child) => child.tagName === "DIV" && modal.preloadFiles(child))) || updateModalTitle(modal));
|
|
138
|
+
|
|
139
|
+
// avoid browser to open the file
|
|
140
|
+
modal.dropZone.addEventListener("dragover", (event) => event.preventDefault() || highlightDropzone(modal));
|
|
141
|
+
modal.dropZone.addEventListener("dragleave", () => resetDropzone(modal));
|
|
142
|
+
// avoid browser to open the file and then, process the files
|
|
143
|
+
modal.dropZone.addEventListener("drop", (event) => event.preventDefault() || resetDropzone(modal) || modal.uploadFiles(event.dataTransfer.files));
|
|
144
|
+
|
|
145
|
+
// update the DOM with the validated items from the modal
|
|
146
|
+
modal.saveButton.addEventListener("click", (event) => event.preventDefault() || updateActiveUploads(modal));
|
|
147
|
+
// remove the uploaded files if cancel button is clicked
|
|
148
|
+
modal.cancelButton.addEventListener("click", (event) => event.preventDefault() || modal.cleanAllFiles());
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import editorBudgetField from "../proposal_custom_fields/editor_budget_field";
|
|
2
|
+
import editorUploadField from "../proposal_custom_fields/editor_upload_field";
|
|
3
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
4
|
+
editorBudgetField();
|
|
5
|
+
// If current page ends with proposal_private_custom_fields, load upload field module
|
|
6
|
+
editorUploadField();
|
|
7
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
8
|
+
const forceAwesomeAttach = urlParams.has("force_awesome_attach_file");
|
|
9
|
+
|
|
10
|
+
if (
|
|
11
|
+
forceAwesomeAttach ||
|
|
12
|
+
window.location.pathname.endsWith("proposal_private_custom_fields")
|
|
13
|
+
) {
|
|
14
|
+
editorUploadField();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import getProposalForm from "./utils/get_proposal_form";
|
|
2
|
+
import {initializeUploadFields, registeredModals, updateActiveUploads } from "src/decidim/direct_uploads/upload_field";
|
|
3
|
+
|
|
4
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
5
|
+
const attachmentButtons = document.querySelectorAll("#proposal_attachments_button");
|
|
6
|
+
|
|
7
|
+
initializeUploadFields(attachmentButtons);
|
|
8
|
+
|
|
9
|
+
const $form = getProposalForm();
|
|
10
|
+
if (!$form) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const $useCameraField = $form.find(".use_camera__input");
|
|
15
|
+
if ($useCameraField.length <= 0) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const $attachmentButton = $form.find("#proposal_attachments_button")
|
|
20
|
+
|
|
21
|
+
const modal = registeredModals[$attachmentButton[0].id];
|
|
22
|
+
|
|
23
|
+
if (!modal) {
|
|
24
|
+
console.warn("No modal found for attachment button");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// Listen on emptyItems classList change to update the dropzone
|
|
28
|
+
const observer = new MutationObserver((mutations) => {
|
|
29
|
+
updateActiveUploads(modal);
|
|
30
|
+
});
|
|
31
|
+
observer.observe(modal.emptyItems, {
|
|
32
|
+
attributes: true,
|
|
33
|
+
attributeFilter: ["class"],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
$useCameraField.on("change", function () {
|
|
37
|
+
modal.uploadFiles(this.files);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get current position from browser, trying to get a < 100m accuracy
|
|
3
|
+
* @returns {Promise<GeolocationPosition>}
|
|
4
|
+
*/
|
|
5
|
+
const getCurrentPosition = async () => {
|
|
6
|
+
let retry = 0;
|
|
7
|
+
let position = null;
|
|
8
|
+
while (!position || (retry < 3 && position.coords.accuracy > 100)) {
|
|
9
|
+
position = await new Promise((resolve, reject) => {
|
|
10
|
+
navigator.geolocation.getCurrentPosition(resolve, reject, {
|
|
11
|
+
enableHighAccuracy: true,
|
|
12
|
+
timeout: 10000,
|
|
13
|
+
maximumAge: 60000,
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
retry++;
|
|
17
|
+
}
|
|
18
|
+
return position;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default getCurrentPosition;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the first proposal form, if not found, return null
|
|
3
|
+
* @returns {jQuery|null}
|
|
4
|
+
*/
|
|
5
|
+
const getProposalForm = () => {
|
|
6
|
+
const match = $("form.new_proposal,form.edit_proposal").first();
|
|
7
|
+
if (match.length <= 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return match;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default getProposalForm;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if we are loading current location
|
|
3
|
+
* @param {jQuery} $button
|
|
4
|
+
* @returns {boolean}
|
|
5
|
+
*/
|
|
6
|
+
export const isLoading = ($button) => {
|
|
7
|
+
return $button.is(":disabled");
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Set loading state for a list of fields
|
|
12
|
+
* @param {jQuery[]} $fields
|
|
13
|
+
* @param {boolean} loading
|
|
14
|
+
*/
|
|
15
|
+
export const setLoading = ($fields, loading) => {
|
|
16
|
+
$fields.forEach(($field) => {
|
|
17
|
+
if (loading) {
|
|
18
|
+
$field.attr("disabled", "disabled");
|
|
19
|
+
} else {
|
|
20
|
+
$field.removeAttr("disabled");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reverse geocode coordinates to an address
|
|
3
|
+
* @param {Record<"latitude" | "longitude", number>} coords
|
|
4
|
+
* @returns {Promise<string|null>}
|
|
5
|
+
*/
|
|
6
|
+
const locateCoordinates = async (coords) => {
|
|
7
|
+
const result = await new Promise((resolve, reject) => {
|
|
8
|
+
$.post(
|
|
9
|
+
"/locate",
|
|
10
|
+
{
|
|
11
|
+
latitude: coords.latitude,
|
|
12
|
+
longitude: coords.longitude,
|
|
13
|
+
},
|
|
14
|
+
(data) => {
|
|
15
|
+
resolve(data);
|
|
16
|
+
},
|
|
17
|
+
"json"
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
return result?.address || null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default locateCoordinates;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import renderBudget from "./render_budget_field";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Override the custom fields renderer to add our own custom fields.
|
|
5
|
+
* This is done by using a Facade other the original renderer.
|
|
6
|
+
*/
|
|
7
|
+
export default class CustomFieldRendererOverride {
|
|
8
|
+
constructor(customFieldsRenderer) {
|
|
9
|
+
if (!customFieldsRenderer) {
|
|
10
|
+
throw new Error("customFieldsRenderer is undefined");
|
|
11
|
+
}
|
|
12
|
+
this.renderer = customFieldsRenderer;
|
|
13
|
+
this.rendererDataToXML = this.renderer.dataToXML;
|
|
14
|
+
this.renderer.dataToXML = this.dataToXML.bind(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get $element() {
|
|
18
|
+
return this.renderer.$element;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
filterByType(data, matchType) {
|
|
22
|
+
return data.filter(({ type }) => {
|
|
23
|
+
return type === matchType;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Takes JSON object data, and transform it in a XML document (valid HTML string)
|
|
29
|
+
* This methods uses only dd, dt, and div tags to be compatible with decidim sanitization.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} data
|
|
32
|
+
* @returns {Promise<string>} String to save the field and render it in the proposal body without further computation.
|
|
33
|
+
*/
|
|
34
|
+
async dataToXML(data) {
|
|
35
|
+
// Get budget fields, to be able to customize rendering after
|
|
36
|
+
// original rendering.
|
|
37
|
+
const budgetData = this.filterByType(data, "budget");
|
|
38
|
+
const attachFileData = this.filterByType(data, "attachFile");
|
|
39
|
+
await Promise.all(
|
|
40
|
+
attachFileData.map(async (field) => {
|
|
41
|
+
const { userData, name } = field;
|
|
42
|
+
if (userData && userData.length > 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const $input = $(`input[name="${name}"]`);
|
|
47
|
+
if ($input.prop("type") === "file") {
|
|
48
|
+
const url = await this.uploadFile(name);
|
|
49
|
+
if (url) {
|
|
50
|
+
field.userData = [url];
|
|
51
|
+
field.value = url;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Call original renderer
|
|
58
|
+
const $xml = $(this.rendererDataToXML(data));
|
|
59
|
+
// Customize rendering for the budget fields
|
|
60
|
+
budgetData.forEach((field) => {
|
|
61
|
+
const fieldId = field.name;
|
|
62
|
+
const $dd = $xml.find(`dd#${fieldId} > div`);
|
|
63
|
+
$dd.html(renderBudget(field.userData, field));
|
|
64
|
+
});
|
|
65
|
+
return $xml.html();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async uploadFile(inputName) {
|
|
69
|
+
const $input = $(`input[name="${inputName}"]`);
|
|
70
|
+
if (!$input.attr("type") === "file") {
|
|
71
|
+
throw new Error(`input[name="${inputName}"] is not a file input.`);
|
|
72
|
+
}
|
|
73
|
+
const file = $input.prop("files")[0];
|
|
74
|
+
if (!file) {
|
|
75
|
+
console.warn(`input[name="${inputName}"] has no file, skipping upload`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const formData = new FormData();
|
|
79
|
+
formData.append("file", file);
|
|
80
|
+
return await new Promise((resolve, reject) => {
|
|
81
|
+
$.ajax({
|
|
82
|
+
url: "/editor_files",
|
|
83
|
+
type: "POST",
|
|
84
|
+
cache: false,
|
|
85
|
+
data: formData,
|
|
86
|
+
dataType: "json",
|
|
87
|
+
jsonp: false,
|
|
88
|
+
processData: false,
|
|
89
|
+
contentType: false,
|
|
90
|
+
async: false,
|
|
91
|
+
headers: { "X-CSRF-Token": this.csrfToken() },
|
|
92
|
+
})
|
|
93
|
+
.done((resp) => {
|
|
94
|
+
const { url = "" } = resp;
|
|
95
|
+
if (!url) {
|
|
96
|
+
resolve(null);
|
|
97
|
+
} else {
|
|
98
|
+
resolve(url);
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
.fail(reject);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
csrfToken() {
|
|
106
|
+
return $('meta[name="csrf-token"]').attr("content");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Defer to CustomFieldsRenderer#fixBuggyFields
|
|
111
|
+
*/
|
|
112
|
+
fixBuggyFields() {
|
|
113
|
+
return this.renderer.fixBuggyFields();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Overrides CustomFieldsRenderer#storeData to
|
|
118
|
+
* allow dataToXML to be async.
|
|
119
|
+
*/
|
|
120
|
+
async storeData() {
|
|
121
|
+
if (!this.renderer.$element) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const $form = this.renderer.$element.closest("form");
|
|
125
|
+
const $body = $form.find(
|
|
126
|
+
`input[name="${this.renderer.$element.data("name")}"]`
|
|
127
|
+
);
|
|
128
|
+
if ($body.length && this.renderer.instance) {
|
|
129
|
+
this.renderer.spec = this.renderer.instance.userData;
|
|
130
|
+
$body.val(await this.dataToXML(this.renderer.spec));
|
|
131
|
+
this.renderer.$element.data("spec", this.renderer.spec);
|
|
132
|
+
}
|
|
133
|
+
console.log(
|
|
134
|
+
"storeData spec",
|
|
135
|
+
this.spec,
|
|
136
|
+
"$body",
|
|
137
|
+
$body,
|
|
138
|
+
"$form",
|
|
139
|
+
$form,
|
|
140
|
+
"this",
|
|
141
|
+
this
|
|
142
|
+
);
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Defer to CustomFieldsRenderer#init
|
|
148
|
+
*/
|
|
149
|
+
init($element) {
|
|
150
|
+
return this.renderer.init($element);
|
|
151
|
+
}
|
|
152
|
+
}
|