diff --git a/app/assets/javascripts/admin/controllers/admin-log-screened-ip-address.js.es6 b/app/assets/javascripts/admin/controllers/admin-log-screened-ip-address.js.es6 deleted file mode 100644 index 199296d82..000000000 --- a/app/assets/javascripts/admin/controllers/admin-log-screened-ip-address.js.es6 +++ /dev/null @@ -1,72 +0,0 @@ -export default Ember.Controller.extend({ - editing: false, - savedIpAddress: null, - - isRange: function() { - return this.get("model.ip_address").indexOf("/") > 0; - }.property("model.ip_address"), - - actions: { - allow: function(record) { - record.set('action_name', 'do_nothing'); - this.send('save', record); - }, - - block: function(record) { - record.set('action_name', 'block'); - this.send('save', record); - }, - - edit: function() { - if (!this.get('editing')) { - this.savedIpAddress = this.get('model.ip_address'); - } - this.set('editing', true); - }, - - cancel: function() { - if (this.get('savedIpAddress') && this.get('editing')) { - this.set('model.ip_address', this.get('savedIpAddress')); - } - this.set('editing', false); - }, - - save: function(record) { - var self = this; - var wasEditing = this.get('editing'); - this.set('editing', false); - record.save().then(function(saved){ - if (saved.success) { - self.set('savedIpAddress', null); - } else { - bootbox.alert(saved.errors); - if (wasEditing) self.set('editing', true); - } - }, function(e){ - if (e.responseJSON && e.responseJSON.errors) { - bootbox.alert(I18n.t("generic_error_with_reason", {error: e.responseJSON.errors.join('. ')})); - } else { - bootbox.alert(I18n.t("generic_error")); - } - if (wasEditing) self.set('editing', true); - }); - }, - - destroy: function(record) { - var self = this; - return bootbox.confirm(I18n.t("admin.logs.screened_ips.delete_confirm", {ip_address: record.get('ip_address')}), I18n.t("no_value"), I18n.t("yes_value"), function(result) { - if (result) { - record.destroy().then(function(deleted) { - if (deleted) { - self.get("parentController.content").removeObject(record); - } else { - bootbox.alert(I18n.t("generic_error")); - } - }, function(e){ - bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body})); - }); - } - }); - } - } -}); diff --git a/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6 b/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6 index 88bc10f0e..88f46d6cc 100644 --- a/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6 @@ -5,19 +5,85 @@ import ScreenedIpAddress from 'admin/models/screened-ip-address'; export default Ember.ArrayController.extend({ loading: false, - itemController: 'admin-log-screened-ip-address', filter: null, + savedIpAddress: null, show: debounce(function() { - var self = this; - self.set('loading', true); - ScreenedIpAddress.findAll(this.get("filter")).then(function(result) { - self.set('model', result); - self.set('loading', false); - }); + this.set('loading', true); + ScreenedIpAddress.findAll(this.get("filter")) + .then(result => { + this.set('model', result); + this.set('loading', false); + }); }, 250).observes("filter"), actions: { + allow(record) { + record.set('action_name', 'do_nothing'); + record.save(); + }, + + block(record) { + record.set('action_name', 'block'); + record.save(); + }, + + edit(record) { + if (!record.get('editing')) { + this.set("savedIpAddress", record.get('ip_address')); + } + record.set('editing', true); + }, + + cancel(record) { + if (this.get('savedIpAddress') && record.get('editing')) { + record.set('ip_address', this.get('savedIpAddress')); + } + record.set('editing', false); + }, + + save(record) { + const wasEditing = record.get('editing'); + record.set('editing', false); + record.save().then(saved => { + if (saved.success) { + this.set('savedIpAddress', null); + } else { + bootbox.alert(saved.errors); + if (wasEditing) record.set('editing', true); + } + }).catch(e => { + if (e.responseJSON && e.responseJSON.errors) { + bootbox.alert(I18n.t("generic_error_with_reason", {error: e.responseJSON.errors.join('. ')})); + } else { + bootbox.alert(I18n.t("generic_error")); + } + if (wasEditing) record.set('editing', true); + }); + }, + + destroy(record) { + const self = this; + return bootbox.confirm( + I18n.t("admin.logs.screened_ips.delete_confirm", { ip_address: record.get('ip_address') }), + I18n.t("no_value"), + I18n.t("yes_value"), + function (result) { + if (result) { + record.destroy().then(deleted => { + if (deleted) { + self.get("content").removeObject(record); + } else { + bootbox.alert(I18n.t("generic_error")); + } + }).catch(e => { + bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body})); + }); + } + } + ); + }, + recordAdded(arg) { this.get("model").unshiftObject(arg); }, diff --git a/app/assets/javascripts/admin/models/screened-ip-address.js.es6 b/app/assets/javascripts/admin/models/screened-ip-address.js.es6 index 51f8ff502..635fddf02 100644 --- a/app/assets/javascripts/admin/models/screened-ip-address.js.es6 +++ b/app/assets/javascripts/admin/models/screened-ip-address.js.es6 @@ -1,38 +1,37 @@ +import computed from 'ember-addons/ember-computed-decorators'; + const ScreenedIpAddress = Discourse.Model.extend({ - actionName: function() { - return I18n.t("admin.logs.screened_ips.actions." + this.get('action_name')); - }.property('action_name'), + @computed("action_name") + actionName(actionName) { + return I18n.t(`admin.logs.screened_ips.actions.${actionName}`); + }, - isBlocked: function() { - return (this.get('action_name') === 'block'); - }.property('action_name'), + isBlocked: Ember.computed.equal("action_name", "block"), - actionIcon: function() { - return (this.get('action_name') === 'block') ? 'ban' : 'check'; - }.property('action_name'), + @computed("ip_address") + isRange(ipAddress) { + return ipAddress.indexOf("/") > 0; + }, - save: function() { + save() { return Discourse.ajax("/admin/logs/screened_ip_addresses" + (this.id ? '/' + this.id : '') + ".json", { type: this.id ? 'PUT' : 'POST', data: {ip_address: this.get('ip_address'), action_name: this.get('action_name')} }); }, - destroy: function() { + destroy() { return Discourse.ajax("/admin/logs/screened_ip_addresses/" + this.get('id') + ".json", {type: 'DELETE'}); } }); ScreenedIpAddress.reopenClass({ - findAll: function(filter) { - return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } }).then(function(screened_ips) { - return screened_ips.map(function(b) { - return ScreenedIpAddress.create(b); - }); - }); + findAll(filter) { + return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } }) + .then(screened_ips => screened_ips.map(b => ScreenedIpAddress.create(b))); }, - rollUp: function() { + rollUp() { return Discourse.ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" }); } }); diff --git a/app/assets/javascripts/admin/routes/admin-logs-screened-ip-addresses.js.es6 b/app/assets/javascripts/admin/routes/admin-logs-screened-ip-addresses.js.es6 index 4aa57c17e..ca914fe1d 100644 --- a/app/assets/javascripts/admin/routes/admin-logs-screened-ip-addresses.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-logs-screened-ip-addresses.js.es6 @@ -1,9 +1,9 @@ export default Discourse.Route.extend({ - renderTemplate: function() { + renderTemplate() { this.render('admin/templates/logs/screened_ip_addresses', {into: 'adminLogs'}); }, - setupController: function() { + setupController() { return this.controllerFor('adminLogsScreenedIpAddresses').show(); } }); diff --git a/app/assets/javascripts/admin/templates/logs/screened_ip_addresses_list_item.hbs b/app/assets/javascripts/admin/templates/logs/screened_ip_addresses_list_item.hbs index f2eb509b3..056b86f9e 100644 --- a/app/assets/javascripts/admin/templates/logs/screened_ip_addresses_list_item.hbs +++ b/app/assets/javascripts/admin/templates/logs/screened_ip_addresses_list_item.hbs @@ -12,7 +12,11 @@ {{/if}}