ES6: Some more controllers
This commit is contained in:
parent
853bbbbf06
commit
3855ead62e
|
@ -7,7 +7,7 @@
|
||||||
@uses Discourse.ModalFunctionality
|
@uses Discourse.ModalFunctionality
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.LoginController = Discourse.Controller.extend(Discourse.ModalFunctionality, {
|
export default Discourse.Controller.extend(Discourse.ModalFunctionality, {
|
||||||
needs: ['modal', 'createAccount'],
|
needs: ['modal', 'createAccount'],
|
||||||
authenticate: null,
|
authenticate: null,
|
||||||
loggingIn: false,
|
loggingIn: false,
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
Modal related to merging of topics
|
||||||
|
|
||||||
|
@class MergeTopicController
|
||||||
|
@extends Discourse.ObjectController
|
||||||
|
@namespace Discourse
|
||||||
|
@uses Discourse.ModalFunctionality
|
||||||
|
@module Discourse
|
||||||
|
**/
|
||||||
|
export default Discourse.ObjectController.extend(Discourse.SelectedPostsCount, Discourse.ModalFunctionality, {
|
||||||
|
needs: ['topic'],
|
||||||
|
|
||||||
|
topicController: Em.computed.alias('controllers.topic'),
|
||||||
|
selectedPosts: Em.computed.alias('topicController.selectedPosts'),
|
||||||
|
selectedReplies: Em.computed.alias('topicController.selectedReplies'),
|
||||||
|
allPostsSelected: Em.computed.alias('topicController.allPostsSelected'),
|
||||||
|
|
||||||
|
buttonDisabled: function() {
|
||||||
|
if (this.get('saving')) return true;
|
||||||
|
return this.blank('selectedTopicId');
|
||||||
|
}.property('selectedTopicId', 'saving'),
|
||||||
|
|
||||||
|
buttonTitle: function() {
|
||||||
|
if (this.get('saving')) return I18n.t('saving');
|
||||||
|
return I18n.t('topic.merge_topic.title');
|
||||||
|
}.property('saving'),
|
||||||
|
|
||||||
|
onShow: function() {
|
||||||
|
this.set('controllers.modal.modalClass', 'split-modal');
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
movePostsToExistingTopic: function() {
|
||||||
|
this.set('saving', true);
|
||||||
|
|
||||||
|
var promise = null;
|
||||||
|
if (this.get('allPostsSelected')) {
|
||||||
|
promise = Discourse.Topic.mergeTopic(this.get('id'), this.get('selectedTopicId'));
|
||||||
|
} else {
|
||||||
|
var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }),
|
||||||
|
replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); });
|
||||||
|
|
||||||
|
promise = Discourse.Topic.movePosts(this.get('id'), {
|
||||||
|
destination_topic_id: this.get('selectedTopicId'),
|
||||||
|
post_ids: postIds,
|
||||||
|
reply_post_ids: replyPostIds
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var mergeTopicController = this;
|
||||||
|
promise.then(function(result) {
|
||||||
|
// Posts moved
|
||||||
|
mergeTopicController.send('closeModal');
|
||||||
|
mergeTopicController.get('topicController').send('toggleMultiSelect');
|
||||||
|
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
||||||
|
}, function() {
|
||||||
|
// Error moving posts
|
||||||
|
mergeTopicController.flash(I18n.t('topic.merge_topic.error'));
|
||||||
|
mergeTopicController.set('saving', false);
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
|
@ -1,63 +0,0 @@
|
||||||
/**
|
|
||||||
Modal related to auto closing of topics
|
|
||||||
|
|
||||||
@class MergeTopicController
|
|
||||||
@extends Discourse.ObjectController
|
|
||||||
@namespace Discourse
|
|
||||||
@uses Discourse.ModalFunctionality
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.MergeTopicController = Discourse.ObjectController.extend(Discourse.SelectedPostsCount, Discourse.ModalFunctionality, {
|
|
||||||
needs: ['topic'],
|
|
||||||
|
|
||||||
topicController: Em.computed.alias('controllers.topic'),
|
|
||||||
selectedPosts: Em.computed.alias('topicController.selectedPosts'),
|
|
||||||
selectedReplies: Em.computed.alias('topicController.selectedReplies'),
|
|
||||||
allPostsSelected: Em.computed.alias('topicController.allPostsSelected'),
|
|
||||||
|
|
||||||
buttonDisabled: function() {
|
|
||||||
if (this.get('saving')) return true;
|
|
||||||
return this.blank('selectedTopicId');
|
|
||||||
}.property('selectedTopicId', 'saving'),
|
|
||||||
|
|
||||||
buttonTitle: function() {
|
|
||||||
if (this.get('saving')) return I18n.t('saving');
|
|
||||||
return I18n.t('topic.merge_topic.title');
|
|
||||||
}.property('saving'),
|
|
||||||
|
|
||||||
onShow: function() {
|
|
||||||
this.set('controllers.modal.modalClass', 'split-modal');
|
|
||||||
},
|
|
||||||
|
|
||||||
movePostsToExistingTopic: function() {
|
|
||||||
this.set('saving', true);
|
|
||||||
|
|
||||||
var promise = null;
|
|
||||||
if (this.get('allPostsSelected')) {
|
|
||||||
promise = Discourse.Topic.mergeTopic(this.get('id'), this.get('selectedTopicId'));
|
|
||||||
} else {
|
|
||||||
var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }),
|
|
||||||
replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); });
|
|
||||||
|
|
||||||
promise = Discourse.Topic.movePosts(this.get('id'), {
|
|
||||||
destination_topic_id: this.get('selectedTopicId'),
|
|
||||||
post_ids: postIds,
|
|
||||||
reply_post_ids: replyPostIds
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var mergeTopicController = this;
|
|
||||||
promise.then(function(result) {
|
|
||||||
// Posts moved
|
|
||||||
mergeTopicController.send('closeModal');
|
|
||||||
mergeTopicController.get('topicController').send('toggleMultiSelect');
|
|
||||||
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
|
||||||
}, function() {
|
|
||||||
// Error moving posts
|
|
||||||
mergeTopicController.flash(I18n.t('topic.merge_topic.error'));
|
|
||||||
mergeTopicController.set('saving', false);
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
Related to showing a modal and its title.
|
||||||
|
|
||||||
|
@class ModalController
|
||||||
|
@extends Discourse.Controller
|
||||||
|
@namespace Discourse
|
||||||
|
@module Discourse
|
||||||
|
**/
|
||||||
|
export default Discourse.Controller.extend({});
|
|
@ -1,11 +0,0 @@
|
||||||
/**
|
|
||||||
This controller supports actions related to showing modals
|
|
||||||
|
|
||||||
@class ModalController
|
|
||||||
@extends Discourse.Controller
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.ModalController = Discourse.Controller.extend({});
|
|
||||||
|
|
||||||
|
|
|
@ -25,26 +25,31 @@ Discourse.ChooseTopicView = Discourse.View.extend({
|
||||||
}.observes('topics'),
|
}.observes('topics'),
|
||||||
|
|
||||||
search: Discourse.debounce(function(title) {
|
search: Discourse.debounce(function(title) {
|
||||||
var chooseTopicView = this;
|
var self = this;
|
||||||
|
if (Em.isEmpty(title)) {
|
||||||
|
self.setProperties({ topics: null, loading: false });
|
||||||
|
return;
|
||||||
|
}
|
||||||
Discourse.Search.forTerm(title, {typeFilter: 'topic'}).then(function (facets) {
|
Discourse.Search.forTerm(title, {typeFilter: 'topic'}).then(function (facets) {
|
||||||
if (facets && facets[0] && facets[0].results) {
|
if (facets && facets[0] && facets[0].results) {
|
||||||
chooseTopicView.set('topics', facets[0].results);
|
self.set('topics', facets[0].results);
|
||||||
} else {
|
} else {
|
||||||
chooseTopicView.set('topics', null);
|
self.setProperties({ topics: null, loading: false });
|
||||||
chooseTopicView.set('loading', false);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 300),
|
}, 300),
|
||||||
|
|
||||||
chooseTopic: function (topic) {
|
actions: {
|
||||||
var topicId = Em.get(topic, 'id');
|
chooseTopic: function (topic) {
|
||||||
this.set('selectedTopicId', topicId);
|
var topicId = Em.get(topic, 'id');
|
||||||
|
this.set('selectedTopicId', topicId);
|
||||||
|
|
||||||
Em.run.next(function () {
|
Em.run.next(function () {
|
||||||
$('#choose-topic-' + topicId).prop('checked', 'true');
|
$('#choose-topic-' + topicId).prop('checked', 'true');
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue