ES6: Some more controllers

This commit is contained in:
Robin Ward 2014-05-09 11:57:19 -04:00
parent 853bbbbf06
commit 3855ead62e
6 changed files with 92 additions and 87 deletions

View File

@ -7,7 +7,7 @@
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.LoginController = Discourse.Controller.extend(Discourse.ModalFunctionality, {
export default Discourse.Controller.extend(Discourse.ModalFunctionality, {
needs: ['modal', 'createAccount'],
authenticate: null,
loggingIn: false,

View File

@ -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;
}
}
});

View File

@ -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;
}
});

View File

@ -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({});

View File

@ -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({});

View File

@ -25,29 +25,34 @@ Discourse.ChooseTopicView = Discourse.View.extend({
}.observes('topics'),
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) {
if (facets && facets[0] && facets[0].results) {
chooseTopicView.set('topics', facets[0].results);
self.set('topics', facets[0].results);
} else {
chooseTopicView.set('topics', null);
chooseTopicView.set('loading', false);
self.setProperties({ topics: null, loading: false });
}
});
}, 300),
chooseTopic: function (topic) {
var topicId = Em.get(topic, 'id');
this.set('selectedTopicId', topicId);
actions: {
chooseTopic: function (topic) {
var topicId = Em.get(topic, 'id');
this.set('selectedTopicId', topicId);
Em.run.next(function () {
$('#choose-topic-' + topicId).prop('checked', 'true');
});
Em.run.next(function () {
$('#choose-topic-' + topicId).prop('checked', 'true');
});
return false;
return false;
}
}
});
Discourse.View.registerHelper('chooseTopic', Discourse.ChooseTopicView);
Discourse.View.registerHelper('chooseTopic', Discourse.ChooseTopicView);