ES6: Half a dozen more controllers

This commit is contained in:
Robin Ward 2014-05-15 11:19:45 -04:00
parent 986e8f2f0f
commit 026cfe2dc7
9 changed files with 29 additions and 38 deletions

View file

@ -8,7 +8,7 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.QuoteButtonController = Discourse.Controller.extend({ export default Discourse.Controller.extend({
needs: ['topic', 'composer'], needs: ['topic', 'composer'],
init: function() { init: function() {

View file

@ -6,7 +6,7 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, { export default Em.ArrayController.extend(Discourse.Presence, {
// If we need to perform another search // If we need to perform another search
newSearchNeeded: function() { newSearchNeeded: function() {
@ -16,24 +16,19 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, {
this.set('loading', true); this.set('loading', true);
this.searchTerm(term, this.get('typeFilter')); this.searchTerm(term, this.get('typeFilter'));
} else { } else {
this.set('content', Em.A()); this.setProperties({ content: [], resultCount: 0, urls: [] });
this.set('resultCount', 0);
this.set('urls', []);
} }
this.set('selectedIndex', 0); this.set('selectedIndex', 0);
}.observes('term', 'typeFilter'), }.observes('term', 'typeFilter'),
searchTerm: Discourse.debouncePromise(function(term, typeFilter) { searchTerm: Discourse.debouncePromise(function(term, typeFilter) {
var self = this; var self = this;
self.set('resultCount', 0); this.setProperties({ resultCount: 0, urls: [] });
self.set('urls', []);
var searcher = Discourse.Search.forTerm(term, { return Discourse.Search.forTerm(term, {
typeFilter: typeFilter, typeFilter: typeFilter,
searchContext: self.get('searchContext') searchContext: this.get('searchContext')
}); }).then(function(results) {
return searcher.then(function(results) {
var urls = []; var urls = [];
if (results) { if (results) {
self.set('noResults', results.length === 0); self.set('noResults', results.length === 0);
@ -52,9 +47,7 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, {
}) })
.value(); .value();
self.set('resultCount', index); self.setProperties({ resultCount: index, content: results, urls: urls });
self.set('content', results);
self.set('urls', urls);
} }
self.set('loading', false); self.set('loading', false);

View file

@ -6,15 +6,18 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.ShareController = Discourse.Controller.extend({ export default Discourse.Controller.extend({
needs: ['topic'], needs: ['topic'],
// Close the share controller // Close the share controller
actions: { actions: {
close: function() { close: function() {
this.set('link', ''); this.setProperties({ link: '', postNumber: '' });
this.set('postNumber', ''); return false;
},
sharePopup: function(target, url) {
window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=600,height=' + Discourse.ShareLink.popupHeight(target));
return false; return false;
} }
}, },
@ -27,11 +30,6 @@ Discourse.ShareController = Discourse.Controller.extend({
return null; return null;
} }
}, this).compact(); }, this).compact();
}.property('link'), }.property('link')
sharePopup: function(target, url) { });
window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=600,height=' + Discourse.ShareLink.popupHeight(target));
return false;
}
});

View file

@ -1,4 +1,4 @@
Discourse.SiteMapCategoryController = Ember.ObjectController.extend({ export default Ember.ObjectController.extend({
showBadges: function() { showBadges: function() {
return !!Discourse.User.current(); return !!Discourse.User.current();
}.property().volatile() }.property().volatile()

View file

@ -1,5 +1,5 @@
Discourse.SiteMapController = Ember.ArrayController.extend(Discourse.HasCurrentUser, { export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
itemController: "siteMapCategory", itemController: "site-map-category",
showAdminLinks: Em.computed.alias('currentUser.staff'), showAdminLinks: Em.computed.alias('currentUser.staff'),
flaggedPostsCount: Em.computed.alias("currentUser.site_flagged_posts_count"), flaggedPostsCount: Em.computed.alias("currentUser.site_flagged_posts_count"),

View file

@ -8,7 +8,7 @@
**/ **/
Discourse.TopicController = Discourse.ObjectController.extend(Discourse.SelectedPostsCount, { Discourse.TopicController = Discourse.ObjectController.extend(Discourse.SelectedPostsCount, {
multiSelect: false, multiSelect: false,
needs: ['header', 'modal', 'composer', 'quoteButton'], needs: ['header', 'modal', 'composer', 'quote-button'],
allPostsSelected: false, allPostsSelected: false,
editingTopic: false, editingTopic: false,
selectedPosts: null, selectedPosts: null,
@ -424,7 +424,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
// Post related methods // Post related methods
replyToPost: function(post) { replyToPost: function(post) {
var composerController = this.get('controllers.composer'); var composerController = this.get('controllers.composer');
var quoteController = this.get('controllers.quoteButton'); var quoteController = this.get('controllers.quote-button');
var quotedText = Discourse.Quote.build(quoteController.get('post'), quoteController.get('buffer')); var quotedText = Discourse.Quote.build(quoteController.get('post'), quoteController.get('buffer'));
var topic = post ? post.get('topic') : this.get('model'); var topic = post ? post.get('topic') : this.get('model');

View file

@ -1,6 +1,6 @@
var controller, searcherStub; var controller, searcherStub;
module("Discourse.SearchController", { module("controller:search", {
setup: function() { setup: function() {
Discourse.SiteSettings.min_search_term_length = 2; Discourse.SiteSettings.min_search_term_length = 2;
@ -10,7 +10,7 @@ module("Discourse.SearchController", {
searcherStub = Ember.Deferred.create(); searcherStub = Ember.Deferred.create();
sinon.stub(Discourse.Search, "forTerm").returns(searcherStub); sinon.stub(Discourse.Search, "forTerm").returns(searcherStub);
controller = Discourse.SearchController.create(); controller = testController('search', []);
}, },
teardown: function() { teardown: function() {

View file

@ -1,8 +1,8 @@
var controller; var controller;
module("Discourse.SiteMapCategoryController", { module("controller:site-map-category", {
setup: function() { setup: function() {
controller = Discourse.SiteMapCategoryController.create(); controller = testController('site-map-category');
} }
}); });

View file

@ -1,10 +1,10 @@
var controller, oldMobileView; var controller, oldMobileView;
module("Discourse.SiteMapController", { module("controller:site-map", {
setup: function() { setup: function() {
oldMobileView = Discourse.Mobile.mobileView; oldMobileView = Discourse.Mobile.mobileView;
controller = Discourse.SiteMapController.create(); controller = testController('site-map');
}, },
teardown: function() { teardown: function() {
@ -13,7 +13,7 @@ module("Discourse.SiteMapController", {
}); });
test("itemController", function() { test("itemController", function() {
equal(controller.get("itemController"), "siteMapCategory", "defaults to SiteMapCategoryController"); equal(controller.get("itemController"), "site-map-category", "defaults to site-map-category");
}); });
test("showAdminLinks", function() { test("showAdminLinks", function() {