discourse/app/assets/javascripts/discourse/controllers/topic-bulk-actions.js.es6
Régis Hanol 0947191060 UX: improved our footer handling
- new "show-footer" mixins
- converted most of the routes to ES6
- FIX: handling of "indexStream" in user pages

There will now be a footer on all the following pages
- /exception
- /about
- /latest
- /new
- /unread
- /starred
- /top
- /categories
- /c/:category
- /c/:category/l/latest
- /c/:category/l/new
- /c/:category/l/unread
- /c/:category/l/top
- /t/:topic/:id
- /groups/:name/members
- /user/activity
- /user/activity/topics
- /user/activity/posts
- /user/activity/replies
- /user/activity/likes-given
- /user/activity/likes-received
- /user/activity/bookmarks
- /user/activity/starred
- /user/badges
- /user/notifications
- /user/flagged-posts
- /user/deleted-posts
- /user/private-messages
- /user/private-messages/mine
- /user/private-messages/unread
- /user/invited
- /user/:username/preferences
- /faq (static pages)
- /badges
- /badges/:id/:badge
2014-11-19 20:37:43 +01:00

92 lines
2.5 KiB
JavaScript

import ModalFunctionality from 'discourse/mixins/modal-functionality';
// Modal for performing bulk actions on topics
export default Ember.ArrayController.extend(ModalFunctionality, {
needs: ['discovery/topics'],
onShow: function() {
this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal small');
},
perform: function(operation) {
this.set('loading', true);
var self = this,
topics = this.get('model');
return Discourse.Topic.bulkOperation(this.get('model'), operation).then(function(result) {
self.set('loading', false);
if (result && result.topic_ids) {
return result.topic_ids.map(function (t) {
return topics.findBy('id', t);
});
}
return result;
}).catch(function() {
bootbox.alert(I18n.t('generic_error'));
self.set('loading', false);
});
},
forEachPerformed: function(operation, cb) {
var self = this;
this.perform(operation).then(function (topics) {
if (topics) {
topics.forEach(cb);
self.send('closeModal');
}
});
},
performAndRefresh: function(operation) {
var self = this;
return this.perform(operation).then(function() {
self.get('controllers.discovery/topics').send('refresh');
self.send('closeModal');
});
},
actions: {
showChangeCategory: function() {
this.send('changeBulkTemplate', 'modal/bulk_change_category');
this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal full');
},
showNotificationLevel: function() {
this.send('changeBulkTemplate', 'modal/bulk_notification_level');
},
deleteTopics: function() {
this.performAndRefresh({type: 'delete'});
},
closeTopics: function() {
this.forEachPerformed({type: 'close'}, function(t) {
t.set('closed', true);
});
},
archiveTopics: function() {
this.forEachPerformed({type: 'archive'}, function(t) {
t.set('archived', true);
});
},
changeCategory: function() {
var categoryId = parseInt(this.get('newCategoryId'), 10) || 0,
category = Discourse.Category.findById(categoryId),
self = this;
this.perform({type: 'change_category', category_id: categoryId}).then(function(topics) {
topics.forEach(function(t) {
t.set('category', category);
});
self.get('controllers.discovery/topics').send('refresh');
self.send('closeModal');
});
},
resetRead: function() {
this.performAndRefresh({ type: 'reset_read' });
}
}
});