discourse/app/assets/javascripts/discourse/components/queued-post.js.es6
Robin Ward fab36e6cf7 Fix more deprecations:
- Remove all `needs:` code
2016-10-21 17:28:37 -04:00

53 lines
1.5 KiB
JavaScript

import { propertyEqual } from 'discourse/lib/computed';
import { bufferedProperty } from 'discourse/mixins/buffered-content';
import { popupAjaxError } from 'discourse/lib/ajax-error';
function updateState(state, opts) {
opts = opts || {};
return function() {
const post = this.get('post');
const args = { state };
if (opts.deleteUser) { args.delete_user = true; }
post.update(args).then(() => {
this.sendAction('removePost', post);
}).catch(popupAjaxError);
};
}
export default Ember.Component.extend(bufferedProperty('post'), {
editing: propertyEqual('post', 'currentlyEditing'),
_confirmDelete: updateState('rejected', {deleteUser: true}),
actions: {
approve: updateState('approved'),
reject: updateState('rejected'),
deleteUser() {
bootbox.confirm(I18n.t('queue.delete_prompt', {username: this.get('post.user.username')}), (confirmed) => {
if (confirmed) { this._confirmDelete(); }
});
},
edit() {
// This is stupid but pagedown cannot be on the screen twice or it will break
this.set('currentlyEditing', null);
Ember.run.scheduleOnce('afterRender', () => this.set('currentlyEditing', this.get('post')));
},
confirmEdit() {
this.get('post').update({ raw: this.get('buffered.raw') }).then(() => {
this.commitBuffer();
this.set('currentlyEditing', null);
});
},
cancelEdit() {
this.rollbackBuffer();
this.set('currentlyEditing', null);
}
}
});