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.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +161 -161
  3. data/README.md +42 -133
  4. data/Rakefile +46 -39
  5. data/app/cells/decidim/footer_topics/show_overrides.erb +8 -0
  6. data/app/cells/decidim/meetings/dates_and_map/show_overrides.erb +23 -0
  7. data/app/commands/decidim/voca/admin/code_census/save_code_list.rb +34 -0
  8. data/app/commands/decidim/voca/code_census/confirm_code_authorization.rb +16 -0
  9. data/app/commands/decidim/voca/create_editor_file.rb +36 -0
  10. data/app/commands/decidim/voca/rack_attack_configurator.rb +244 -0
  11. data/app/commands/decidim/voca/sync_redis_routing.rb +120 -0
  12. data/app/commands/decidim/voca/user_fields_configurator.rb +40 -0
  13. data/app/controllers/decidim/voca/admin/application_controller.rb +4 -6
  14. data/app/controllers/decidim/voca/admin/code_census/code_lists_controller.rb +40 -0
  15. data/app/controllers/decidim/voca/application_controller.rb +4 -6
  16. data/app/controllers/decidim/voca/code_census/authorizations_controller.rb +53 -0
  17. data/app/controllers/decidim/voca/editor_files_controller.rb +47 -0
  18. data/app/controllers/decidim/voca/geolocation_controller.rb +32 -0
  19. data/app/forms/decidim/voca/admin/code_census/code_list_form.rb +21 -0
  20. data/app/forms/decidim/voca/admin/organization_config_form.rb +24 -0
  21. data/app/forms/decidim/voca/code_census/code_form.rb +41 -0
  22. data/app/forms/decidim/voca/editor_file_form.rb +18 -0
  23. data/app/jobs/decidim/voca/machine_translate_awesome_menu_label_job.rb +63 -0
  24. data/app/jobs/decidim/voca/machine_translate_component_setting_job.rb +58 -0
  25. data/app/jobs/decidim/voca/machine_translate_content_block_setting_job.rb +85 -0
  26. data/app/models/decidim/voca/conversation_uuid.rb +18 -0
  27. data/app/models/decidim/voca/editor_file.rb +18 -0
  28. data/app/models/decidim/voca/validation_code.rb +13 -0
  29. data/app/overrides/admin_add_machine_translation_flag.rb +40 -0
  30. data/app/overrides/insert_assets.rb +26 -0
  31. data/app/overrides/insert_weglot_scripts.rb +60 -0
  32. data/app/overrides/proposal_camera.rb +18 -0
  33. data/app/overrides/show_votes.rb +27 -0
  34. data/app/overrides/voca_footer.rb +52 -0
  35. data/app/packs/entrypoints/admin-decidim-voca.js +2 -0
  36. data/app/packs/entrypoints/admin-decidim-voca.scss +1 -0
  37. data/app/packs/entrypoints/decidim-voca-fixes.scss +1 -0
  38. data/app/packs/entrypoints/decidim-voca.js +1 -0
  39. data/app/packs/entrypoints/decidim-voca.scss +1 -0
  40. data/app/packs/images/voca-logo-primary-x3.png +0 -0
  41. data/app/packs/src/decidim/direct_uploads/upload_field.js +150 -0
  42. data/app/packs/src/decidim/voca/admin/voca.js +16 -0
  43. data/app/packs/src/decidim/voca/proposal_better_ux/use_camera_button.js +39 -0
  44. data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_current_position.js +21 -0
  45. data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_proposal_form.js +13 -0
  46. data/app/packs/src/decidim/voca/proposal_better_ux/utils/loading.js +23 -0
  47. data/app/packs/src/decidim/voca/proposal_better_ux/utils/locate_coordinates.js +23 -0
  48. data/app/packs/src/decidim/voca/proposal_custom_fields/custom_field_renderer_override.js +152 -0
  49. data/app/packs/src/decidim/voca/proposal_custom_fields/editor_budget_field.js +329 -0
  50. data/app/packs/src/decidim/voca/proposal_custom_fields/editor_upload_field.js +85 -0
  51. data/app/packs/src/decidim/voca/proposal_custom_fields/proposal_custom_fields.js +96 -0
  52. data/app/packs/src/decidim/voca/proposal_custom_fields/render_budget_field.js +76 -0
  53. data/app/packs/src/decidim/voca/proposal_fields/render_budget_field.js +76 -0
  54. data/app/packs/src/decidim/voca/questionnaire/scroll_questionnaire_steps_to_top.js +18 -0
  55. data/app/packs/src/decidim/voca/voca.js +4 -0
  56. data/app/packs/src/decidim/voca/weglot/index.js +13 -0
  57. data/app/packs/src/decidim/voca/weglot/start_weglot.js +112 -0
  58. data/app/packs/src/decidim/voca/weglot/switcher.js +92 -0
  59. data/app/packs/src/decidim/voca/weglot/wait_for_weglot.js +10 -0
  60. data/app/packs/stylesheets/decidim/voca/_custom_proposal_fields.scss +111 -0
  61. data/app/packs/stylesheets/decidim/voca/_decidim_voca.scss +5 -0
  62. data/app/packs/stylesheets/decidim/voca/_decidim_voca_fixes.scss +25 -0
  63. data/app/packs/stylesheets/decidim/voca/_primary_footer.scss +77 -0
  64. data/app/packs/stylesheets/decidim/voca/_proposal_camera.scss +14 -0
  65. data/app/packs/stylesheets/decidim/voca/_weglot.scss +61 -0
  66. data/app/packs/stylesheets/decidim/voca/admin/_decidim_voca.scss +5 -0
  67. data/app/packs/stylesheets/decidim/voca/admin/_full_machine_translation.scss +34 -0
  68. data/app/permissions/decidim/voca/admin/permissions.rb +31 -0
  69. data/app/permissions/decidim/voca/permissions.rb +17 -0
  70. data/app/views/decidim/voca/admin/code_census/authorizations/new.html.erb +33 -0
  71. data/app/views/decidim/voca/admin/code_census/code_lists/edit.html.erb +27 -0
  72. data/app/views/decidim/voca/code_census/authorizations/new.html.erb +24 -0
  73. data/app/views/decidim/voca/deepl/overrides/_admin_machine_translation_alert.html.erb +14 -0
  74. data/app/views/decidim/voca/rack_attack/_blocked.html.erb +151 -0
  75. data/app/views/decidim/voca/weglot/_js_configuration.html.erb +14 -0
  76. data/app/views/decidim/voca/weglot/_locale_switcher.html.erb +14 -0
  77. data/app/views/decidim/voca/weglot/_locale_switcher_mobile.erb +14 -0
  78. data/app/views/decidim/voca/weglot/_topbar_locale_switcher.html.erb +14 -0
  79. data/config/assets.rb +12 -0
  80. data/config/i18n-tasks.yml +14 -5
  81. data/config/locales/cs.yml +94 -0
  82. data/config/locales/custom_fields.cs.yml +30 -0
  83. data/config/locales/custom_fields.en.yml +41 -0
  84. data/config/locales/custom_fields.fr.yml +30 -0
  85. data/config/locales/custom_fields.it.yml +30 -0
  86. data/config/locales/en.yml +97 -4
  87. data/config/locales/fr.yml +102 -0
  88. data/config/locales/it.yml +94 -0
  89. data/lib/decidim/voca/awesome_menu_label_machine_translation.rb +73 -0
  90. data/lib/decidim/voca/awesome_menu_labels.rb +28 -0
  91. data/lib/decidim/voca/code_census/admin_engine.rb +22 -0
  92. data/lib/decidim/voca/code_census/engine.rb +29 -0
  93. data/lib/decidim/voca/code_census/workflow.rb +7 -0
  94. data/lib/decidim/voca/code_census.rb +4 -0
  95. data/lib/decidim/voca/component_setting_manifest.rb +27 -0
  96. data/lib/decidim/voca/component_setting_pending_locales.rb +33 -0
  97. data/lib/decidim/voca/component_translated_settings_machine_translation.rb +86 -0
  98. data/lib/decidim/voca/configuration.rb +23 -0
  99. data/lib/decidim/voca/content_block_setting_manifest.rb +67 -0
  100. data/lib/decidim/voca/content_block_translated_settings_machine_translation.rb +100 -0
  101. data/lib/decidim/voca/deepl/deepl_active_job_context.rb +27 -0
  102. data/lib/decidim/voca/deepl/deepl_context.rb +78 -0
  103. data/lib/decidim/voca/deepl/deepl_form_builder_overrides.rb +82 -0
  104. data/lib/decidim/voca/deepl/deepl_machine_translator.rb +61 -0
  105. data/lib/decidim/voca/deepl/deepl_middleware.rb +83 -0
  106. data/lib/decidim/voca/deepl/engine_config.rb +181 -0
  107. data/lib/decidim/voca/deepl/settings.rb +75 -0
  108. data/lib/decidim/voca/deepl/translation_bar_overrides.rb +20 -0
  109. data/lib/decidim/voca/deepl.rb +10 -0
  110. data/lib/decidim/voca/engine.rb +320 -11
  111. data/lib/decidim/voca/export/comment_serializer_localized_csv.rb +34 -0
  112. data/lib/decidim/voca/export/csv_with_locale_transformer.rb +53 -0
  113. data/lib/decidim/voca/export/proposal_serializer_localized_csv.rb +45 -0
  114. data/lib/decidim/voca/export/user_answers_serializer_localized_csv.rb +54 -0
  115. data/lib/decidim/voca/installation.rb +33 -0
  116. data/lib/decidim/voca/machine_translation/translate_string.rb +121 -0
  117. data/lib/decidim/voca/machine_translation_human_source.rb +29 -0
  118. data/lib/decidim/voca/machine_translation_resource_job_voca.rb +65 -0
  119. data/lib/decidim/voca/organization_voca_extensions.rb +31 -0
  120. data/lib/decidim/voca/overrides/csv_export_serializers.rb +51 -0
  121. data/lib/decidim/voca/overrides/meetings/dates_and_map_cell_overrides.rb +20 -0
  122. data/lib/decidim/voca/overrides/menu_breadcrumb_last_activity_cache.rb +31 -0
  123. data/lib/decidim/voca/overrides/mod_secure/conversation_controller_overrides.rb +19 -0
  124. data/lib/decidim/voca/overrides/mod_secure/conversation_sanitize.rb +29 -0
  125. data/lib/decidim/voca/overrides/mod_secure/conversation_uuid.rb +34 -0
  126. data/lib/decidim/voca/overrides/mod_secure/user_conversations_redirect_overrides.rb +53 -0
  127. data/lib/decidim/voca/overrides/mod_secure/user_profile_verification_override.rb +31 -0
  128. data/lib/decidim/voca/overrides/newsletter_helper_overrides.rb +30 -0
  129. data/lib/decidim/voca/overrides/resource_presenter_overrides.rb +30 -0
  130. data/lib/decidim/voca/overrides/sanitize_helper_overrides.rb +39 -0
  131. data/lib/decidim/voca/sync_locales/README.md +13 -0
  132. data/lib/decidim/voca/sync_locales/awesome_menu_label_sync.rb +89 -0
  133. data/lib/decidim/voca/sync_locales/command.rb +54 -0
  134. data/lib/decidim/voca/sync_locales/component_setting_sync.rb +72 -0
  135. data/lib/decidim/voca/sync_locales/content_block_setting_sync.rb +86 -0
  136. data/lib/decidim/voca/sync_locales/field_hash_normalizer.rb +98 -0
  137. data/lib/decidim/voca/sync_locales/locale_context.rb +589 -0
  138. data/lib/decidim/voca/sync_locales/machine_translation_enqueuer.rb +60 -0
  139. data/lib/decidim/voca/sync_locales/relation_lint_runner.rb +55 -0
  140. data/lib/decidim/voca/sync_locales/runner.rb +352 -0
  141. data/lib/decidim/voca/sync_locales.rb +11 -0
  142. data/lib/decidim/voca/update_column_without_callbacks.rb +21 -0
  143. data/lib/decidim/voca/version.rb +13 -3
  144. data/lib/decidim/voca.rb +40 -14
  145. data/lib/decidim-voca.rb +5 -0
  146. data/lib/tasks/decidim/voca/voca_anonymize.rake +41 -0
  147. data/lib/tasks/decidim/voca/voca_clean_machine_translations.rake +22 -0
  148. data/lib/tasks/decidim/voca/voca_enhanced_invalid_record.rake +141 -0
  149. data/lib/tasks/decidim/voca/voca_install_migration.rake +45 -0
  150. data/lib/tasks/decidim/voca/voca_relation_lint.rake +12 -0
  151. data/lib/tasks/decidim/voca/voca_sync_locales.rake +10 -0
  152. data/lib/tasks/decidim/voca/voca_upgrade.rake +13 -0
  153. data/lib/tasks/decidim/voca/voca_webpacker.rake +58 -0
  154. metadata +247 -55
  155. data/app/assets/config/voca_manifest.js +0 -0
  156. data/app/assets/images/decidim/voca/icon.svg +0 -1
  157. data/app/commands/decidim/voca/organization/command.rb +0 -16
  158. data/app/commands/decidim/voca/organization/organization_command.rb +0 -17
  159. data/app/commands/decidim/voca/organization/update_color_command.rb +0 -35
  160. data/app/commands/decidim/voca/organization/update_environment_command.rb +0 -23
  161. data/app/commands/decidim/voca/organization/update_feature_command.rb +0 -32
  162. data/app/commands/decidim/voca/organization/update_file_upload_command.rb +0 -45
  163. data/app/commands/decidim/voca/organization/update_locale_command.rb +0 -53
  164. data/app/commands/decidim/voca/organization/update_naming_command.rb +0 -30
  165. data/app/commands/decidim/voca/organization/update_permission_command.rb +0 -31
  166. data/app/commands/decidim/voca/organization/update_smtp_command.rb +0 -51
  167. data/app/jobs/decidim/voca/command_job.rb +0 -36
  168. data/app/jobs/decidim/voca/webhook_notifier_job.rb +0 -57
  169. data/app/rpc/decidim/voca/decidim_service_controller.rb +0 -68
  170. data/app/rpc/decidim/voca/rpc/enum_casting.rb +0 -58
  171. data/app/rpc/decidim/voca/rpc/get_settings.rb +0 -144
  172. data/app/rpc/decidim/voca/rpc/health.rb +0 -18
  173. data/app/rpc/decidim/voca/rpc/seed_admin.rb +0 -75
  174. data/app/rpc/decidim/voca/rpc/set_settings.rb +0 -56
  175. data/app/rpc/decidim/voca/rpc/setup_db.rb +0 -38
  176. data/config/environments/development.rb +0 -6
  177. data/config/spring.rb +0 -2
  178. data/lib/decidim/voca/admin.rb +0 -10
  179. data/lib/decidim/voca/admin_engine.rb +0 -27
  180. data/lib/decidim/voca/backup/app_backup.rb +0 -169
  181. data/lib/decidim/voca/backup/app_decrypt_backup_file.rb +0 -50
  182. data/lib/decidim/voca/backup/app_encrypt_backup_file.rb +0 -49
  183. data/lib/decidim/voca/backup/app_upload_to_s3.rb +0 -49
  184. data/lib/decidim/voca/middleware/dynamic_config_middleware.rb +0 -42
  185. data/lib/decidim/voca/rpc/decidim_pb.rb +0 -134
  186. data/lib/decidim/voca/rpc/decidim_services_pb.rb +0 -30
  187. data/lib/decidim/voca/test/factories.rb +0 -9
  188. data/lib/decidim/voca/updater.rb +0 -50
  189. data/lib/tasks/voca.rake +0 -88
@@ -0,0 +1,329 @@
1
+ import throttle from "lodash.throttle";
2
+
3
+ /**
4
+ * Register administration field.
5
+ * Used in administration and in front end, on proposal creation and edition.
6
+ */
7
+ export default function editorBudgetField() {
8
+ if (!window.fbControls) window.fbControls = new Array();
9
+
10
+ window.fbControls.push(function (controlClass) {
11
+ /**
12
+ * Budget field
13
+ * Add line of budget and get a total
14
+ */
15
+ class controlBudgetField extends controlClass {
16
+ static get definition() {
17
+ return {
18
+ icon: "💸",
19
+ i18n: {
20
+ default: "Budget",
21
+ },
22
+ defaultAttrs: {
23
+ currency: {
24
+ label: "Currency",
25
+ value: "€",
26
+ type: "text",
27
+ },
28
+ addLineLabel: {
29
+ label: "Label to add a new line",
30
+ value: "+ new line",
31
+ type: "text",
32
+ },
33
+ totalLabel: {
34
+ label: "Total label",
35
+ value: "Total:",
36
+ type: "text",
37
+ },
38
+ },
39
+ };
40
+ }
41
+ configure() {}
42
+
43
+ ensureMinimumLines(value, required) {
44
+ const lines = value?.lines || [];
45
+ if (!required) {
46
+ return lines;
47
+ }
48
+ const hasLines = value?.lines?.length > 0;
49
+ if (!hasLines) {
50
+ return [...lines, { label: "", price: 0, id: `${+new Date()}` }];
51
+ }
52
+ return lines;
53
+ }
54
+ _renderLine() {}
55
+
56
+ _currentValue() {
57
+ if (this.__currentValue) return this.__currentValue;
58
+ const { value, userData } = this._config();
59
+ const rawValue = userData ? userData[0] : value;
60
+ try {
61
+ return (this.__currentValue = JSON.parse(
62
+ $(rawValue).find("pre").first().html()
63
+ ));
64
+ } catch (e) {
65
+ return (this.__currentValue = {});
66
+ }
67
+ }
68
+
69
+ _config() {
70
+ if (this.__config) return this.__config;
71
+ const {
72
+ value,
73
+ userData,
74
+ name,
75
+ currency = "€",
76
+ addLineLabel = "+ new line",
77
+ } = this.config;
78
+ const { required = false, placeholder = "" } = this.rawConfig;
79
+ return (this.__config = {
80
+ value,
81
+ userData,
82
+ name,
83
+ currency,
84
+ addLineLabel,
85
+ required,
86
+ placeholder,
87
+ });
88
+ }
89
+ /**
90
+ * Get the DOMElements that have handler subscribed
91
+ * @returns {Array<DOMElement>} The DOMElement
92
+ */
93
+ _handlers() {
94
+ if (this.__handlers) return this.__handlers;
95
+ return (this.__handlers = []);
96
+ }
97
+
98
+ _addHandler(handler) {
99
+ this._handlers().push(handler);
100
+ return this;
101
+ }
102
+
103
+ _clearHandlers() {
104
+ this._handlers().forEach((h) => $(h).off());
105
+ this.__handlers = [];
106
+ return this;
107
+ }
108
+
109
+ /**
110
+ * Button to add a new budget line.
111
+ * @returns {DOMElement} The add line button element.
112
+ */
113
+ _renderAddLineBtn(data) {
114
+ const { addLineLabel, name } = this._config();
115
+ const addLine = this.markup("button", addLineLabel, {
116
+ class:
117
+ "formBuilder__budgetField-addLine button button__xs button__secondary",
118
+ });
119
+ $(addLine).on("click", (evt) => {
120
+ evt.preventDefault();
121
+ $(`#${name}-container`).html(
122
+ this._reRender({
123
+ ...data,
124
+ lines: [
125
+ ...data.lines,
126
+ { label: "", price: 0, id: `${+new Date()}` },
127
+ ],
128
+ })
129
+ );
130
+ $(`#${name}-container .formBuilder__budgetField-label`)
131
+ .last()
132
+ .trigger("focus");
133
+ return false;
134
+ });
135
+ this._addHandler(addLine);
136
+ return addLine;
137
+ }
138
+
139
+ /**
140
+ * Render a label input field.
141
+ * This field is always required.
142
+ * @returns {DOMElement} The label input field element.
143
+ */
144
+ _renderLineLabelField(line, index, data) {
145
+ const { name, placeholder } = this._config();
146
+ const inputField = this.markup("input", undefined, {
147
+ class: "formBuilder__budgetField-label",
148
+ type: "text",
149
+ name: `${name}-input[${index}][label]`,
150
+ value: line.label || "",
151
+ placeholder: placeholder,
152
+ required: true,
153
+ });
154
+ $(inputField).on(
155
+ "keyup",
156
+ throttle(function (evt) {
157
+ const newValue = evt.target.value;
158
+ line.label = newValue;
159
+ $(`input#${name}`).val(JSON.stringify(data, null, 2));
160
+ }, 250)
161
+ );
162
+ this._addHandler(inputField);
163
+ return inputField;
164
+ }
165
+
166
+ /**
167
+ * Render a price input field, made of:
168
+ * 1. Input field
169
+ * 2. Currency label
170
+ *
171
+ * This field is always required.
172
+ * @returns {DOMElement} The price input field element.
173
+ */
174
+ _renderLinePriceField(line, index, data) {
175
+ const { currency, name } = this._config();
176
+ const priceField = this.markup("input", undefined, {
177
+ class: "input-group-field formBuilder__budgetField-price",
178
+ required: true,
179
+ type: "number",
180
+ name: `${name}-input[${index}][label]`,
181
+ value: line.price || "",
182
+ });
183
+
184
+ // Update price value on change.
185
+ $(priceField).on(
186
+ "keyup",
187
+ throttle(function (evt) {
188
+ const newValue = evt.target.value;
189
+ line.price = parseInt(newValue, 10);
190
+ $(`input#${name}`).val(JSON.stringify(data, null, 2));
191
+ }, 250)
192
+ );
193
+ this._addHandler(priceField);
194
+ // Return an input group with price field and currency label
195
+ return this.markup(
196
+ "div",
197
+ [
198
+ priceField,
199
+ this.markup("span", currency, {
200
+ class: "input-group-label",
201
+ }),
202
+ ],
203
+ { class: "input-group formBuilder__budgetField-priceGroup" }
204
+ );
205
+ }
206
+
207
+ /**
208
+ * Render a remove line button.
209
+ * If the form is required, the button is disabled if the form has only one line.
210
+ * @returns {DOMElement} The remove line button element.
211
+ */
212
+ _renderRemoveLineBtn(line, index, data) {
213
+ const { name, required } = this._config();
214
+ const canRemove = data.lines.length > 1 || !required;
215
+ const removeLine = this.markup("a", "X", {
216
+ class:
217
+ "button button__xs button__secondary formBuilder__budgetField-removeLine",
218
+ tabIndex: -1,
219
+ disabled: !canRemove,
220
+ role: "button",
221
+ });
222
+ if (canRemove) {
223
+ // Add handle to remove line (else disabled)
224
+ $(removeLine).on("click", (evt) => {
225
+ evt.preventDefault();
226
+ $(`#${name}-container`).html(
227
+ this._reRender({
228
+ ...data,
229
+ lines: data.lines.filter(({ id }) => id !== line.id),
230
+ })
231
+ );
232
+ });
233
+ this._addHandler(removeLine);
234
+ }
235
+ return removeLine;
236
+ }
237
+
238
+ /**
239
+ * Render a line of the form, made of:
240
+ * 1. Label input
241
+ * 2. Price input + Currency label
242
+ * 3. Remove line button
243
+ * */
244
+ _renderLine(line, index, data) {
245
+ const labelInput = this._renderLineLabelField(line, index, data);
246
+ const priceInput = this._renderLinePriceField(line, index, data);
247
+ const removeLine = this._renderRemoveLineBtn(line, index, data);
248
+ return this.markup("div", [labelInput, priceInput, removeLine], {
249
+ class: "formBuilder__budgetField-editor",
250
+ });
251
+ }
252
+
253
+ /**
254
+ * Render the fieldset.
255
+ * Used while handling dynamic changes
256
+ * @param {Object} data - The data to render.
257
+ * @returns {DOMElement} The fieldset element.
258
+ */
259
+ _reRender(data = { lines: [] }) {
260
+ const { required } = this._config();
261
+ data.lines = this.ensureMinimumLines(data, required);
262
+ this._clearHandlers();
263
+ const markupLines = data.lines.map((line, index) =>
264
+ this._renderLine(line, index, data)
265
+ );
266
+ return this.markup(
267
+ "div",
268
+ [...markupLines, this._renderAddLineBtn(data)],
269
+ {
270
+ class:
271
+ "formBuilder__budgetField-container clearfix formBuilder__budgetField-form-editor",
272
+ }
273
+ );
274
+ }
275
+
276
+ /**
277
+ * Render a hidden input to store the current value.
278
+ * @returns {DOMElement} The hidden input element.
279
+ */
280
+ _renderHiddenInput() {
281
+ const { name } = this._config();
282
+ return this.markup("input", undefined, {
283
+ type: "hidden",
284
+ value: JSON.stringify(this._currentValue()),
285
+ name: `${name}`,
286
+ id: `${name}`,
287
+ class: "formBuilder__budgetField-editor-value",
288
+ });
289
+ }
290
+ /**
291
+ * Render a fieldset with the current form, made of:
292
+ * 1. Lines
293
+ * 2. Add line button
294
+ * 3. Hidden input to store the current value.
295
+ * @returns {DOMElement} The fieldset element.
296
+ */
297
+ _renderFieldset() {
298
+ const { name } = this._config();
299
+ return this.markup("fieldset", this._reRender(this._currentValue()), {
300
+ id: `${name}-container`,
301
+ class:
302
+ "formBuilder__budgetField-container clearfix formBuilder__budgetField-form-editor",
303
+ });
304
+ }
305
+
306
+ /**
307
+ * build a text DOM element, supporting other jquery text form-control's
308
+ * @return DOM Element to be injected into the form.
309
+ */
310
+ build() {
311
+ return (this.input = this.markup(
312
+ "div",
313
+ [this._renderFieldset(), this._renderHiddenInput()],
314
+ {
315
+ class: "formBuilder__budgetField formBuilder--stale",
316
+ }
317
+ ));
318
+ }
319
+
320
+ onRender() {
321
+ // Do not render result while editing.
322
+ }
323
+ }
324
+
325
+ // register this control for the following types & text subtypes
326
+ controlClass.register("budget", controlBudgetField);
327
+ return controlBudgetField;
328
+ });
329
+ }
@@ -0,0 +1,85 @@
1
+ export default function editorUploadField() {
2
+ if (!window.fbControls) window.fbControls = new Array();
3
+ window.fbControls.push(function (controlClass) {
4
+ /**
5
+ * Attach one file field.
6
+ */
7
+ class controlAttachFile extends controlClass {
8
+ static get definition() {
9
+ return {
10
+ icon: "🏞️",
11
+ i18n: {
12
+ default: "Attach File",
13
+ removeIconTitle: "Remove file",
14
+ },
15
+ };
16
+ }
17
+ configure() {}
18
+
19
+ i18n(key) {
20
+ return controlAttachFile.definition.i18n[key] || key;
21
+ }
22
+ /**
23
+ * build a text DOM element, supporting other jquery text form-control's
24
+ * @return DOM Element to be injected into the form.
25
+ */
26
+ build() {
27
+ const { value, userData, ...attrs } = this.config;
28
+ const currentValue = value || (userData ? userData[0] : "");
29
+ const inputId = `${this.config.name}-input`;
30
+ const fileControl = this.markup("input", null, {
31
+ ...attrs,
32
+ id: inputId,
33
+ type: "file",
34
+ });
35
+ if (!currentValue) {
36
+ this.input = fileControl;
37
+ } else {
38
+ const removeButton = this.markup(
39
+ "button",
40
+ `<svg xmlns="http://www.w3.org/2000/svg" class="formBuilder__attachFile-icon" viewBox="0 0 512 512">
41
+ <title>${this.i18n("removeIconTitle")}</title>
42
+ <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="64" d="M368 368L144 144M368 144L144 368"/>
43
+ </svg>
44
+ `,
45
+ {
46
+ class: "formBuilder__attachFile-button",
47
+ title: this.i18n("removeIconTitle"),
48
+ alt: "remove",
49
+ }
50
+ );
51
+ const hiddenInput = this.markup("input", currentValue, {
52
+ id: inputId,
53
+ type: "hidden",
54
+ value: currentValue,
55
+ name: this.config.name,
56
+ });
57
+ const filename = currentValue.split("/").pop();
58
+ const link = this.markup("a", filename, {
59
+ href: currentValue,
60
+ target: "_blank",
61
+ class: "formBuilder__attachFile-preview",
62
+ });
63
+ const input = (this.input = this.markup(
64
+ "div",
65
+ [link, hiddenInput, removeButton],
66
+ { class: "formBuilder__attachFile" }
67
+ ));
68
+ $(removeButton).on("click", function (evt) {
69
+ evt.preventDefault();
70
+ $(input).html(fileControl);
71
+ });
72
+ }
73
+ return this.input;
74
+ }
75
+
76
+ onRender() {
77
+ $("#" + this.config.name).html(this.config.value);
78
+ }
79
+ }
80
+
81
+ // register this control for the following types & text subtypes
82
+ controlClass.register("attachFile", controlAttachFile);
83
+ return controlAttachFile;
84
+ });
85
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Public facing javascript
3
+ */
4
+ import CustomFieldRendererOverride from "./custom_field_renderer_override";
5
+ import editorBudgetField from "./editor_budget_field";
6
+ import editorUploadField from "./editor_upload_field";
7
+ /**
8
+ * Wait for DecidimAwesome to be initialized, and then override the custom fields renderer.
9
+ * Will wait for at most 640ms before raising an error.
10
+ * @param {number} retryCount - The number of retries.
11
+ * @returns {Promise} A promise that resolves when DecidimAwesome is initialized.
12
+ */
13
+ const whenDecidimAwesomeInitialized = (retryCount = 0) => {
14
+ return new Promise((resolve, reject) => {
15
+ if (
16
+ window.DecidimAwesome?.CustomFieldsRenderer &&
17
+ window.DecidimAwesome?.PrivateCustomFieldsRenderer &&
18
+ (window.DecidimAwesome?.CustomFieldsRenderer?.$element ||
19
+ window.DecidimAwesome?.PrivateCustomFieldsRenderer?.$element)
20
+ ) {
21
+ resolve();
22
+ } else {
23
+ if (retryCount > 10) {
24
+ return reject("decidim-voca: DecidimAwesome is not initialized");
25
+ }
26
+ console.warn(
27
+ "decidim-voca: DecidimAwesome is not initialized, retrying...."
28
+ );
29
+ setTimeout(() => {
30
+ whenDecidimAwesomeInitialized(retryCount + 1).then(resolve);
31
+ }, 64);
32
+ }
33
+ });
34
+ };
35
+
36
+ document.addEventListener("DOMContentLoaded", () => {
37
+ // subscribe the field in the formBuidler editor.
38
+ // @see https://github.com/kevinchappell/formBuilder/blob/master/src/js/control/custom.js
39
+ // @see https://formbuilder.online/docs/formBuilder/controls/#registering-the-new-types-subtypes
40
+ editorBudgetField();
41
+ editorUploadField();
42
+
43
+ // wait on global DecidimAwesome to be initialized, and then override.
44
+ whenDecidimAwesomeInitialized()
45
+ .then(() => {
46
+ // We monkey patch the custom fields renderer to add our own custom fields
47
+ window.DecidimAwesome.CustomFieldsRenderer =
48
+ new CustomFieldRendererOverride(
49
+ window.DecidimAwesome.CustomFieldsRenderer
50
+ );
51
+ window.DecidimAwesome.PrivateCustomFieldsRenderer =
52
+ new CustomFieldRendererOverride(
53
+ window.DecidimAwesome.PrivateCustomFieldsRenderer
54
+ );
55
+
56
+ const $public = $(".proposal_custom_field:first");
57
+ const $private = $(
58
+ ".proposal_custom_field.proposal_custom_field--private_body:first"
59
+ );
60
+ let $form = null;
61
+ if ($public.length) {
62
+ $form =
63
+ window.DecidimAwesome.CustomFieldsRenderer.$element.closest("form");
64
+ }
65
+ if ($private.length && !$form) {
66
+ $form =
67
+ window.DecidimAwesome.PrivateCustomFieldsRenderer.$element.closest(
68
+ "form"
69
+ );
70
+ }
71
+
72
+ if ($form) {
73
+ $form.off("submit");
74
+ $form.on("submit", async (evt) => {
75
+ evt.preventDefault();
76
+ if (evt.target.checkValidity()) {
77
+ // save current editors
78
+ if ($public.length) {
79
+ await window.DecidimAwesome.CustomFieldsRenderer.storeData();
80
+ }
81
+ if ($private.length) {
82
+ await window.DecidimAwesome.PrivateCustomFieldsRenderer.storeData();
83
+ }
84
+ evt.target.submit();
85
+ } else {
86
+ evt.target.reportValidity();
87
+ }
88
+ });
89
+ }
90
+ })
91
+ .catch(() => {
92
+ console.warn(
93
+ "decidim-voca: DecidimAwesome is not initialized, skipping override"
94
+ );
95
+ });
96
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Render the budget field in the proposal form.
3
+ * @param {string} value JSON string of the budget field value
4
+ * @param {Object} config Configuration object for the budget field
5
+ * @returns {jQuery} a jquery div object
6
+ */
7
+ export default function renderBudget(value, config) {
8
+ let currentValue;
9
+ try {
10
+ currentValue = JSON.parse(value || "{}");
11
+ } catch (e) {
12
+ currentValue = {};
13
+ }
14
+ // Ensure no white line are saved .
15
+ const lines = (currentValue.lines || []).filter(({ label = "" }) => !!label);
16
+ // Add a div container, to be compatible with other formBuilder fields.
17
+ const $container = $("<div />");
18
+ $container.addClass("formBuilder__budgetField-rendered");
19
+
20
+ // Render a hidden tag to store current JSON value for
21
+ // edition purpose. (will parse the content to populate form)
22
+ const $dataContainer = $("<pre />");
23
+ $dataContainer.addClass("hidden");
24
+ $dataContainer.html(JSON.stringify({ ...currentValue, lines }, null, 2));
25
+ $container.append($dataContainer);
26
+
27
+ // Render a table with the budget
28
+ const $table = $("<table />");
29
+ $table.data("json", value);
30
+ $table.addClass("table stack formBuilder__budgetField-table");
31
+ const $tbody = $("<tbody />");
32
+ const $tfoot = $("<tfoot />");
33
+ // Compute lines and total
34
+ let total = 0;
35
+ lines.forEach((line) => {
36
+ const $line = $("<tr />");
37
+ $line.addClass("formBuilder__budgetField-line");
38
+ const $label = $("<td />").prop("id", line.id);
39
+ $label.addClass(
40
+ "formBuilder__budgetField-cell formBuilder__budgetField-cell--label"
41
+ );
42
+ $label.text(line.label);
43
+ $line.append($label);
44
+
45
+ const $price = $("<td />");
46
+ $price.addClass(
47
+ "formBuilder__budgetField-cell formBuilder__budgetField-cell--price"
48
+ );
49
+ $price.append($("<span />").text(line.price));
50
+ $price.append($("<span />").text(` ${config.currency}`));
51
+ $line.append($price);
52
+ total += line.price;
53
+ $tbody.append($line);
54
+ });
55
+ // Add a footer with the total
56
+ $tfoot.append(
57
+ $("<tr/>").append(
58
+ $("<td/>")
59
+ .prop("colspan", 2)
60
+ .addClass(
61
+ "formBuilder__budgetField-cell formBuilder__budgetField-cell--total"
62
+ )
63
+ .append(
64
+ $("<span />")
65
+ .text(config.totalLabel + ` ${total}`)
66
+ .prop("alt", "total")
67
+ )
68
+ .append($("<span />").text(` ${config.currency}`))
69
+ )
70
+ );
71
+ // Compose the table and container
72
+ $table.append($tbody);
73
+ $table.append($tfoot);
74
+ $container.append($table);
75
+ return $container;
76
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Render the budget field in the proposal form.
3
+ * @param {string} value JSON string of the budget field value
4
+ * @param {Object} config Configuration object for the budget field
5
+ * @returns {jQuery} a jquery div object
6
+ */
7
+ export default function renderBudget(value, config) {
8
+ let currentValue;
9
+ try {
10
+ currentValue = JSON.parse(value || "{}");
11
+ } catch (e) {
12
+ currentValue = {};
13
+ }
14
+ // Ensure no white line are saved .
15
+ const lines = (currentValue.lines || []).filter(({ label = "" }) => !!label);
16
+ // Add a div container, to be compatible with other formBuilder fields.
17
+ const $container = $("<div />");
18
+ $container.addClass("formBuilder__budgetField-rendered");
19
+
20
+ // Render a hidden tag to store current JSON value for
21
+ // edition purpose. (will parse the content to populate form)
22
+ const $dataContainer = $("<pre />");
23
+ $dataContainer.addClass("hidden");
24
+ $dataContainer.html(JSON.stringify({ ...currentValue, lines }, null, 2));
25
+ $container.append($dataContainer);
26
+
27
+ // Render a table with the budget
28
+ const $table = $("<table />");
29
+ $table.data("json", value);
30
+ $table.addClass("table stack formBuilder__budgetField-table");
31
+ const $tbody = $("<tbody />");
32
+ const $tfoot = $("<tfoot />");
33
+ // Compute lines and total
34
+ let total = 0;
35
+ lines.forEach((line) => {
36
+ const $line = $("<tr />");
37
+ $line.addClass("formBuilder__budgetField-line");
38
+ const $label = $("<td />").prop("id", line.id);
39
+ $label.addClass(
40
+ "formBuilder__budgetField-cell formBuilder__budgetField-cell--label"
41
+ );
42
+ $label.text(line.label);
43
+ $line.append($label);
44
+
45
+ const $price = $("<td />");
46
+ $price.addClass(
47
+ "formBuilder__budgetField-cell formBuilder__budgetField-cell--price"
48
+ );
49
+ $price.append($("<span />").text(line.price));
50
+ $price.append($("<span />").text(` ${config.currency}`));
51
+ $line.append($price);
52
+ total += line.price;
53
+ $tbody.append($line);
54
+ });
55
+ // Add a footer with the total
56
+ $tfoot.append(
57
+ $("<tr/>").append(
58
+ $("<td/>")
59
+ .prop("colspan", 2)
60
+ .addClass(
61
+ "formBuilder__budgetField-cell formBuilder__budgetField-cell--total"
62
+ )
63
+ .append(
64
+ $("<span />")
65
+ .text(config.totalLabel + ` ${total}`)
66
+ .prop("alt", "total")
67
+ )
68
+ .append($("<span />").text(` ${config.currency}`))
69
+ )
70
+ );
71
+ // Compose the table and container
72
+ $table.append($tbody);
73
+ $table.append($tfoot);
74
+ $container.append($table);
75
+ return $container;
76
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Scrolls the questionnaire step to the top
3
+ */
4
+ document.addEventListener('DOMContentLoaded', () => {
5
+ const stepDivs = document.querySelectorAll('.response-questionnaire__step');
6
+ if (stepDivs.length === 0) { return }
7
+ stepDivs.forEach((stepDiv) => {
8
+ const buttons = stepDiv.querySelectorAll('button');
9
+
10
+ buttons.forEach((button) => {
11
+ button.addEventListener("click", (event) => {
12
+ event.preventDefault();
13
+ const content = document.getElementById('content');
14
+ if (content) { content.scrollIntoView() }
15
+ });
16
+ });
17
+ });
18
+ });
@@ -0,0 +1,4 @@
1
+ import "./proposal_custom_fields/proposal_custom_fields";
2
+ import "./proposal_better_ux/use_camera_button";
3
+ import "./weglot";
4
+ import "./questionnaire/scroll_questionnaire_steps_to_top";
@@ -0,0 +1,13 @@
1
+ import startWeglot from "./start_weglot";
2
+ import switcher from "./switcher";
3
+
4
+ document.addEventListener("DOMContentLoaded", () => {
5
+ startWeglot()
6
+ .then(switcher)
7
+ .then(() => {
8
+ console.log("Voca Weglot: loaded");
9
+ })
10
+ .catch((error) => {
11
+ console.error("Voca Weglot: error", error);
12
+ });
13
+ });