ts: Convert ui_report module to TypeScript.

This commit is contained in:
Priyank Patel 2021-06-04 19:44:07 +00:00 committed by Tim Abbott
parent 8a6f57d750
commit f7235912ff
3 changed files with 24 additions and 10 deletions

View File

@ -10,7 +10,12 @@ import {$t} from "./i18n";
cls- class that we want to add/remove to/from the status_box
*/
export function message(response_html, status_box, cls = "alert", remove_after) {
export function message(
response_html: string,
status_box: JQuery,
cls = "alert",
remove_after?: number,
): void {
// Note we use html() below, since we can rely on our callers escaping HTML
// via $t_html when interpolating data.
status_box
@ -27,7 +32,12 @@ export function message(response_html, status_box, cls = "alert", remove_after)
status_box.addClass("show");
}
export function error(response_html, xhr, status_box, remove_after) {
export function error(
response_html: string,
xhr: JQuery.jqXHR | undefined,
status_box: JQuery,
remove_after?: number,
): void {
if (xhr && xhr.status >= 400 && xhr.status < 500) {
// Only display the error response for 4XX, where we've crafted
// a nice response.
@ -42,15 +52,19 @@ export function error(response_html, xhr, status_box, remove_after) {
message(response_html, status_box, "alert-error", remove_after);
}
export function client_error(response_html, status_box, remove_after) {
export function client_error(
response_html: string,
status_box: JQuery,
remove_after?: number,
): void {
message(response_html, status_box, "alert-error", remove_after);
}
export function success(response_html, status_box, remove_after) {
export function success(response_html: string, status_box: JQuery, remove_after?: number): void {
message(response_html, status_box, "alert-success", remove_after);
}
export function generic_embed_error(error_html) {
export function generic_embed_error(error_html: string): void {
const $alert = $("<div class='alert home-error-bar'></div>");
const $exit = "<div class='exit'></div>";
@ -59,7 +73,7 @@ export function generic_embed_error(error_html) {
);
}
export function generic_row_button_error(xhr, btn) {
export function generic_row_button_error(xhr: JQuery.jqXHR, btn: JQuery): void {
if (xhr.status >= 400 && xhr.status < 500) {
const $error = $("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg);
btn.closest("td").empty().append($error);
@ -68,13 +82,13 @@ export function generic_row_button_error(xhr, btn) {
}
}
export function hide_error($target) {
export function hide_error($target: JQuery): void {
$target.addClass("fade-out");
setTimeout(() => {
$target.removeClass("show fade-out");
}, 300);
}
export function show_error($target) {
export function show_error($target: JQuery): void {
$target.addClass("show");
}

View File

@ -132,7 +132,7 @@ js_rules = RuleList(
"exclude": {
"static/js/portico",
"static/js/lightbox.js",
"static/js/ui_report.js",
"static/js/ui_report.ts",
"static/js/confirm_dialog.js",
"frontend_tests/",
},

View File

@ -164,7 +164,7 @@ EXEMPT_FILES = {
"static/js/typing.js",
"static/js/ui_init.js",
"static/js/ui.js",
"static/js/ui_report.js",
"static/js/ui_report.ts",
"static/js/ui_util.js",
"static/js/unread_ops.js",
"static/js/unread_ui.js",