All files / Scripts/ui mha.ts

0% Statements 0/47
0% Branches 0/3
0% Functions 0/8
0% Lines 0/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81                                                                                                                                                                 
import "office-ui-fabric-js/dist/css/fabric.min.css";
import "office-ui-fabric-js/dist/css/fabric.components.min.css";
import "../../Content/fabric.css";
import "../../Content/Office.css";
import "../../Content/classicDesktopFrame.css";
import $ from "jquery";
 
import { diagnostics } from "../Diag";
import { HeaderModel } from "../HeaderModel";
import { mhaStrings } from "../mhaStrings";
import { Strings } from "../Strings";
import { Table } from "./Table";
 
let viewModel: HeaderModel;
let table: Table;
 
function enableSpinner() {
    $("#response").css("background-image", "url(../Resources/loader.gif)");
    $("#response").css("background-repeat", "no-repeat");
    $("#response").css("background-position", "center");
}
 
function disableSpinner() {
    $("#response").css("background", "none");
}
 
function updateStatus(statusText: string) {
    $("#status").text(statusText);
    Iif (viewModel !== null) {
        viewModel.status = statusText;
    }
 
    table.recalculateVisibility();
}
 
// Do our best at recognizing RFC 2822 headers:
// http://tools.ietf.org/html/rfc2822
function analyze() {
    // Can't do anything without jQuery
    Iif (!$) return;
    diagnostics.trackEvent({ name: "analyzeHeaders" });
    viewModel = new HeaderModel($("#inputHeaders").val() as string);
    table.resetArrows();
 
    enableSpinner();
    updateStatus(mhaStrings.mhaLoading);
 
    table.rebuildTables(viewModel);
    updateStatus("");
 
    disableSpinner();
}
 
function clear() {
    $("#inputHeaders").val("");
 
    viewModel = new HeaderModel();
    table.resetArrows();
    table.rebuildSections(viewModel);
    document.getElementById("inputHeaders")?.focus();
}
 
function copy() {
    Strings.copyToClipboard(viewModel.toString());
    document.getElementById("copyButton")?.focus();
}
 
Iif ($) {
    $(function() {
        diagnostics.set("API used", "standalone");
        viewModel = new HeaderModel();
        table = new Table();
        table.initializeTableUI(viewModel);
        table.makeResizablePane("inputHeaders", "sectionHeader", mhaStrings.mhaPrompt, () => true);
 
        (document.querySelector("#analyzeButton") as HTMLButtonElement).onclick = analyze;
        (document.querySelector("#clearButton") as HTMLButtonElement).onclick = clear;
        (document.querySelector("#copyButton") as HTMLButtonElement).onclick = copy;
    });
}