aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/pages/view-khatian/index.ts
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 20:49:57 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 20:49:57 +0530
commit6f6c263a072c9df4e826d8ebb2035c82a87be7e0 (patch)
treec8b944fe53b660d9d58b5559b10f4c73141e7559 /src/scripts/pages/view-khatian/index.ts
parentbc4eb3606afbbc4b54fbb3b4ef81badd06cde525 (diff)
downloadbanglar-bhumi-utils-6f6c263a072c9df4e826d8ebb2035c82a87be7e0.tar.gz
banglar-bhumi-utils-6f6c263a072c9df4e826d8ebb2035c82a87be7e0.zip
refactor: organised the scripts into a more well defined structure
now all scripts that are common to all pages lie in src/scripts/common each page gets its own folder in src/pages and different parts of the page's configuration are separated in separated folders which are all finally imported in src/pages/*/index.ts
Diffstat (limited to 'src/scripts/pages/view-khatian/index.ts')
-rw-r--r--src/scripts/pages/view-khatian/index.ts95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/scripts/pages/view-khatian/index.ts b/src/scripts/pages/view-khatian/index.ts
new file mode 100644
index 0000000..0be0c52
--- /dev/null
+++ b/src/scripts/pages/view-khatian/index.ts
@@ -0,0 +1,95 @@
+import { generateWebPage } from "@/shared/generate-web-page";
+import { interceptPost } from "@/shared/intercept-jquery-ajax";
+import getDownloadInformationPDFPageContent from "@/scripts/pages/view-khatian/download-information-pdf-page-content.html";
+
+const submitButtonElement = $("#khbutton");
+const separatorElement = $("#bodycover > div > form > hr:nth-child(2)");
+const formElement = $("#bodycover > div > form");
+let downloadPDFButton: JQuery<HTMLButtonElement> | null = null;
+
+const submitButtonElementComputedStyles = window.getComputedStyle(submitButtonElement[0]);
+const styles = Array.from(submitButtonElementComputedStyles)
+ .reduce(
+ (str, property) => `${str}${property}:${submitButtonElementComputedStyles.getPropertyValue(property)};`,
+ ""
+ );
+
+/**
+ * Reads the currently selected text from a `<select>` element.
+ *
+ * @param selector - CSS selector for the select element.
+ * @returns The text of the selected option.
+ */
+const getValueOfSelectElement = (selector: string) => {
+ const element = document.querySelector<HTMLSelectElement>(selector)!;
+ return element.options[element.selectedIndex].text;
+};
+
+let isPlotInformation: boolean | null = null;
+
+/**
+ * Opens a new window with a printable PDF view of the current khatian
+ * or plot details, including district/block/mouza info.
+ */
+const downloadInformationPDF = () => {
+ generateWebPage(
+ getDownloadInformationPDFPageContent({
+ isPlotInformation: !!isPlotInformation,
+ details: $(isPlotInformation ? "#plotdetails" : "#khdetails").html(),
+ district: getValueOfSelectElement("#lstDistrictCode1"),
+ block: getValueOfSelectElement("#lstBlockCode1"),
+ mouza: getValueOfSelectElement("#lstMouzaList")
+ }),
+ isPlotInformation
+ ? "Plot Details"
+ : "Khatian Details"
+ );
+};
+
+/**
+ * Intercepts the success callback of a jQuery AJAX call. When a valid
+ * details table is returned, it inserts a "Download PDF" button;
+ * otherwise it removes an existing button.
+ *
+ * @param args - The `arguments` object from the intercepted `$.post` call.
+ */
+const showDownloadButton = (args: any) => {
+ if (isPlotInformation !== null) {
+ const callback = args[2];
+ args[2] = (data: any) => {
+ callback(data);
+ const tableElement = $(isPlotInformation
+ ? "#plotdetails > div:nth-child(1) > div:nth-child(4) > table > tbody"
+ : "#khdetails > table > tbody > tr > td:nth-child(1) > div:nth-child(5) > table > tbody"
+ );
+
+ if (tableElement.length) {
+ tableElement.css("height", "auto");
+ tableElement.css("width", "100%");
+
+ if (!downloadPDFButton) {
+ downloadPDFButton = $(document.createElement("button"));
+ downloadPDFButton.html("Download PDF");
+ downloadPDFButton[0].style.cssText = styles;
+ downloadPDFButton.css("width", "auto");
+ downloadPDFButton.css("margin-bottom", "1rem");
+ downloadPDFButton.on("click", downloadInformationPDF);
+ formElement[0].insertBefore(downloadPDFButton[0], separatorElement[0]);
+ }
+ } else if (downloadPDFButton) {
+ ($(downloadPDFButton as any) as any).remove();
+ isPlotInformation = null;
+ downloadPDFButton = null;
+ }
+ }
+ }
+};
+
+interceptPost("plotDetailsAction_LandInfo.action", args => {
+ isPlotInformation = true;
+ showDownloadButton(args);
+});
+interceptPost("khDetailsAction_LandInfo.action", args => {
+ isPlotInformation = false;
+ showDownloadButton(args);
+});