This repository has been archived on 2025-05-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
discourse/app/assets/javascripts/discourse/controllers/topic_bulk_actions_controller.js

71 lines
2 KiB
JavaScript

/**
Modal for performing bulk actions on topics
@class TopicBulkActionsController
@extends Ember.ArrayController
@namespace Discourse
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, {
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() {
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');
}
});
},
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');
},
closeTopics: function() {
this.forEachPerformed({type: 'close'}, function(t) {
t.set('closed', true);
});
},
changeCategory: function() {
var category = Discourse.Category.findById(parseInt(this.get('newCategoryId'), 10)),
categoryName = (category ? category.get('name') : null),
self = this;
this.perform({type: 'change_category', category_name: categoryName}).then(function(topics) {
topics.forEach(function(t) {
t.set('category', category);
});
self.send('closeModal');
});
}
}
});