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/views/choose-topic.js.es6
Sam e13ed24122 FEATURE: on mobile take users to full page search
UX: improve styling on full page search page
FEATURE: allow search context in full page search
FEATURE: visited color link for full page search
FIX: broken search help on fulls page search page
FEATURE: allow preload store to return a null
FEATURE: "mobileAction" for the header buttons
2015-09-08 11:04:03 +10:00

56 lines
1.4 KiB
JavaScript

import debounce from 'discourse/lib/debounce';
import { searchForTerm } from 'discourse/lib/search';
export default Ember.View.extend({
templateName: 'choose_topic',
topicTitleChanged: function() {
this.setProperties({
loading: true,
noResults: true,
selectedTopicId: null,
});
this.search(this.get('topicTitle'));
}.observes('topicTitle'),
topicsChanged: function() {
const topics = this.get('topics');
if (topics) {
this.set('noResults', topics.length === 0);
}
this.set('loading', false);
}.observes('topics'),
search: debounce(function(title) {
const self = this,
currentTopicId = this.get("currentTopicId");
if (Em.isEmpty(title)) {
self.setProperties({ topics: null, loading: false });
return;
}
searchForTerm(title, { typeFilter: 'topic', searchForId: true }).then(function (results) {
if (results && results.posts && results.posts.length > 0) {
self.set('topics', results.posts.mapBy('topic').filter(t => t.get("id") !== currentTopicId));
} else {
self.setProperties({ topics: null, loading: false });
}
});
}, 300),
actions: {
chooseTopic: function (topic) {
const topicId = Em.get(topic, 'id');
this.set('selectedTopicId', topicId);
Em.run.next(function () {
$('#choose-topic-' + topicId).prop('checked', 'true');
});
return false;
}
}
});