template: string;
};
+const enum SearchAction {
+ Modify,
+ Init,
+}
+
export class UiSearchExtended {
private readonly form: HTMLFormElement;
private readonly queryInput: HTMLInputElement;
this.form.addEventListener("submit", (event) => {
event.preventDefault();
this.activePage = 1;
- void this.search();
+ void this.search(SearchAction.Modify);
});
this.typeInput.addEventListener("change", () => this.changeType());
+
+ window.addEventListener("popstate", () => {
+ this.initQueryString();
+ });
}
private initKeywordSuggestions(): void {
});
}
- private async search(): Promise<void> {
+ private async search(searchAction: SearchAction): Promise<void> {
if (!this.queryInput.value.trim() && !this.usernameInput.value.trim()) {
return;
}
- this.updateQueryString();
+ this.updateQueryString(searchAction);
this.lastSearchRequest?.abort();
}
}
- private updateQueryString(): void {
+ private updateQueryString(searchAction: SearchAction): void {
const url = new URL(this.form.action);
url.search += url.search !== "" ? "&" : "?";
}
url.search += new URLSearchParams(parameters);
- window.history.replaceState({}, document.title, url.toString());
+ if (searchAction === SearchAction.Init) {
+ window.history.replaceState({}, document.title, url.toString());
+ } else {
+ window.history.pushState({}, document.title, url.toString());
+ }
}
private getFormData(): Record<string, unknown> {
});
this.typeInput.dispatchEvent(new Event("change"));
- void this.search();
+ void this.search(SearchAction.Init);
}
private initPagination(position: "top" | "bottom"): void {
this.form.addEventListener("submit", (event) => {
event.preventDefault();
this.activePage = 1;
- void this.search();
+ void this.search(0 /* Modify */);
});
this.typeInput.addEventListener("change", () => this.changeType());
+ window.addEventListener("popstate", () => {
+ this.initQueryString();
+ });
}
initKeywordSuggestions() {
new Input_1.default(this.queryInput, {
filter.hidden = filter.dataset.objectType !== this.typeInput.value;
});
}
- async search() {
+ async search(searchAction) {
var _a;
if (!this.queryInput.value.trim() && !this.usernameInput.value.trim()) {
return;
}
- this.updateQueryString();
+ this.updateQueryString(searchAction);
(_a = this.lastSearchRequest) === null || _a === void 0 ? void 0 : _a.abort();
const request = (0, Ajax_1.dboAction)("search", "wcf\\data\\search\\SearchAction").payload(this.getFormData());
this.lastSearchRequest = request.getAbortController();
this.showSearchResults(template);
}
}
- updateQueryString() {
+ updateQueryString(searchAction) {
const url = new URL(this.form.action);
url.search += url.search !== "" ? "&" : "?";
const parameters = [];
parameters.push(["pageNo", this.activePage.toString()]);
}
url.search += new URLSearchParams(parameters);
- window.history.replaceState({}, document.title, url.toString());
+ if (searchAction === 1 /* Init */) {
+ window.history.replaceState({}, document.title, url.toString());
+ }
+ else {
+ window.history.pushState({}, document.title, url.toString());
+ }
}
getFormData() {
const data = {};
}
});
this.typeInput.dispatchEvent(new Event("change"));
- void this.search();
+ void this.search(1 /* Init */);
}
initPagination(position) {
const wrapperDiv = document.createElement("div");