mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 13:14:04 +08:00
Merge pull request #3769 from tgxworld/disable_button_while_searching
UX: Disable button while searching.
This commit is contained in:
commit
975837cf0d
|
@ -12,6 +12,7 @@ export default Ember.Controller.extend({
|
||||||
selected: [],
|
selected: [],
|
||||||
context_id: null,
|
context_id: null,
|
||||||
context: null,
|
context: null,
|
||||||
|
searching: false,
|
||||||
|
|
||||||
@computed('q')
|
@computed('q')
|
||||||
hasAutofocus(q) {
|
hasAutofocus(q) {
|
||||||
|
@ -45,9 +46,9 @@ export default Ember.Controller.extend({
|
||||||
return isValidSearchTerm(q);
|
return isValidSearchTerm(q);
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed('searchTerm')
|
@computed('searchTerm', 'searching')
|
||||||
isNotValidSearchTerm(searchTerm) {
|
searchButtonDisabled(searchTerm, searching) {
|
||||||
return !isValidSearchTerm(searchTerm);
|
return !!(searching || !isValidSearchTerm(searchTerm));
|
||||||
},
|
},
|
||||||
|
|
||||||
@observes('model')
|
@observes('model')
|
||||||
|
@ -74,10 +75,8 @@ export default Ember.Controller.extend({
|
||||||
canBulkSelect: Em.computed.alias('currentUser.staff'),
|
canBulkSelect: Em.computed.alias('currentUser.staff'),
|
||||||
|
|
||||||
search(){
|
search(){
|
||||||
if (this._searching) {
|
if (this.get("searching")) return;
|
||||||
return;
|
this.set("searching", true);
|
||||||
}
|
|
||||||
this._searching = true;
|
|
||||||
|
|
||||||
const router = Discourse.__container__.lookup('router:main');
|
const router = Discourse.__container__.lookup('router:main');
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ export default Ember.Controller.extend({
|
||||||
const model = translateResults(results) || {};
|
const model = translateResults(results) || {};
|
||||||
router.transientCache('lastSearch', { searchKey, model }, 5);
|
router.transientCache('lastSearch', { searchKey, model }, 5);
|
||||||
this.set("model", model);
|
this.set("model", model);
|
||||||
}).finally(() => this._searching = false);
|
}).finally(() => { this.set("searching",false); });
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -139,7 +138,7 @@ export default Ember.Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
if (this.get("isNotValidSearchTerm")) return;
|
if (this.get("searchButtonDisabled")) return;
|
||||||
this.search();
|
this.search();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="search row clearfix">
|
<div class="search row clearfix">
|
||||||
{{search-text-field value=searchTerm class="input-xxlarge search no-blur" action="search" hasAutofocus=hasAutofocus}}
|
{{search-text-field value=searchTerm class="input-xxlarge search no-blur" action="search" hasAutofocus=hasAutofocus}}
|
||||||
{{d-button action="search" icon="search" class="btn-primary" disabled=isNotValidSearchTerm}}
|
{{d-button action="search" icon="search" class="btn-primary" disabled=searchButtonDisabled}}
|
||||||
{{#if canBulkSelect}}
|
{{#if canBulkSelect}}
|
||||||
{{#if model.posts}}
|
{{#if model.posts}}
|
||||||
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
|
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user