UX: Allow admin to copy IP address details of a user. (#6270)

This commit is contained in:
Misaka 0x4e21 2018-08-20 23:29:20 +08:00 committed by Régis Hanol
parent ac40fede66
commit 1d913d3204
2 changed files with 34 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user"; import AdminUser from "admin/models/admin-user";
import copyText from "discourse/lib/copy-text";
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: ["ip-lookup"], classNames: ["ip-lookup"],
@ -62,6 +63,38 @@ export default Ember.Component.extend({
this.set("show", false); this.set("show", false);
}, },
copy: function() {
let text = `IP: ${this.get("ip")}\n`;
const location = this.get("location");
if (location) {
if (location.hostname) {
text += `${I18n.t("ip_lookup.hostname")}: ${location.hostname}\n`;
}
text += I18n.t("ip_lookup.location");
if (location.loc) {
text += `: ${location.loc} ${this.get("city")}\n`;
} else {
text += `: ${I18n.t("ip_lookup.location_not_found")}\n`;
}
if (location.org) {
text += I18n.t("ip_lookup.organisation");
text += `: ${location.org}\n`;
}
if (location.phone) {
text += I18n.t("ip_lookup.phone");
text += `: ${location.phone}\n`;
}
}
const copyRange = $(`<textarea id="copy-range"></textarea>`);
copyRange.text(text);
$(document.body).append(copyRange);
copyText(text, copyRange[0]);
copyRange.remove();
},
deleteOtherAccounts: function() { deleteOtherAccounts: function() {
var self = this; var self = this;
bootbox.confirm( bootbox.confirm(

View File

@ -6,6 +6,7 @@
{{#if show}} {{#if show}}
<div class="location-box"> <div class="location-box">
<a class="close pull-right" {{action "hide"}}>{{d-icon "times"}}</a> <a class="close pull-right" {{action "hide"}}>{{d-icon "times"}}</a>
<a class="btn pull-right" {{action "copy"}}>{{d-icon "copy"}}</a>
<h4>{{i18n 'ip_lookup.title'}}</h4> <h4>{{i18n 'ip_lookup.title'}}</h4>
<p class='powered-by'>{{{i18n 'ip_lookup.powered_by'}}}</p> <p class='powered-by'>{{{i18n 'ip_lookup.powered_by'}}}</p>
<dl> <dl>