From 15a973fd451ab5d870ecacba08f8c02dd1ca41cd Mon Sep 17 00:00:00 2001 From: Claus Strasburger Date: Wed, 2 Oct 2013 19:11:48 +0200 Subject: [PATCH] Improved private message user removal, locale edit replaced array iteration with findProperty (will be renamed and aliased to findBy with Ember 1.1) added modal dialog to verify catched nil-error on topic.rb --- .../discourse/controllers/topic_controller.js | 12 +++++++++++- .../javascripts/discourse/models/topic_details.js | 6 +----- app/models/topic.rb | 7 ++++++- config/locales/client.de.yml | 1 + config/locales/client.en.yml | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index a68bb037c10..f94607567fb 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -471,7 +471,17 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, removeAllowedUser: function(username) { - this.get('details').removeAllowedUser(username); + var self = this; + bootbox.dialog(I18n.t("private_message_info.remove_allowed_user", {name: username}), [ + {label: I18n.t("no_value"), + 'class': 'btn-danger rightg'}, + {label: I18n.t("yes_value"), + 'class': 'btn-primary', + callback: function() { + self.get('details').removeAllowedUser(username); + } + } + ]); } }); diff --git a/app/assets/javascripts/discourse/models/topic_details.js b/app/assets/javascripts/discourse/models/topic_details.js index 59fe80302c8..40bb8859234 100644 --- a/app/assets/javascripts/discourse/models/topic_details.js +++ b/app/assets/javascripts/discourse/models/topic_details.js @@ -57,11 +57,7 @@ Discourse.TopicDetails = Discourse.Model.extend({ type: 'PUT', data: { username: username } }).then(function(res) { - users.forEach(function(user, i) { - if (user.username === username) { - users.removeAt(i); - } - }); + users.removeObject(users.findProperty('username', username)); }); } }); diff --git a/app/models/topic.rb b/app/models/topic.rb index 570fabf68be..33b3160e391 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -382,7 +382,12 @@ class Topic < ActiveRecord::Base def remove_allowed_user(username) user = User.where(username: username).first if user - topic_allowed_users.where(user_id: user.id).first.destroy + topic_user = topic_allowed_users.where(user_id: user.id).first + if topic_user + topic_user.destroy + else + false + end end end diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml index e08ee8b0989..4a6857f8ce4 100644 --- a/config/locales/client.de.yml +++ b/config/locales/client.de.yml @@ -373,6 +373,7 @@ de: private_message_info: title: "Privates Gespräch" invite: "Andere einladen..." + remove_allowed_user: "Willst du {{name}} wirklich aus diesem Gespräch entfernen?" email: 'Mail' username: 'Benutzername' diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index d1c22dec2c9..7891f01c090 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -372,6 +372,7 @@ en: private_message_info: title: "Private Message" invite: "Invite Others..." + remove_allowed_user: "Do you really want to remove {{name}} from this private message?" email: 'Email' username: 'Username'