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,
|
|
|
|
loading: false,
|
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,
|
|
|
|
loading: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-09-14 04:44:47 +08:00
|
|
|
@computed('suspendUntil', 'reason', 'loading')
|
|
|
|
submitDisabled(suspendUntil, reason, loading) {
|
|
|
|
return (loading || 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-14 04:44:47 +08:00
|
|
|
this.set('loading', true);
|
|
|
|
this.get('model').suspend({
|
|
|
|
suspend_until: this.get('suspendUntil'),
|
|
|
|
reason: this.get('reason'),
|
|
|
|
message: this.get('message')
|
|
|
|
}).then(() => {
|
|
|
|
this.send('closeModal');
|
|
|
|
}).catch(popupAjaxError).finally(() => this.set('loading', false));
|
2013-11-01 22:47:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|