Skip to content

Commit c4f6a22

Browse files
committed
fix modals
1 parent e380c44 commit c4f6a22

File tree

7 files changed

+70
-9
lines changed

7 files changed

+70
-9
lines changed

app/packs/src/decidim/participatory_documents/pdf.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,63 @@ window.InitDocumentManagers = (options) => {
1515
window.currentSuggestionForm.open();
1616
}
1717
});
18+
19+
const exportContent = options.exportModal.querySelector(".content");
20+
const exportCallout = options.exportModal.querySelector(".callout");
21+
const exportButton = options.exportModal.querySelector(".export-button");
22+
const closeButton = options.exportModal.querySelector(".close-button");
23+
24+
options.exportButton.addEventListener("click", (evt) => {
25+
evt.stopPropagation();
26+
exportCallout.classList.remove("alert", "success");
27+
exportCallout.classList.add("hidden");
28+
exportContent.classList.remove("hidden");
29+
exportButton.classList.remove("hidden");
30+
window.Decidim.currentDialogs[options.exportModal.id].open();
31+
});
32+
33+
closeButton.addEventListener("click", (evt) => {
34+
evt.stopPropagation();
35+
window.Decidim.currentDialogs[options.exportModal.id].close();
36+
});
37+
38+
exportButton.addEventListener("click", (evt) => {
39+
evt.stopPropagation();
40+
const token = document.getElementsByName("csrf-token");
41+
fetch(evt.target.dataset.url, {
42+
method: "POST",
43+
headers: {
44+
"Content-Type": "application/json",
45+
"Accept": "application/json",
46+
"X-CSRF-Token": token && token[0].content
47+
},
48+
credentials: "include"
49+
}).
50+
then((response) => {
51+
if (response.ok) {
52+
return response.json();
53+
}
54+
return response.json().then((json) => {
55+
throw new Error(json.message)
56+
});
57+
}).
58+
then((resp) => {
59+
console.log("response ok", resp);
60+
exportButton.classList.add("hidden");
61+
exportContent.classList.add("hidden");
62+
exportCallout.classList.remove("hidden");
63+
exportCallout.classList.add("success");
64+
exportCallout.innerHTML = resp.message;
65+
}).
66+
catch((message) => {
67+
exportButton.classList.add("hidden");
68+
exportContent.classList.add("hidden");
69+
exportCallout.classList.remove("hidden");
70+
exportCallout.classList.add("alert");
71+
exportCallout.innerHTML = message;
72+
console.error("Error exporting", message);
73+
});
74+
});
1875
};
1976

2077
// Call this on an annotation layer to initialize the polygon viewer (public side)

app/packs/src/decidim/participatory_documents/pdf_off.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const openLogin = (evt) => {
2323

2424
window.InitDocumentManagers = (options) => {
2525
options.globalSuggestionsButton.addEventListener("click", openLogin);
26+
options.exportButton.addEventListener("click", openLogin);
2627
};
2728

2829
// Call this on an annotation layer to initialize the polygon viewer (public side)

app/views/decidim/participatory_documents/admin/sections/_modal.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</div>
1010
<div data-dialog-actions>
1111
<div>
12-
<button class="button button__lg button__secondary" id="editor-modal-save"><%= t("modal.save", scope: "decidim.participatory_documents.admin.sections") %></button>
1312
<button class="button button__lg button__alert" id="editor-modal-remove"><%= t("modal.delete", scope: "decidim.participatory_documents.admin.sections") %></button>
13+
<button class="button button__lg button__secondary" id="editor-modal-save"><%= t("modal.save", scope: "decidim.participatory_documents.admin.sections") %></button>
1414
</div>
1515
</div>
1616
<% end %>
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<%= decidim_modal id: "exportSuggestionsModal" do %>
22
<div data-dialog-container>
3+
<%= icon "download-line" %>
34
<h3 class="h3 mb-2"><%= t(".title") %></h3>
5+
<div>
6+
<div class="callout hidden"></div>
7+
<p class="content"><%= t(".description_html", email: current_user&.email, count: all_suggestions&.count) %></p>
8+
</div>
49
</div>
5-
<div data-dialog-container>
6-
<p><%= t(".description_html", email: current_user&.email, count: all_suggestions&.count) %></p>
7-
</div>
8-
<div class="row text-center mt-8 my-2" data-dialog-actions>
10+
<div class="mt-8 my-2" data-dialog-actions>
11+
<button type="button" class="close-button button button__lg button__primary"><%= t(".close") %></button>
912
<button type="button" class="export-button button button__lg button__secondary" data-url="<%= export_document_suggestions_path(document) %>"><%= t(".send") %></button>
1013
</div>
1114
<% end %>

app/views/decidim/participatory_documents/documents/_pdfjs_base.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ See https://github.com/adobe-type-tools/cmap-resources
315315
<%= t "global_suggestions", scope: "decidim.participatory_documents.document" %>
316316
</button>
317317
<button id="exportSuggestionsTrigger"
318-
data-dialog-open="exportSuggestionsModal"
319318
class="decidimButton muted"
320319
title="<%= t "export_my_suggestions", scope: "decidim.participatory_documents.document" %>">
321320
<%= t "export_my_suggestions", scope: "decidim.participatory_documents.document" %>

app/views/decidim/participatory_documents/documents/pdf_viewer.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<div id="notifications"></div>
3232

33-
<div id="participation-modal"></div>
33+
<div id="participationModal"></div>
3434

3535
<%= render "export_modal" %>
3636

@@ -46,9 +46,9 @@
4646
i18n: I18n,
4747
documentPath: DocumentPath,
4848
globalSuggestionsButton: document.getElementById("globalSuggestionTrigger"),
49-
participationLayout: document.getElementById("participation-modal"),
49+
participationLayout: document.getElementById("participationModal"),
5050
exportButton: document.getElementById("exportSuggestionsTrigger"),
51-
exportModal: document.getElementById("export-modal")
51+
exportModal: document.getElementById("exportSuggestionsModal")
5252
};
5353
window.InitDocumentManagers(options);
5454

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ en:
227227
your email inbox at %{email}."
228228
documents:
229229
export_modal:
230+
close: Close
230231
description_html: You have %{count} suggestions on this document. If you
231232
want to export them, you will receive a ZIP file with and Excel document
232233
in it with all your data and any possible answer the admins have given

0 commit comments

Comments
 (0)