mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 12:51:24 +08:00
Tests + Refactoring for Suspension Modal
This commit is contained in:
@ -1,24 +1,41 @@
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
duration: null,
|
||||
reason: null,
|
||||
message: null,
|
||||
loading: false,
|
||||
|
||||
submitDisabled: function() {
|
||||
return (!this.get('reason') || this.get('reason').length < 1);
|
||||
}.property('reason'),
|
||||
onShow() {
|
||||
this.setProperties({
|
||||
duration: null,
|
||||
reason: null,
|
||||
message: null,
|
||||
loading: false
|
||||
});
|
||||
},
|
||||
|
||||
@computed('reason', 'loading')
|
||||
submitDisabled(reason, loading) {
|
||||
return (loading || !reason || reason.length < 1);
|
||||
},
|
||||
|
||||
actions: {
|
||||
suspend: function() {
|
||||
if (this.get('submitDisabled')) return;
|
||||
var duration = parseInt(this.get('duration'), 10);
|
||||
suspend() {
|
||||
if (this.get('submitDisabled')) { return; }
|
||||
|
||||
let duration = parseInt(this.get('duration'), 10);
|
||||
if (duration > 0) {
|
||||
var self = this;
|
||||
this.send('hideModal');
|
||||
this.get('model').suspend(duration, this.get('reason')).then(function() {
|
||||
window.location.reload();
|
||||
}, function(e) {
|
||||
var error = I18n.t('admin.user.suspend_failed', { error: "http: " + e.status + " - " + e.body });
|
||||
bootbox.alert(error, function() { self.send('reopenModal'); });
|
||||
});
|
||||
this.set('loading', true);
|
||||
this.get('model').suspend({
|
||||
duration,
|
||||
reason: this.get('reason'),
|
||||
message: this.get('message')
|
||||
}).then(() => {
|
||||
this.send('closeModal');
|
||||
}).catch(popupAjaxError).finally(() => this.set('loading', false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user