This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/queued-post.js.es6

43 lines
1.2 KiB
JavaScript

import BufferedContent from 'discourse/mixins/buffered-content';
import { popupAjaxError } from 'discourse/lib/ajax-error';
function updateState(state) {
return function() {
const post = this.get('post');
post.update({ state }).then(() => {
this.get('controllers.queued-posts.model').removeObject(post);
}).catch(popupAjaxError);
};
}
export default Ember.Controller.extend(BufferedContent, {
needs: ['queued-posts'],
post: Ember.computed.alias('model'),
currentlyEditing: Ember.computed.alias('controllers.queued-posts.editing'),
editing: Discourse.computed.propertyEqual('model', 'currentlyEditing'),
actions: {
approve: updateState('approved'),
reject: updateState('rejected'),
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('model')));
},
confirmEdit() {
this.get('post').update({ raw: this.get('buffered.raw') }).then(() => {
this.commitBuffer();
this.set('currentlyEditing', null);
});
},
cancelEdit() {
this.rollbackBuffer();
this.set('currentlyEditing', null);
}
}
});