Skip to content

Commit

Permalink
Manage attachments in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
entantoencuanto committed Nov 26, 2024
1 parent 400aaf7 commit 7d635b6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

<% append_javascript_pack_tag "decidim_decidim_awesome", defer: false %>
<% append_javascript_pack_tag("decidim_decidim_awesome_custom_fields") if Decidim::DecidimAwesome.enabled?(:proposal_custom_fields) %>
<% append_javascript_pack_tag("decidim_decidim_awesome_comments") if Decidim::DecidimAwesome.enabled?(:allow_attachments_in_comments) %>
1 change: 1 addition & 0 deletions app/packs/entrypoints/decidim_decidim_awesome_comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "src/decidim/decidim_awesome/comments/attachments"
21 changes: 21 additions & 0 deletions app/packs/src/decidim/decidim_awesome/comments/attachments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const addResetCommentForm = (form) => {
form.addEventListener("submit", (event) => {
event.preventDefault();
Reflect.apply(Rails.handleRemote, event.target, [event]);
event.target.reset();
});
};

document.querySelectorAll(".comment__form-submit button[type='submit']").forEach((item) => addResetCommentForm(item.form));

document.addEventListener("comments:loaded", (event) => {
const commentsIds = event.detail.commentsIds;
if (commentsIds) {
commentsIds.forEach((commentId) => {
const commentsContainer = document.getElementById(`comment_${commentId}`);
if (commentsContainer) {
commentsContainer.querySelectorAll(".comment__form-submit button[type='submit']").forEach((item) => addResetCommentForm(item.form));
}
});
}
});
1 change: 1 addition & 0 deletions config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
decidim_admin_decidim_awesome: "#{base_path}/app/packs/entrypoints/decidim_admin_decidim_awesome.js",
decidim_admin_decidim_awesome_global: "#{base_path}/app/packs/entrypoints/decidim_admin_decidim_awesome_global.js",
decidim_decidim_awesome_map: "#{base_path}/app/packs/entrypoints/decidim_decidim_awesome_map.js",
decidim_decidim_awesome_comments: "#{base_path}/app/packs/entrypoints/decidim_decidim_awesome_comments.js",
decidim_decidim_awesome_custom_fields: "#{base_path}/app/packs/entrypoints/decidim_decidim_awesome_custom_fields.js",
decidim_decidim_awesome_iframe: "#{base_path}/app/packs/entrypoints/decidim_decidim_awesome_iframe.scss"
)

0 comments on commit 7d635b6

Please sign in to comment.