diff --git a/app/assets/javascripts/discourse/components/track-selected.js.es6 b/app/assets/javascripts/discourse/components/track-selected.js.es6 new file mode 100644 index 00000000000..ded975509c9 --- /dev/null +++ b/app/assets/javascripts/discourse/components/track-selected.js.es6 @@ -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') +}) diff --git a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 index 86e240febf3..7a5f031d2bf 100644 --- a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 @@ -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(); } } }); diff --git a/app/assets/javascripts/discourse/templates/components/track-selected.hbs b/app/assets/javascripts/discourse/templates/components/track-selected.hbs new file mode 100644 index 00000000000..dcc61529505 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/track-selected.hbs @@ -0,0 +1 @@ +{{input type="checkbox" checked=selected}} diff --git a/app/assets/javascripts/discourse/templates/full-page-search.hbs b/app/assets/javascripts/discourse/templates/full-page-search.hbs index b04d1e59374..7ece854650f 100644 --- a/app/assets/javascripts/discourse/templates/full-page-search.hbs +++ b/app/assets/javascripts/discourse/templates/full-page-search.hbs @@ -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>