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 02:11:33 +08:00
|
|
|
duration: null,
|
|
|
|
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({
|
|
|
|
duration: null,
|
|
|
|
reason: null,
|
|
|
|
message: null,
|
|
|
|
loading: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed('reason', 'loading')
|
|
|
|
submitDisabled(reason, loading) {
|
|
|
|
return (loading || !reason || reason.length < 1);
|
|
|
|
},
|
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; }
|
|
|
|
|
|
|
|
let duration = parseInt(this.get('duration'), 10);
|
2013-11-01 22:47:03 +08:00
|
|
|
if (duration > 0) {
|
2017-09-14 02:11:33 +08:00
|
|
|
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));
|
2013-11-01 22:47:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|