Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
delete attachments: Add confirmation dialog.
Ganesh Pawar6b80f010f587
diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.jsindex a88150012a3..42d52a09b56 100644--- a/static/js/attachments_ui.js+++ b/static/js/attachments_ui.js@@ -1,9 +1,11 @@import $ from "jquery";+import render_confirm_delete_attachment from "../templates/confirm_dialog/confirm_delete_attachment.hbs";import render_settings_upload_space_stats from "../templates/settings/upload_space_stats.hbs";import render_uploaded_files_list from "../templates/settings/uploaded_files_list.hbs";import * as channel from "./channel";+import * as dialog_widget from "./dialog_widget";import {$t_html} from "./i18n";import * as ListWidget from "./list_widget";import * as loading from "./loading";@@ -49,16 +51,18 @@ function set_upload_space_stats() {$("#attachment-stats-holder").html(rendered_upload_stats_html);}-function delete_attachments(attachment) {- const $status = $("#delete-upload-status");- channel.del({- url: "/json/attachments/" + attachment,- error(xhr) {- ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $status);- },- success() {- ui_report.success($t_html({defaultMessage: "Attachment deleted"}), $status);- },+function delete_attachments(attachment, file_name) {+ const html_body = render_confirm_delete_attachment({file_name});++ dialog_widget.launch({+ html_heading: $t_html({defaultMessage: "Delete file?"}),+ html_body,+ html_submit_button: $t_html({defaultMessage: "Delete"}),+ id: "confirm_delete_file_modal",+ focus_submit_on_open: true,+ on_click: () =>+ dialog_widget.submit_api_request(channel.del, "/json/attachments/" + attachment),+ loading_spinner: true,});}@@ -146,7 +150,11 @@ export function set_up_attachments() {loading.make_indicator($("#attachments_loading_indicator"), {text: "Loading..."});$("#uploaded_files_table").on("click", ".remove-attachment", (e) => {- delete_attachments($(e.target).closest(".uploaded_file_row").attr("data-attachment-id"));+ const file_name = $(e.target).closest(".uploaded_file_row").attr("id");+ delete_attachments(+ $(e.target).closest(".uploaded_file_row").attr("data-attachment-id"),+ file_name,+ );});channel.get({diff --git a/static/templates/confirm_dialog/confirm_delete_attachment.hbs b/static/templates/confirm_dialog/confirm_delete_attachment.hbsnew file mode 100644index 00000000000..17f93ee4a64--- /dev/null+++ b/static/templates/confirm_dialog/confirm_delete_attachment.hbs@@ -0,0 +1,3 @@+{{#tr}}+ <p><strong>{file_name}</strong> will be removed from the messages where it was shared. This action cannot be undone.</p>+{{/tr}}