mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-02 11:59:17 -05:00
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
/**
|
|
Represents an action taken by a staff member that has been logged.
|
|
|
|
@class StaffActionLog
|
|
@extends Discourse.Model
|
|
@namespace Discourse
|
|
@module Discourse
|
|
**/
|
|
Discourse.StaffActionLog = Discourse.Model.extend({
|
|
showFullDetails: false,
|
|
|
|
actionName: function() {
|
|
return I18n.t("admin.logs.staff_actions.actions." + this.get('action_name'));
|
|
}.property('action_name'),
|
|
|
|
formattedDetails: function() {
|
|
var formatted = "";
|
|
formatted += this.format('email', 'email');
|
|
formatted += this.format('admin.logs.ip_address', 'ip_address');
|
|
formatted += this.format('admin.logs.topic_id', 'topic_id');
|
|
formatted += this.format('admin.logs.post_id', 'post_id');
|
|
if (!this.get('useCustomModalForDetails')) {
|
|
formatted += this.format('admin.logs.staff_actions.new_value', 'new_value');
|
|
formatted += this.format('admin.logs.staff_actions.previous_value', 'previous_value');
|
|
}
|
|
if (!this.get('useModalForDetails')) {
|
|
if (this.get('details')) formatted += Handlebars.Utils.escapeExpression(this.get('details')) + '<br/>';
|
|
}
|
|
return formatted;
|
|
}.property('ip_address', 'email', 'topic_id', 'post_id'),
|
|
|
|
format: function(label, propertyName) {
|
|
if (this.get(propertyName)) {
|
|
return ('<b>' + I18n.t(label) + ':</b> ' + Handlebars.Utils.escapeExpression(this.get(propertyName)) + '<br/>');
|
|
} else {
|
|
return '';
|
|
}
|
|
},
|
|
|
|
useModalForDetails: function() {
|
|
return (this.get('details') && this.get('details').length > 100);
|
|
}.property('action_name'),
|
|
|
|
useCustomModalForDetails: function() {
|
|
return _.contains(['change_site_customization', 'delete_site_customization'], this.get('action_name'));
|
|
}.property('action_name')
|
|
});
|
|
|
|
Discourse.StaffActionLog.reopenClass({
|
|
create: function(attrs) {
|
|
attrs = attrs || {};
|
|
|
|
if (attrs.acting_user) {
|
|
attrs.acting_user = Discourse.AdminUser.create(attrs.acting_user);
|
|
}
|
|
if (attrs.target_user) {
|
|
attrs.target_user = Discourse.AdminUser.create(attrs.target_user);
|
|
}
|
|
return this._super(attrs);
|
|
},
|
|
|
|
findAll: function(filters) {
|
|
return Discourse.ajax("/admin/logs/staff_action_logs.json", { data: filters }).then(function(staff_actions) {
|
|
return staff_actions.map(function(s) {
|
|
return Discourse.StaffActionLog.create(s);
|
|
});
|
|
});
|
|
}
|
|
});
|