From bc0d4f1bfcdb3b46d5adaeae99369b65113de44b Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 14 Aug 2013 11:48:18 -0400 Subject: [PATCH] Add a confirm modal to Delete All Posts button --- .../javascripts/admin/models/admin_user.js | 23 +++++++++++++++---- .../stylesheets/application/modal.css.scss | 2 +- config/locales/client.en.yml | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index fecb1c779..c76df0099 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -9,11 +9,26 @@ Discourse.AdminUser = Discourse.User.extend({ deleteAllPosts: function() { - var user = this; this.set('can_delete_all_posts', false); - Discourse.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}).then(function(result){ - user.set('post_count', 0); - }); + var user = this; + var message = I18n.t('admin.user.delete_all_posts_confirm', {posts: user.get('post_count'), topics: user.get('topic_count')}); + var buttons = [{ + "label": I18n.t("composer.cancel"), + "class": "cancel", + "link": true, + "callback": function() { + user.set('can_delete_all_posts', true); + } + }, { + "label": ' ' + I18n.t("admin.user.delete_all_posts"), + "class": "btn btn-danger", + "callback": function() { + Discourse.ajax("/admin/users/" + (user.get('id')) + "/delete_all_posts", {type: 'PUT'}).then(function(result){ + user.set('post_count', 0); + }); + } + }]; + bootbox.dialog(message, buttons, {"classes": "delete-all-posts"}); }, // Revoke the user's admin access diff --git a/app/assets/stylesheets/application/modal.css.scss b/app/assets/stylesheets/application/modal.css.scss index b55012430..7292b81d9 100644 --- a/app/assets/stylesheets/application/modal.css.scss +++ b/app/assets/stylesheets/application/modal.css.scss @@ -313,7 +313,7 @@ } } -.flagging-delete-spammer { +.flagging-delete-spammer, .delete-all-posts { .modal-footer .cancel { text-decoration: underline; margin-left: 10px; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 09400690e..f32c27ac3 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1247,6 +1247,7 @@ en: unban_failed: "Something went wrong unbanning this user {{error}}" ban_duration: "How long would you like to ban the user for? (days)" delete_all_posts: "Delete all posts" + delete_all_posts_confirm: "You are about to delete %{posts} posts and %{topics} topics. Are you sure?" ban: "Ban" unban: "Unban" banned: "Banned?"