From b089805dc04659ba6f96b53dff8744862305697d Mon Sep 17 00:00:00 2001 From: Claus Strasburger Date: Tue, 1 Oct 2013 16:34:04 +0200 Subject: [PATCH] Added method removeAllowedUser to topic_details.js perform a request to /t/:id/remove-allowed-user, then delete the user from the local list --- .../discourse/controllers/topic_controller.js | 1 + .../javascripts/discourse/models/topic_details.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index e6a01bbe4..a68bb037c 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -473,6 +473,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected removeAllowedUser: function(username) { this.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 a4f4858e9..59fe80302 100644 --- a/app/assets/javascripts/discourse/models/topic_details.js +++ b/app/assets/javascripts/discourse/models/topic_details.js @@ -49,6 +49,19 @@ Discourse.TopicDetails = Discourse.Model.extend({ type: 'POST', data: { notification_level: v } }); - } + }, + removeAllowedUser: function(username) { + var users = this.get('allowed_users'); + Discourse.ajax("/t/" + this.get('topic.id') + "/remove-allowed-user", { + type: 'PUT', + data: { username: username } + }).then(function(res) { + users.forEach(function(user, i) { + if (user.username === username) { + users.removeAt(i); + } + }); + }); + } });