FEATURE: bulk select on search results

This commit is contained in:
Sam 2015-08-27 11:44:13 +10:00
parent 83f76acbcb
commit 5865bd2abb
4 changed files with 52 additions and 9 deletions

View File

@ -0,0 +1,14 @@
export default Ember.Component.extend({
tagName: "span",
selectionChanged: function(){
const selected = this.get('selected');
const list = this.get('selectedList');
const id = this.get('selectedId');
if (selected) {
list.addObject(id);
} else {
list.removeObject(id);
}
}.observes('selected')
})

View File

@ -6,6 +6,7 @@ export default Ember.Controller.extend({
loading: Em.computed.not("model"),
queryParams: ["q"],
q: null,
selected: [],
modelChanged: function() {
if (this.get("searchTerm") !== this.get("q")) {
@ -25,15 +26,33 @@ export default Ember.Controller.extend({
this.set("controllers.application.showFooter", !this.get("loading"));
}.observes("loading"),
actions: {
search() {
this.set("q", this.get("searchTerm"));
this.set("model", null);
canBulkSelect: Em.computed.alias('currentUser.staff'),
Discourse.ajax("/search", { data: { q: this.get("searchTerm") } }).then(results => {
this.set("model", translateResults(results) || {});
this.set("model.q", this.get("q"));
});
search(){
this.set("q", this.get("searchTerm"));
this.set("model", null);
Discourse.ajax("/search", { data: { q: this.get("searchTerm") } }).then(results => {
this.set("model", translateResults(results) || {});
this.set("model.q", this.get("q"));
});
},
actions: {
toggleBulkSelect() {
this.toggleProperty('bulkSelectEnabled');
this.get('selected').clear();
},
refresh() {
this.set('bulkSelectEnabled', false);
this.get('selected').clear();
this.search();
},
search() {
this.search();
}
}
});

View File

@ -0,0 +1 @@
{{input type="checkbox" checked=selected}}

View File

@ -1,6 +1,12 @@
<div class="search row">
<div class="search row clearfix">
{{input type="text" value=searchTerm class="input-xxlarge search no-blur" action="search"}}
{{d-button action="search" icon="search" class="btn-primary"}}
{{#if canBulkSelect}}
{{#if model.posts}}
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
{{bulk-select-button selected=selected refreshTarget=controller}}
{{/if}}
{{/if}}
</div>
{{#conditional-loading-spinner condition=loading}}
@ -14,6 +20,9 @@
{{#each model.posts as |result|}}
<div class='fps-result'>
<div class='topic'>
{{#if bulkSelectEnabled}}
{{track-selected selectedList=selected selectedId=result.topic}}
{{/if}}
{{avatar result imageSize="tiny"}}
<a class='search-link' href='{{unbound result.url}}'>
{{topic-status topic=result.topic disableActions=true}}<span class='topic-title'>{{unbound result.topic.title}}</span>