2013-02-22 15:41:12 -05:00
|
|
|
/**
|
2014-01-14 12:48:57 -05:00
|
|
|
The controller for displaying a list of topics.
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2014-01-14 12:48:57 -05:00
|
|
|
@class DiscoveryTopicsController
|
|
|
|
@extends Discourse.Controller
|
2013-02-22 15:41:12 -05:00
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
|
|
|
**/
|
2014-01-18 11:52:39 -05:00
|
|
|
Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
|
2014-04-11 11:55:05 -04:00
|
|
|
needs: ['discovery'],
|
2014-01-28 17:13:13 -05:00
|
|
|
bulkSelectEnabled: false,
|
|
|
|
selected: [],
|
2013-09-16 14:08:55 -04:00
|
|
|
|
2014-04-16 12:05:54 -04:00
|
|
|
order: 'default',
|
|
|
|
ascending: false,
|
|
|
|
|
2014-01-28 17:13:13 -05:00
|
|
|
actions: {
|
2014-04-16 12:05:54 -04:00
|
|
|
|
|
|
|
changeSort: function(sortBy) {
|
|
|
|
if (sortBy === this.get('order')) {
|
|
|
|
this.toggleProperty('ascending');
|
|
|
|
} else {
|
|
|
|
this.setProperties({ order: sortBy, ascending: false });
|
|
|
|
}
|
|
|
|
this.get('model').refreshSort(sortBy, this.get('ascending'));
|
|
|
|
},
|
|
|
|
|
2013-09-16 14:08:55 -04:00
|
|
|
// Show newly inserted topics
|
2013-12-30 13:29:52 -05:00
|
|
|
showInserted: function() {
|
2013-09-16 14:08:55 -04:00
|
|
|
var tracker = Discourse.TopicTrackingState.current();
|
|
|
|
|
|
|
|
// Move inserted into topics
|
|
|
|
this.get('content').loadBefore(tracker.get('newIncoming'));
|
|
|
|
tracker.resetTracking();
|
|
|
|
return false;
|
2014-01-14 12:48:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
refresh: function() {
|
|
|
|
var filter = this.get('model.filter'),
|
|
|
|
self = this;
|
|
|
|
|
2014-04-11 11:55:05 -04:00
|
|
|
// Don't refresh if we're still loading
|
|
|
|
if (this.get('controllers.discovery.loading')) { return; }
|
|
|
|
|
2014-01-14 12:48:57 -05:00
|
|
|
this.send('loading');
|
|
|
|
Discourse.TopicList.find(filter).then(function(list) {
|
2014-02-21 12:31:54 -05:00
|
|
|
self.setProperties({ model: list, selected: [] });
|
2014-02-21 14:17:45 -05:00
|
|
|
|
|
|
|
var tracking = Discourse.TopicTrackingState.current();
|
|
|
|
if (tracking) {
|
|
|
|
tracking.sync(list, filter);
|
|
|
|
}
|
|
|
|
|
2014-01-14 12:48:57 -05:00
|
|
|
self.send('loadingComplete');
|
|
|
|
});
|
2014-01-28 17:13:13 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleBulkSelect: function() {
|
|
|
|
this.toggleProperty('bulkSelectEnabled');
|
|
|
|
this.get('selected').clear();
|
2014-02-21 12:31:54 -05:00
|
|
|
},
|
|
|
|
|
2014-03-03 15:46:38 -05:00
|
|
|
resetNew: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
Discourse.TopicTrackingState.current().resetNew();
|
|
|
|
Discourse.Topic.resetNew().then(function() {
|
|
|
|
self.send('refresh');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-02-21 12:31:54 -05:00
|
|
|
dismissRead: function() {
|
|
|
|
var self = this,
|
|
|
|
selected = this.get('selected'),
|
|
|
|
operation = { type: 'change_notification_level',
|
2014-02-21 21:10:06 -05:00
|
|
|
notification_level_id: Discourse.Topic.NotificationLevel.REGULAR };
|
2014-02-21 12:31:54 -05:00
|
|
|
|
2014-02-21 14:17:45 -05:00
|
|
|
var promise;
|
2014-02-21 12:31:54 -05:00
|
|
|
if (selected.length > 0) {
|
2014-02-21 14:17:45 -05:00
|
|
|
promise = Discourse.Topic.bulkOperation(selected, operation);
|
2014-02-21 12:31:54 -05:00
|
|
|
} else {
|
2014-02-21 14:17:45 -05:00
|
|
|
promise = Discourse.Topic.bulkOperationByFilter(this.get('filter'), operation);
|
2014-02-21 12:31:54 -05:00
|
|
|
}
|
2014-04-24 15:52:07 -04:00
|
|
|
promise.then(function(result) {
|
|
|
|
if (result && result.topic_ids) {
|
|
|
|
var tracker = Discourse.TopicTrackingState.current();
|
|
|
|
result.topic_ids.forEach(function(t) {
|
|
|
|
tracker.removeTopic(t);
|
|
|
|
});
|
|
|
|
tracker.incrementMessageCount();
|
|
|
|
}
|
|
|
|
self.send('refresh');
|
|
|
|
});
|
2013-09-16 14:08:55 -04:00
|
|
|
}
|
2013-05-29 13:28:07 -04:00
|
|
|
},
|
|
|
|
|
2014-02-21 12:31:54 -05:00
|
|
|
|
2014-01-14 12:48:57 -05:00
|
|
|
topicTrackingState: function() {
|
|
|
|
return Discourse.TopicTrackingState.current();
|
|
|
|
}.property(),
|
|
|
|
|
2014-02-21 12:31:54 -05:00
|
|
|
showDismissRead: function() {
|
|
|
|
return this.get('filter') === 'unread' && this.get('topics.length') > 0;
|
|
|
|
}.property('filter', 'topics.length'),
|
|
|
|
|
2014-03-03 15:46:38 -05:00
|
|
|
showResetNew: function() {
|
|
|
|
return this.get('filter') === 'new' && this.get('topics.length') > 0;
|
|
|
|
}.property('filter', 'topics.length'),
|
|
|
|
|
2014-01-28 17:13:13 -05:00
|
|
|
canBulkSelect: Em.computed.alias('currentUser.staff'),
|
2014-01-14 12:48:57 -05:00
|
|
|
hasTopics: Em.computed.gt('topics.length', 0),
|
|
|
|
showTable: Em.computed.or('hasTopics', 'topicTrackingState.hasIncoming'),
|
|
|
|
allLoaded: Em.computed.empty('more_topics_url'),
|
2014-01-18 11:52:39 -05:00
|
|
|
latest: Discourse.computed.endWith('filter', 'latest'),
|
|
|
|
top: Em.computed.notEmpty('period'),
|
|
|
|
yearly: Em.computed.equal('period', 'yearly'),
|
|
|
|
monthly: Em.computed.equal('period', 'monthly'),
|
|
|
|
weekly: Em.computed.equal('period', 'weekly'),
|
|
|
|
daily: Em.computed.equal('period', 'daily'),
|
2013-05-29 13:28:07 -04:00
|
|
|
|
|
|
|
footerMessage: function() {
|
2014-01-14 12:48:57 -05:00
|
|
|
if (!this.get('allLoaded')) { return; }
|
|
|
|
|
2013-05-29 13:33:54 -04:00
|
|
|
var category = this.get('category');
|
|
|
|
if( category ) {
|
2013-07-08 19:32:16 -04:00
|
|
|
return I18n.t('topics.bottom.category', {category: category.get('name')});
|
2013-05-29 13:28:07 -04:00
|
|
|
} else {
|
|
|
|
var split = this.get('filter').split('/');
|
|
|
|
if (this.get('topics.length') === 0) {
|
2013-07-08 19:32:16 -04:00
|
|
|
return I18n.t("topics.none." + split[0], {
|
2013-05-29 13:28:07 -04:00
|
|
|
category: split[1]
|
|
|
|
});
|
|
|
|
} else {
|
2013-07-08 19:32:16 -04:00
|
|
|
return I18n.t("topics.bottom." + split[0], {
|
2013-05-29 13:28:07 -04:00
|
|
|
category: split[1]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.property('allLoaded', 'topics.length'),
|
|
|
|
|
2014-01-14 12:48:57 -05:00
|
|
|
loadMoreTopics: function() {
|
2014-04-16 12:05:54 -04:00
|
|
|
return this.get('model').loadMore();
|
2013-05-29 13:30:03 -04:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|