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/app/services/search.js
2020-09-04 13:42:47 +02:00

31 lines
850 B
JavaScript

import EmberObject, { get } from "@ember/object";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
export default EmberObject.extend({
searchContextEnabled: false, // checkbox to scope search
searchContext: null,
term: null,
highlightTerm: null,
@observes("term")
_sethighlightTerm() {
this.set("highlightTerm", this.term);
},
@discourseComputed("searchContext")
contextType: {
get(searchContext) {
if (searchContext) {
return get(searchContext, "type");
}
},
set(value, searchContext) {
// a bit hacky, consider cleaning this up, need to work through all observers though
const context = $.extend({}, searchContext);
context.type = value;
this.set("searchContext", context);
return this.get("searchContext.type");
},
},
});