2014-08-13 07:04:36 +08:00
|
|
|
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
2017-09-14 02:11:33 +08:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
|
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
2014-08-13 07:04:36 +08:00
|
|
|
|
2015-08-12 00:27:07 +08:00
|
|
|
export default Ember.Controller.extend(ModalFunctionality, {
|
2017-09-14 04:44:47 +08:00
|
|
|
suspendUntil: null,
|
2017-09-14 02:11:33 +08:00
|
|
|
reason: null,
|
|
|
|
message: null,
|
2017-09-15 02:10:39 +08:00
|
|
|
suspending: false,
|
|
|
|
user: null,
|
|
|
|
post: null,
|
|
|
|
successCallback: null,
|
2013-11-01 22:47:03 +08:00
|
|
|
|
2017-09-14 02:11:33 +08:00
|
|
|
onShow() {
|
|
|
|
this.setProperties({
|
2017-09-14 04:44:47 +08:00
|
|
|
suspendUntil: null,
|
2017-09-14 02:11:33 +08:00
|
|
|
reason: null,
|
|
|
|
message: null,
|
2017-09-15 02:10:39 +08:00
|
|
|
suspending: false,
|
|
|
|
loadingUser: true,
|
|
|
|
post: null,
|
|
|
|
successCallback: null,
|
2017-09-14 02:11:33 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-09-15 02:10:39 +08:00
|
|
|
@computed('suspendUntil', 'reason', 'suspending')
|
|
|
|
submitDisabled(suspendUntil, reason, suspending) {
|
|
|
|
return (suspending || Ember.isEmpty(suspendUntil) || !reason || reason.length < 1);
|
2017-09-14 02:11:33 +08:00
|
|
|
},
|
2014-02-05 00:03:35 +08:00
|
|
|
|
2013-11-01 22:47:03 +08:00
|
|
|
actions: {
|
2017-09-14 02:11:33 +08:00
|
|
|
suspend() {
|
|
|
|
if (this.get('submitDisabled')) { return; }
|
|
|
|
|
2017-09-15 02:10:39 +08:00
|
|
|
this.set('suspending', true);
|
|
|
|
this.get('user').suspend({
|
2017-09-14 04:44:47 +08:00
|
|
|
suspend_until: this.get('suspendUntil'),
|
|
|
|
reason: this.get('reason'),
|
2017-09-15 02:10:39 +08:00
|
|
|
message: this.get('message'),
|
|
|
|
post_id: this.get('post.id')
|
|
|
|
}).then(result => {
|
2017-09-14 04:44:47 +08:00
|
|
|
this.send('closeModal');
|
2017-09-15 02:10:39 +08:00
|
|
|
let callback = this.get('successCallback');
|
|
|
|
if (callback) {
|
|
|
|
callback(result);
|
|
|
|
}
|
|
|
|
}).catch(popupAjaxError).finally(() => this.set('suspending', false));
|
2013-11-01 22:47:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|