This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/routes/discovery_route.js
Robin Ward 4bec839d9d Using Discourse.XYZ in templates is deprecated. This fixes that, plus
adds some more integration tests to make sure login required is working.
2014-09-05 13:09:01 -04:00

72 lines
2.2 KiB
JavaScript

/**
The parent route for all discovery routes. Handles the logic for showing
the loading spinners.
@class DiscoveryRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, Discourse.OpenComposer, {
redirect: function() { return this.redirectIfLoginRequired(); },
beforeModel: function(transition) {
if (transition.targetName.indexOf("discovery.top") === -1 &&
Discourse.User.currentProp("should_be_redirected_to_top")) {
Discourse.User.currentProp("should_be_redirected_to_top", false);
this.replaceWith("discovery.top");
}
},
actions: {
loading: function() {
var controller = this.controllerFor('discovery');
// If we're already loading don't do anything
if (controller.get('loading')) { return; }
controller.set('loading', true);
controller.set('scheduledSpinner', Ember.run.later(controller, function() {
this.set('loadingSpinner', true);
},500));
},
loadingComplete: function() {
var controller = this.controllerFor('discovery');
Ember.run.cancel(controller.get('scheduledSpinner'));
controller.setProperties({ loading: false, loadingSpinner: false });
if (!Discourse.Session.currentProp('topicListScrollPosition')) {
this._scrollTop();
}
},
didTransition: function() {
this.send('loadingComplete');
},
// clear a pinned topic
clearPin: function(topic) {
topic.clearPin();
},
createTopic: function() {
this.openComposer(this.controllerFor('discovery/topics'));
},
changeBulkTemplate: function(w) {
var controllerName = w.replace('modal/', ''),
factory = this.container.lookupFactory('controller:' + controllerName);
this.render(w, {into: 'topicBulkActions', outlet: 'bulkOutlet', controller: factory ? controllerName : 'topic-bulk-actions'});
},
showBulkActions: function() {
var selected = this.controllerFor('discovery/topics').get('selected');
Discourse.Route.showModal(this, 'topicBulkActions', selected);
this.send('changeBulkTemplate', 'modal/bulk_actions_buttons');
}
}
});