mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 15:52:12 +08:00
ES6: Half a dozen more controllers
This commit is contained in:
parent
986e8f2f0f
commit
026cfe2dc7
|
@ -8,7 +8,7 @@
|
|||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.QuoteButtonController = Discourse.Controller.extend({
|
||||
export default Discourse.Controller.extend({
|
||||
needs: ['topic', 'composer'],
|
||||
|
||||
init: function() {
|
|
@ -6,7 +6,7 @@
|
|||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, {
|
||||
export default Em.ArrayController.extend(Discourse.Presence, {
|
||||
|
||||
// If we need to perform another search
|
||||
newSearchNeeded: function() {
|
||||
|
@ -16,24 +16,19 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, {
|
|||
this.set('loading', true);
|
||||
this.searchTerm(term, this.get('typeFilter'));
|
||||
} else {
|
||||
this.set('content', Em.A());
|
||||
this.set('resultCount', 0);
|
||||
this.set('urls', []);
|
||||
this.setProperties({ content: [], resultCount: 0, urls: [] });
|
||||
}
|
||||
this.set('selectedIndex', 0);
|
||||
}.observes('term', 'typeFilter'),
|
||||
|
||||
searchTerm: Discourse.debouncePromise(function(term, typeFilter) {
|
||||
var self = this;
|
||||
self.set('resultCount', 0);
|
||||
self.set('urls', []);
|
||||
this.setProperties({ resultCount: 0, urls: [] });
|
||||
|
||||
var searcher = Discourse.Search.forTerm(term, {
|
||||
return Discourse.Search.forTerm(term, {
|
||||
typeFilter: typeFilter,
|
||||
searchContext: self.get('searchContext')
|
||||
});
|
||||
|
||||
return searcher.then(function(results) {
|
||||
searchContext: this.get('searchContext')
|
||||
}).then(function(results) {
|
||||
var urls = [];
|
||||
if (results) {
|
||||
self.set('noResults', results.length === 0);
|
||||
|
@ -52,9 +47,7 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, {
|
|||
})
|
||||
.value();
|
||||
|
||||
self.set('resultCount', index);
|
||||
self.set('content', results);
|
||||
self.set('urls', urls);
|
||||
self.setProperties({ resultCount: index, content: results, urls: urls });
|
||||
}
|
||||
|
||||
self.set('loading', false);
|
|
@ -6,15 +6,18 @@
|
|||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.ShareController = Discourse.Controller.extend({
|
||||
|
||||
export default Discourse.Controller.extend({
|
||||
needs: ['topic'],
|
||||
|
||||
// Close the share controller
|
||||
actions: {
|
||||
close: function() {
|
||||
this.set('link', '');
|
||||
this.set('postNumber', '');
|
||||
this.setProperties({ link: '', 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;
|
||||
}
|
||||
},
|
||||
|
@ -27,11 +30,6 @@ Discourse.ShareController = Discourse.Controller.extend({
|
|||
return null;
|
||||
}
|
||||
}, 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;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
Discourse.SiteMapCategoryController = Ember.ObjectController.extend({
|
||||
export default Ember.ObjectController.extend({
|
||||
showBadges: function() {
|
||||
return !!Discourse.User.current();
|
||||
}.property().volatile()
|
|
@ -1,5 +1,5 @@
|
|||
Discourse.SiteMapController = Ember.ArrayController.extend(Discourse.HasCurrentUser, {
|
||||
itemController: "siteMapCategory",
|
||||
export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
|
||||
itemController: "site-map-category",
|
||||
|
||||
showAdminLinks: Em.computed.alias('currentUser.staff'),
|
||||
flaggedPostsCount: Em.computed.alias("currentUser.site_flagged_posts_count"),
|
|
@ -8,7 +8,7 @@
|
|||
**/
|
||||
Discourse.TopicController = Discourse.ObjectController.extend(Discourse.SelectedPostsCount, {
|
||||
multiSelect: false,
|
||||
needs: ['header', 'modal', 'composer', 'quoteButton'],
|
||||
needs: ['header', 'modal', 'composer', 'quote-button'],
|
||||
allPostsSelected: false,
|
||||
editingTopic: false,
|
||||
selectedPosts: null,
|
||||
|
@ -424,7 +424,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||
// Post related methods
|
||||
replyToPost: function(post) {
|
||||
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 topic = post ? post.get('topic') : this.get('model');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var controller, searcherStub;
|
||||
|
||||
module("Discourse.SearchController", {
|
||||
module("controller:search", {
|
||||
setup: function() {
|
||||
Discourse.SiteSettings.min_search_term_length = 2;
|
||||
|
||||
|
@ -10,7 +10,7 @@ module("Discourse.SearchController", {
|
|||
searcherStub = Ember.Deferred.create();
|
||||
sinon.stub(Discourse.Search, "forTerm").returns(searcherStub);
|
||||
|
||||
controller = Discourse.SearchController.create();
|
||||
controller = testController('search', []);
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
var controller;
|
||||
|
||||
module("Discourse.SiteMapCategoryController", {
|
||||
module("controller:site-map-category", {
|
||||
setup: function() {
|
||||
controller = Discourse.SiteMapCategoryController.create();
|
||||
controller = testController('site-map-category');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var controller, oldMobileView;
|
||||
|
||||
module("Discourse.SiteMapController", {
|
||||
module("controller:site-map", {
|
||||
setup: function() {
|
||||
oldMobileView = Discourse.Mobile.mobileView;
|
||||
|
||||
controller = Discourse.SiteMapController.create();
|
||||
controller = testController('site-map');
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
|
@ -13,7 +13,7 @@ module("Discourse.SiteMapController", {
|
|||
});
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user