occupancy type print management

deepsource-autofix-76c6eb20
Dan Gowans 2022-12-22 14:08:07 -05:00
parent a1348fedbc
commit e0573ee890
36 changed files with 1442 additions and 186 deletions

View File

@ -1,12 +1,22 @@
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
import * as configFunctions from "../../helpers/functions.config.js";
import * as printFunctions from "../../helpers/functions.print.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler = (_request, response) => {
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
const occupancyTypePrints = configFunctions.getProperty("settings.lotOccupancy.prints");
const occupancyTypePrintTitles = {};
for (const printEJS of occupancyTypePrints) {
const printConfig = printFunctions.getPrintConfig(printEJS);
if (printConfig) {
occupancyTypePrintTitles[printEJS] = printConfig.title;
}
}
response.render("admin-occupancyTypes", {
headTitle: configFunctions.getProperty("aliases.occupancy") + " Type Management",
occupancyTypes,
allOccupancyTypeFields
allOccupancyTypeFields,
occupancyTypePrintTitles
});
};
export default handler;

View File

@ -1,17 +1,31 @@
import type { RequestHandler } from "express";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
import * as configFunctions from "../../helpers/functions.config.js";
import * as printFunctions from "../../helpers/functions.print.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (_request, response) => {
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
const occupancyTypePrints = configFunctions.getProperty("settings.lotOccupancy.prints");
const occupancyTypePrintTitles = {};
for (const printEJS of occupancyTypePrints) {
const printConfig = printFunctions.getPrintConfig(printEJS);
if (printConfig) {
occupancyTypePrintTitles[printEJS] = printConfig.title;
}
}
response.render("admin-occupancyTypes", {
headTitle: configFunctions.getProperty("aliases.occupancy") + " Type Management",
occupancyTypes,
allOccupancyTypeFields
allOccupancyTypeFields,
occupancyTypePrintTitles
});
};

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,13 @@
import { addOccupancyTypePrint } from "../../helpers/lotOccupancyDB/addOccupancyTypePrint.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = addOccupancyTypePrint(request.body, request.session);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,20 @@
import type { RequestHandler } from "express";
import { addOccupancyTypePrint } from "../../helpers/lotOccupancyDB/addOccupancyTypePrint.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = addOccupancyTypePrint(request.body, request.session);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,13 @@
import { deleteOccupancyTypePrint } from "../../helpers/lotOccupancyDB/deleteOccupancyTypePrint.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = deleteOccupancyTypePrint(request.body.occupancyTypeId, request.body.printEJS, request.session);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,24 @@
import type { RequestHandler } from "express";
import { deleteOccupancyTypePrint } from "../../helpers/lotOccupancyDB/deleteOccupancyTypePrint.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = deleteOccupancyTypePrint(
request.body.occupancyTypeId,
request.body.printEJS,
request.session
);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,15 @@
import { moveOccupancyTypePrintDown, moveOccupancyTypePrintDownToBottom } from "../../helpers/lotOccupancyDB/moveOccupancyTypePrintDown.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = request.body.moveToBottom === "1"
? moveOccupancyTypePrintDownToBottom(request.body.occupancyTypeId, request.body.printEJS)
: moveOccupancyTypePrintDown(request.body.occupancyTypeId, request.body.printEJS);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,26 @@
import type { RequestHandler } from "express";
import {
moveOccupancyTypePrintDown,
moveOccupancyTypePrintDownToBottom
} from "../../helpers/lotOccupancyDB/moveOccupancyTypePrintDown.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success =
request.body.moveToBottom === "1"
? moveOccupancyTypePrintDownToBottom(request.body.occupancyTypeId, request.body.printEJS)
: moveOccupancyTypePrintDown(request.body.occupancyTypeId, request.body.printEJS);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,15 @@
import { moveOccupancyTypePrintUp, moveOccupancyTypePrintUpToTop } from "../../helpers/lotOccupancyDB/moveOccupancyTypePrintUp.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = request.body.moveToTop === "1"
? moveOccupancyTypePrintUpToTop(request.body.occupancyTypeId, request.body.printEJS)
: moveOccupancyTypePrintUp(request.body.occupancyTypeId, request.body.printEJS);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,26 @@
import type { RequestHandler } from "express";
import {
moveOccupancyTypePrintUp,
moveOccupancyTypePrintUpToTop
} from "../../helpers/lotOccupancyDB/moveOccupancyTypePrintUp.js";
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success =
request.body.moveToTop === "1"
? moveOccupancyTypePrintUpToTop(request.body.occupancyTypeId, request.body.printEJS)
: moveOccupancyTypePrintUp(request.body.occupancyTypeId, request.body.printEJS);
const occupancyTypes = getOccupancyTypes();
const allOccupancyTypeFields = getAllOccupancyTypeFields();
response.json({
success,
occupancyTypes,
allOccupancyTypeFields
});
};
export default handler;

View File

@ -0,0 +1,8 @@
import type * as recordTypes from "../../types/recordTypes";
interface OccupancyTypePrintForm {
occupancyTypeId: string | number;
printEJS: string;
orderNumber?: number;
}
export declare const addOccupancyTypePrint: (occupancyTypePrintForm: OccupancyTypePrintForm, requestSession: recordTypes.PartialSession) => boolean;
export default addOccupancyTypePrint;

View File

@ -0,0 +1,30 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
export const addOccupancyTypePrint = (occupancyTypePrintForm, requestSession) => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
let result = database
.prepare("update OccupancyTypePrints" +
" set recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?," +
" recordDelete_userName = null," +
" recordDelete_timeMillis = null" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.run(requestSession.user.userName, rightNowMillis, occupancyTypePrintForm.occupancyTypeId, occupancyTypePrintForm.printEJS);
if (result.changes === 0) {
result = database
.prepare("insert into OccupancyTypePrints (" +
"occupancyTypeId, printEJS," +
" orderNumber," +
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?)")
.run(occupancyTypePrintForm.occupancyTypeId, occupancyTypePrintForm.printEJS, occupancyTypePrintForm.orderNumber || -1, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
}
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export default addOccupancyTypePrint;

View File

@ -0,0 +1,68 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
import type * as recordTypes from "../../types/recordTypes";
interface OccupancyTypePrintForm {
occupancyTypeId: string | number;
printEJS: string;
orderNumber?: number;
}
export const addOccupancyTypePrint = (
occupancyTypePrintForm: OccupancyTypePrintForm,
requestSession: recordTypes.PartialSession
): boolean => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
let result = database
.prepare(
"update OccupancyTypePrints" +
" set recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?," +
" recordDelete_userName = null," +
" recordDelete_timeMillis = null" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.run(
requestSession.user.userName,
rightNowMillis,
occupancyTypePrintForm.occupancyTypeId,
occupancyTypePrintForm.printEJS
);
if (result.changes === 0) {
result = database
.prepare(
"insert into OccupancyTypePrints (" +
"occupancyTypeId, printEJS," +
" orderNumber," +
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?)"
)
.run(
occupancyTypePrintForm.occupancyTypeId,
occupancyTypePrintForm.printEJS,
occupancyTypePrintForm.orderNumber || -1,
requestSession.user.userName,
rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
}
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export default addOccupancyTypePrint;

View File

@ -0,0 +1,3 @@
import type * as recordTypes from "../../types/recordTypes";
export declare const deleteOccupancyTypePrint: (occupancyTypeId: number | string, printEJS: string, requestSession: recordTypes.PartialSession) => boolean;
export default deleteOccupancyTypePrint;

View File

@ -0,0 +1,18 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
export const deleteOccupancyTypePrint = (occupancyTypeId, printEJS, requestSession) => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
const result = database
.prepare("update OccupancyTypePrints" +
" set recordDelete_userName = ?," +
" recordDelete_timeMillis = ?" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.run(requestSession.user.userName, rightNowMillis, occupancyTypeId, printEJS);
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export default deleteOccupancyTypePrint;

View File

@ -0,0 +1,35 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
import type * as recordTypes from "../../types/recordTypes";
export const deleteOccupancyTypePrint = (
occupancyTypeId: number | string,
printEJS: string,
requestSession: recordTypes.PartialSession
): boolean => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
const result = database
.prepare(
"update OccupancyTypePrints" +
" set recordDelete_userName = ?," +
" recordDelete_timeMillis = ?" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.run(requestSession.user.userName, rightNowMillis, occupancyTypeId, printEJS);
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export default deleteOccupancyTypePrint;

View File

@ -25,7 +25,7 @@ export const getOccupancyTypePrints = (occupancyTypeId, connectedDatabase) => {
expectedOrderNumber += 1;
if (result.orderNumber !== expectedOrderNumber) {
database
.prepare("update OccupancyTypeFields" +
.prepare("update OccupancyTypePrints" +
" set orderNumber = ?" +
" where occupancyTypeId = ?" +
" and printEJS = ?")

View File

@ -42,7 +42,7 @@ export const getOccupancyTypePrints = (
if (result.orderNumber !== expectedOrderNumber) {
database
.prepare(
"update OccupancyTypeFields" +
"update OccupancyTypePrints" +
" set orderNumber = ?" +
" where occupancyTypeId = ?" +
" and printEJS = ?"

View File

@ -0,0 +1,3 @@
export declare const moveOccupancyTypePrintDown: (occupancyTypeId: number | string, printEJS: string) => boolean;
export declare const moveOccupancyTypePrintDownToBottom: (occupancyTypeId: number | string, printEJS: string) => boolean;
export default moveOccupancyTypePrintDown;

View File

@ -0,0 +1,61 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
export const moveOccupancyTypePrintDown = (occupancyTypeId, printEJS) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.get(occupancyTypeId, printEJS).orderNumber;
database
.prepare("update OccupancyTypePrints" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = '" + occupancyTypeId + "'" +
" and orderNumber = ? + 1")
.run(currentOrderNumber);
const result = database
.prepare("update OccupancyTypePrints" +
" set orderNumber = ? + 1" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.run(currentOrderNumber, occupancyTypeId, printEJS);
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export const moveOccupancyTypePrintDownToBottom = (occupancyTypeId, printEJS) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.get(occupancyTypeId, printEJS).orderNumber;
const maxOrderNumber = database
.prepare("select max(orderNumber) as maxOrderNumber" +
" from OccupancyTypePrints" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = ?")
.get(occupancyTypeId).maxOrderNumber;
if (currentOrderNumber !== maxOrderNumber) {
database
.prepare("update OccupancyTypePrints set orderNumber = ? + 1" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.run(maxOrderNumber, occupancyTypeId, printEJS);
database
.prepare("update OccupancyTypeFields" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = ?" +
" and orderNumber > ?")
.run(occupancyTypeId, currentOrderNumber);
}
database.close();
clearOccupancyTypesCache();
return true;
};
export default moveOccupancyTypePrintDown;

View File

@ -0,0 +1,96 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
export const moveOccupancyTypePrintDown = (occupancyTypeId: number | string, printEJS: string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare(
"select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.get(occupancyTypeId, printEJS).orderNumber;
database
.prepare(
"update OccupancyTypePrints" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = '" + occupancyTypeId + "'" +
" and orderNumber = ? + 1"
)
.run(currentOrderNumber);
const result = database
.prepare(
"update OccupancyTypePrints" +
" set orderNumber = ? + 1" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.run(currentOrderNumber, occupancyTypeId, printEJS);
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export const moveOccupancyTypePrintDownToBottom = (
occupancyTypeId: number | string,
printEJS: string
): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare(
"select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.get(occupancyTypeId, printEJS).orderNumber;
const maxOrderNumber: number = database
.prepare(
"select max(orderNumber) as maxOrderNumber" +
" from OccupancyTypePrints" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = ?"
)
.get(occupancyTypeId).maxOrderNumber;
if (currentOrderNumber !== maxOrderNumber) {
database
.prepare(
"update OccupancyTypePrints set orderNumber = ? + 1" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.run(maxOrderNumber, occupancyTypeId, printEJS);
database
.prepare(
"update OccupancyTypeFields" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = ?" +
" and orderNumber > ?"
)
.run(occupancyTypeId, currentOrderNumber);
}
database.close();
clearOccupancyTypesCache();
return true;
};
export default moveOccupancyTypePrintDown;

View File

@ -0,0 +1,3 @@
export declare const moveOccupancyTypePrintUp: (occupancyTypeId: number | string, printEJS: string) => boolean;
export declare const moveOccupancyTypePrintUpToTop: (occupancyTypeId: number | string, printEJS: string) => boolean;
export default moveOccupancyTypePrintUp;

View File

@ -0,0 +1,59 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
export const moveOccupancyTypePrintUp = (occupancyTypeId, printEJS) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.get(occupancyTypeId, printEJS).orderNumber;
if (currentOrderNumber <= 0) {
database.close();
return true;
}
database
.prepare("update OccupancyTypePrints" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = '" + occupancyTypeId + "'" +
" and orderNumber = ? - 1")
.run(currentOrderNumber);
const result = database
.prepare("update OccupancyTypePrints" +
" set orderNumber = ? - 1" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.run(currentOrderNumber, occupancyTypeId, printEJS);
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export const moveOccupancyTypePrintUpToTop = (occupancyTypeId, printEJS) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.get(occupancyTypeId, printEJS).orderNumber;
if (currentOrderNumber > 0) {
database
.prepare("update OccupancyTypePrints set orderNumber = -1" +
" where occupancyTypeId = ?" +
" and printEJS = ?")
.run(occupancyTypeId, printEJS);
database
.prepare("update OccupancyTypePrints" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = ?" +
" and orderNumber < ?")
.run(occupancyTypeId, currentOrderNumber);
}
database.close();
clearOccupancyTypesCache();
return true;
};
export default moveOccupancyTypePrintUp;

View File

@ -0,0 +1,89 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearOccupancyTypesCache } from "../functions.cache.js";
export const moveOccupancyTypePrintUp = (occupancyTypeId: number | string, printEJS: string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare(
"select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.get(occupancyTypeId, printEJS).orderNumber;
if (currentOrderNumber <= 0) {
database.close();
return true;
}
database
.prepare(
"update OccupancyTypePrints" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = '" + occupancyTypeId + "'" +
" and orderNumber = ? - 1"
)
.run(currentOrderNumber);
const result = database
.prepare(
"update OccupancyTypePrints" +
" set orderNumber = ? - 1" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.run(currentOrderNumber, occupancyTypeId, printEJS);
database.close();
clearOccupancyTypesCache();
return result.changes > 0;
};
export const moveOccupancyTypePrintUpToTop = (occupancyTypeId: number | string, printEJS: string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare(
"select orderNumber" +
" from OccupancyTypePrints" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.get(occupancyTypeId, printEJS).orderNumber;
if (currentOrderNumber > 0) {
database
.prepare(
"update OccupancyTypePrints set orderNumber = -1" +
" where occupancyTypeId = ?" +
" and printEJS = ?"
)
.run(occupancyTypeId, printEJS);
database
.prepare(
"update OccupancyTypePrints" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and occupancyTypeId = ?" +
" and orderNumber < ?"
)
.run(occupancyTypeId, currentOrderNumber);
}
database.close();
clearOccupancyTypesCache();
return true;
};
export default moveOccupancyTypePrintUp;

View File

@ -2,7 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
(() => {
const los = exports.los;
const containerElement = document.querySelector("#container--occupancyTypes");
const occupancyTypesContainerElement = document.querySelector("#container--occupancyTypes");
const occupancyTypePrintsContainerElement = document.querySelector("#container--occupancyTypePrints");
let occupancyTypes = exports.occupancyTypes;
delete exports.occupancyTypes;
let allOccupancyTypeFields = exports.allOccupancyTypeFields;
@ -309,13 +310,153 @@ Object.defineProperty(exports, "__esModule", { value: true });
}
}
};
const openAddOccupancyTypePrint = (clickEvent) => {
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyTypePrintList").dataset.occupancyTypeId;
let closeAddModalFunction;
const doAdd = (formEvent) => {
formEvent.preventDefault();
cityssm.postJSON(los.urlPrefix + "/admin/doAddOccupancyTypePrint", formEvent.currentTarget, (responseJSON) => {
if (responseJSON.success) {
closeAddModalFunction();
}
occupancyTypeResponseHandler(responseJSON);
});
};
cityssm.openHtmlModal("adminOccupancyTypes-addOccupancyTypePrint", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
modalElement.querySelector("#occupancyTypePrintAdd--occupancyTypeId").value = occupancyTypeId;
const printSelectElement = modalElement.querySelector("#occupancyTypePrintAdd--printEJS");
for (const [printEJS, printTitle] of Object.entries(exports.occupancyTypePrintTitles)) {
const optionElement = document.createElement("option");
optionElement.value = printEJS;
optionElement.textContent = printTitle;
printSelectElement.append(optionElement);
}
},
onshown: (modalElement, closeModalFunction) => {
var _a;
closeAddModalFunction = closeModalFunction;
(_a = modalElement.querySelector("form")) === null || _a === void 0 ? void 0 : _a.addEventListener("submit", doAdd);
}
});
};
const moveOccupancyTypePrintUp = (clickEvent) => {
clickEvent.preventDefault();
const printEJS = clickEvent.currentTarget.closest(".container--occupancyTypePrint").dataset.printEJS;
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyTypePrintList").dataset.occupancyTypeId;
cityssm.postJSON(los.urlPrefix + "/admin/doMoveOccupancyTypePrintUp", {
occupancyTypeId,
printEJS,
moveToTop: clickEvent.shiftKey ? "1" : "0"
}, occupancyTypeResponseHandler);
};
const moveOccupancyTypePrintDown = (clickEvent) => {
clickEvent.preventDefault();
const printEJS = clickEvent.currentTarget.closest(".container--occupancyTypePrint").dataset.printEJS;
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyTypePrintList").dataset.occupancyTypeId;
cityssm.postJSON(los.urlPrefix + "/admin/doMoveOccupancyTypePrintDown", {
occupancyTypeId,
printEJS,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
}, occupancyTypeResponseHandler);
};
const deleteOccupancyTypePrint = (clickEvent) => {
clickEvent.preventDefault();
const printEJS = clickEvent.currentTarget.closest(".container--occupancyTypePrint").dataset.printEJS;
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyTypePrintList").dataset.occupancyTypeId;
const doDelete = () => {
cityssm.postJSON(los.urlPrefix + "/admin/doDeleteOccupancyTypePrint", {
occupancyTypeId,
printEJS
}, occupancyTypeResponseHandler);
};
bulmaJS.confirm({
title: "Delete Print",
message: "Are you sure you want to remove this print option?",
contextualColorName: "warning",
okButton: {
text: "Yes, Remove Print",
callbackFunction: doDelete
}
});
};
const renderOccupancyTypePrints = (panelElement, occupancyTypeId, occupancyTypePrints) => {
if (occupancyTypePrints.length === 0) {
panelElement.insertAdjacentHTML("beforeend", '<div class="panel-block is-block">' +
'<div class="message is-info">' +
'<p class="message-body">There are no prints associated with this record.</p>' +
"</div>" +
"</div>");
}
else {
for (const printEJS of occupancyTypePrints) {
const panelBlockElement = document.createElement("div");
panelBlockElement.className = "panel-block is-block container--occupancyTypePrint";
panelBlockElement.dataset.printEJS = printEJS;
const printTitle = printEJS === "*"
? "(All Available Prints)"
: exports.occupancyTypePrintTitles[printEJS];
let printIconClass = "fa-star";
if (printEJS.startsWith("pdf/")) {
printIconClass = "fa-file-pdf";
}
else if (printEJS.startsWith("screen/")) {
printIconClass = "fa-file";
}
panelBlockElement.innerHTML =
'<div class="level is-mobile">' +
'<div class="level-left">' +
('<div class="level-item">' +
'<i class="fas fa-fw ' +
printIconClass +
'" aria-hidden="true"></i>' +
"</div>") +
('<div class="level-item">' +
cityssm.escapeHTML(printTitle || printEJS) +
"</div>") +
"</div>" +
'<div class="level-right">' +
('<div class="level-item">' +
'<div class="field has-addons">' +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypePrintUp" data-tooltip="Move Up" type="button" aria-label="Move Up">' +
'<i class="fas fa-arrow-up" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypePrintDown" data-tooltip="Move Down" type="button" aria-label="Move Down">' +
'<i class="fas fa-arrow-down" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-small is-danger button--deleteOccupancyTypePrint" data-tooltip="Delete" type="button" aria-label="Delete Print">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>") +
"</div>" +
"</div>";
panelBlockElement.querySelector(".button--moveOccupancyTypePrintUp").addEventListener("click", moveOccupancyTypePrintUp);
panelBlockElement.querySelector(".button--moveOccupancyTypePrintDown").addEventListener("click", moveOccupancyTypePrintDown);
panelBlockElement.querySelector(".button--deleteOccupancyTypePrint").addEventListener("click", deleteOccupancyTypePrint);
panelElement.append(panelBlockElement);
}
}
};
const renderOccupancyTypes = () => {
containerElement.innerHTML =
occupancyTypesContainerElement.innerHTML =
'<div class="panel container--occupancyType" id="container--allOccupancyTypeFields" data-occupancy-type-id="">' +
'<div class="panel-heading">' +
('<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item"><h2 class="title is-4">(All ' + cityssm.escapeHTML(exports.aliases.occupancy) + ' Types)</h2></div>' +
'<div class="level-item">' +
('<h2 class="title is-4">(All ' +
cityssm.escapeHTML(exports.aliases.occupancy) +
" Types)</h2>") +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
@ -328,10 +469,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
"</div>") +
"</div>" +
"</div>";
renderOccupancyTypeFields(containerElement.querySelector("#container--allOccupancyTypeFields"), undefined, allOccupancyTypeFields);
containerElement.querySelector(".button--addOccupancyTypeField").addEventListener("click", openAddOccupancyTypeField);
occupancyTypePrintsContainerElement.innerHTML = "";
renderOccupancyTypeFields(occupancyTypesContainerElement.querySelector("#container--allOccupancyTypeFields"), undefined, allOccupancyTypeFields);
occupancyTypesContainerElement.querySelector(".button--addOccupancyTypeField").addEventListener("click", openAddOccupancyTypeField);
if (occupancyTypes.length === 0) {
containerElement.insertAdjacentHTML("afterbegin", '<div class="message is-warning>' +
occupancyTypesContainerElement.insertAdjacentHTML("afterbegin", '<div class="message is-warning>' +
'<p class="message-body">There are no active ' +
exports.aliases.occupancy.toLowerCase() +
" types.</p>" +
"</div>");
occupancyTypePrintsContainerElement.insertAdjacentHTML("afterbegin", '<div class="message is-warning>' +
'<p class="message-body">There are no active ' +
exports.aliases.occupancy.toLowerCase() +
" types.</p>" +
@ -339,73 +486,104 @@ Object.defineProperty(exports, "__esModule", { value: true });
return;
}
for (const occupancyType of occupancyTypes) {
const occupancyTypeContainer = document.createElement("div");
occupancyTypeContainer.className = "panel container--occupancyType";
occupancyTypeContainer.dataset.occupancyTypeId =
occupancyType.occupancyTypeId.toString();
occupancyTypeContainer.innerHTML =
'<div class="panel-heading">' +
'<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item">' +
'<button class="button is-small button--toggleOccupancyTypeFields" data-tooltip="Toggle Fields" type="button" aria-label="Toggle Fields">' +
(expandedOccupancyTypes.has(occupancyType.occupancyTypeId)
? '<i class="fas fa-fw fa-minus" aria-hidden="true"></i>'
: '<i class="fas fa-fw fa-plus" aria-hidden="true"></i>') +
"</button>" +
{
const occupancyTypeContainer = document.createElement("div");
occupancyTypeContainer.className = "panel container--occupancyType";
occupancyTypeContainer.dataset.occupancyTypeId =
occupancyType.occupancyTypeId.toString();
occupancyTypeContainer.innerHTML =
'<div class="panel-heading">' +
'<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item">' +
'<button class="button is-small button--toggleOccupancyTypeFields" data-tooltip="Toggle Fields" type="button" aria-label="Toggle Fields">' +
(expandedOccupancyTypes.has(occupancyType.occupancyTypeId)
? '<i class="fas fa-fw fa-minus" aria-hidden="true"></i>'
: '<i class="fas fa-fw fa-plus" aria-hidden="true"></i>') +
"</button>" +
"</div>" +
'<div class="level-item">' +
'<h2 class="title is-4">' +
cityssm.escapeHTML(occupancyType.occupancyType) +
"</h2>" +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
'<button class="button is-danger is-small button--deleteOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-trash" aria-hidden="true"></i></span>' +
"<span>Delete</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-primary is-small button--editOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
"<span>Edit " +
exports.aliases.occupancy +
" Type</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-success is-small button--addOccupancyTypeField" type="button">' +
'<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>' +
"<span>Add Field</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<div class="field has-addons">' +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeUp" data-tooltip="Move Up" type="button" aria-label="Move Up">' +
'<i class="fas fa-arrow-up" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeDown" data-tooltip="Move Down" type="button" aria-label="Move Down">' +
'<i class="fas fa-arrow-down" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>" +
"</div>") +
"</div>") +
"</div>" +
'<div class="level-item">' +
'<h2 class="title is-4">' +
cityssm.escapeHTML(occupancyType.occupancyType) +
"</h2>" +
"</div>";
renderOccupancyTypeFields(occupancyTypeContainer, occupancyType.occupancyTypeId, occupancyType.occupancyTypeFields);
occupancyTypeContainer.querySelector(".button--toggleOccupancyTypeFields").addEventListener("click", toggleOccupancyTypeFields);
occupancyTypeContainer.querySelector(".button--deleteOccupancyType").addEventListener("click", deleteOccupancyType);
occupancyTypeContainer.querySelector(".button--editOccupancyType").addEventListener("click", openEditOccupancyType);
occupancyTypeContainer.querySelector(".button--addOccupancyTypeField").addEventListener("click", openAddOccupancyTypeField);
occupancyTypeContainer.querySelector(".button--moveOccupancyTypeUp").addEventListener("click", moveOccupancyTypeUp);
occupancyTypeContainer.querySelector(".button--moveOccupancyTypeDown").addEventListener("click", moveOccupancyTypeDown);
occupancyTypesContainerElement.append(occupancyTypeContainer);
}
{
const occupancyTypePrintContainer = document.createElement("div");
occupancyTypePrintContainer.className = "panel container--occupancyTypePrintList";
occupancyTypePrintContainer.dataset.occupancyTypeId =
occupancyType.occupancyTypeId.toString();
occupancyTypePrintContainer.innerHTML =
'<div class="panel-heading">' +
'<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item">' +
'<h2 class="title is-4">' +
cityssm.escapeHTML(occupancyType.occupancyType) +
"</h2>" +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
'<button class="button is-success is-small button--addOccupancyTypePrint" type="button">' +
'<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>' +
"<span>Add Print</span>" +
"</button>" +
"</div>") +
"</div>") +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
'<button class="button is-danger is-small button--deleteOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-trash" aria-hidden="true"></i></span>' +
"<span>Delete</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-primary is-small button--editOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
"<span>Edit " +
exports.aliases.occupancy +
" Type</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-success is-small button--addOccupancyTypeField" type="button">' +
'<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>' +
"<span>Add Field</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<div class="field has-addons">' +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeUp" data-tooltip="Move Up" type="button" aria-label="Move Up">' +
'<i class="fas fa-arrow-up" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeDown" data-tooltip="Move Down" type="button" aria-label="Move Down">' +
'<i class="fas fa-arrow-down" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>" +
"</div>") +
"</div>") +
"</div>" +
"</div>";
renderOccupancyTypeFields(occupancyTypeContainer, occupancyType.occupancyTypeId, occupancyType.occupancyTypeFields);
occupancyTypeContainer.querySelector(".button--toggleOccupancyTypeFields").addEventListener("click", toggleOccupancyTypeFields);
occupancyTypeContainer.querySelector(".button--deleteOccupancyType").addEventListener("click", deleteOccupancyType);
occupancyTypeContainer.querySelector(".button--editOccupancyType").addEventListener("click", openEditOccupancyType);
occupancyTypeContainer.querySelector(".button--addOccupancyTypeField").addEventListener("click", openAddOccupancyTypeField);
occupancyTypeContainer.querySelector(".button--moveOccupancyTypeUp").addEventListener("click", moveOccupancyTypeUp);
occupancyTypeContainer.querySelector(".button--moveOccupancyTypeDown").addEventListener("click", moveOccupancyTypeDown);
containerElement.append(occupancyTypeContainer);
"</div>";
renderOccupancyTypePrints(occupancyTypePrintContainer, occupancyType.occupancyTypeId, occupancyType.occupancyTypePrints);
occupancyTypePrintContainer.querySelector(".button--addOccupancyTypePrint").addEventListener("click", openAddOccupancyTypePrint);
occupancyTypePrintsContainerElement.append(occupancyTypePrintContainer);
}
}
};
document.querySelector("#button--addOccupancyType").addEventListener("click", () => {

View File

@ -13,7 +13,12 @@ declare const bulmaJS: BulmaJS;
(() => {
const los = exports.los as globalTypes.LOS;
const containerElement = document.querySelector("#container--occupancyTypes") as HTMLElement;
const occupancyTypesContainerElement = document.querySelector(
"#container--occupancyTypes"
) as HTMLElement;
const occupancyTypePrintsContainerElement = document.querySelector(
"#container--occupancyTypePrints"
) as HTMLElement;
let occupancyTypes: recordTypes.OccupancyType[] = exports.occupancyTypes;
delete exports.occupancyTypes;
@ -588,13 +593,260 @@ declare const bulmaJS: BulmaJS;
}
};
const openAddOccupancyTypePrint = (clickEvent: MouseEvent) => {
const occupancyTypeId = (
(clickEvent.currentTarget as HTMLElement).closest(
".container--occupancyTypePrintList"
) as HTMLElement
).dataset.occupancyTypeId!;
let closeAddModalFunction: () => void;
const doAdd = (formEvent: SubmitEvent) => {
formEvent.preventDefault();
cityssm.postJSON(
los.urlPrefix + "/admin/doAddOccupancyTypePrint",
formEvent.currentTarget,
(responseJSON: {
success: boolean;
errorMessage?: string;
occupancyTypes?: recordTypes.OccupancyType[];
allOccupancyTypeFields?: recordTypes.OccupancyTypeField[];
}) => {
if (responseJSON.success) {
closeAddModalFunction();
}
occupancyTypeResponseHandler(responseJSON);
}
);
};
cityssm.openHtmlModal("adminOccupancyTypes-addOccupancyTypePrint", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
(
modalElement.querySelector(
"#occupancyTypePrintAdd--occupancyTypeId"
) as HTMLInputElement
).value = occupancyTypeId;
const printSelectElement = modalElement.querySelector(
"#occupancyTypePrintAdd--printEJS"
) as HTMLSelectElement;
for (const [printEJS, printTitle] of Object.entries(
exports.occupancyTypePrintTitles
)) {
const optionElement = document.createElement("option");
optionElement.value = printEJS;
optionElement.textContent = printTitle as string;
printSelectElement.append(optionElement);
}
},
onshown: (modalElement, closeModalFunction) => {
closeAddModalFunction = closeModalFunction;
modalElement.querySelector("form")?.addEventListener("submit", doAdd);
}
});
};
const moveOccupancyTypePrintUp = (clickEvent: MouseEvent) => {
clickEvent.preventDefault();
const printEJS = (
(clickEvent.currentTarget as HTMLElement).closest(
".container--occupancyTypePrint"
) as HTMLElement
).dataset.printEJS;
const occupancyTypeId = (
(clickEvent.currentTarget as HTMLElement).closest(
".container--occupancyTypePrintList"
) as HTMLElement
).dataset.occupancyTypeId;
cityssm.postJSON(
los.urlPrefix + "/admin/doMoveOccupancyTypePrintUp",
{
occupancyTypeId,
printEJS,
moveToTop: clickEvent.shiftKey ? "1" : "0"
},
occupancyTypeResponseHandler
);
};
const moveOccupancyTypePrintDown = (clickEvent: MouseEvent) => {
clickEvent.preventDefault();
const printEJS = (
(clickEvent.currentTarget as HTMLElement).closest(
".container--occupancyTypePrint"
) as HTMLElement
).dataset.printEJS;
const occupancyTypeId = (
(clickEvent.currentTarget as HTMLElement).closest(
".container--occupancyTypePrintList"
) as HTMLElement
).dataset.occupancyTypeId;
cityssm.postJSON(
los.urlPrefix + "/admin/doMoveOccupancyTypePrintDown",
{
occupancyTypeId,
printEJS,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
},
occupancyTypeResponseHandler
);
};
const deleteOccupancyTypePrint = (clickEvent: MouseEvent) => {
clickEvent.preventDefault();
const printEJS = (
(clickEvent.currentTarget as HTMLElement).closest(
".container--occupancyTypePrint"
) as HTMLElement
).dataset.printEJS;
const occupancyTypeId = (
(clickEvent.currentTarget as HTMLElement).closest(
".container--occupancyTypePrintList"
) as HTMLElement
).dataset.occupancyTypeId;
const doDelete = () => {
cityssm.postJSON(
los.urlPrefix + "/admin/doDeleteOccupancyTypePrint",
{
occupancyTypeId,
printEJS
},
occupancyTypeResponseHandler
);
};
bulmaJS.confirm({
title: "Delete Print",
message: "Are you sure you want to remove this print option?",
contextualColorName: "warning",
okButton: {
text: "Yes, Remove Print",
callbackFunction: doDelete
}
});
};
const renderOccupancyTypePrints = (
panelElement: HTMLElement,
occupancyTypeId: number,
occupancyTypePrints: string[]
) => {
if (occupancyTypePrints.length === 0) {
panelElement.insertAdjacentHTML(
"beforeend",
'<div class="panel-block is-block">' +
'<div class="message is-info">' +
'<p class="message-body">There are no prints associated with this record.</p>' +
"</div>" +
"</div>"
);
} else {
for (const printEJS of occupancyTypePrints) {
const panelBlockElement = document.createElement("div");
panelBlockElement.className = "panel-block is-block container--occupancyTypePrint";
panelBlockElement.dataset.printEJS = printEJS;
const printTitle =
printEJS === "*"
? "(All Available Prints)"
: (exports.occupancyTypePrintTitles[printEJS] as string);
let printIconClass = "fa-star";
if (printEJS.startsWith("pdf/")) {
printIconClass = "fa-file-pdf";
} else if (printEJS.startsWith("screen/")) {
printIconClass = "fa-file";
}
panelBlockElement.innerHTML =
'<div class="level is-mobile">' +
'<div class="level-left">' +
('<div class="level-item">' +
'<i class="fas fa-fw ' +
printIconClass +
'" aria-hidden="true"></i>' +
"</div>") +
('<div class="level-item">' +
cityssm.escapeHTML(printTitle || printEJS) +
"</div>") +
"</div>" +
'<div class="level-right">' +
('<div class="level-item">' +
'<div class="field has-addons">' +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypePrintUp" data-tooltip="Move Up" type="button" aria-label="Move Up">' +
'<i class="fas fa-arrow-up" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypePrintDown" data-tooltip="Move Down" type="button" aria-label="Move Down">' +
'<i class="fas fa-arrow-down" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-small is-danger button--deleteOccupancyTypePrint" data-tooltip="Delete" type="button" aria-label="Delete Print">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>") +
"</div>" +
"</div>";
(
panelBlockElement.querySelector(
".button--moveOccupancyTypePrintUp"
) as HTMLButtonElement
).addEventListener("click", moveOccupancyTypePrintUp);
(
panelBlockElement.querySelector(
".button--moveOccupancyTypePrintDown"
) as HTMLButtonElement
).addEventListener("click", moveOccupancyTypePrintDown);
(
panelBlockElement.querySelector(
".button--deleteOccupancyTypePrint"
) as HTMLButtonElement
).addEventListener("click", deleteOccupancyTypePrint);
panelElement.append(panelBlockElement);
}
}
};
const renderOccupancyTypes = () => {
containerElement.innerHTML =
occupancyTypesContainerElement.innerHTML =
'<div class="panel container--occupancyType" id="container--allOccupancyTypeFields" data-occupancy-type-id="">' +
'<div class="panel-heading">' +
('<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item"><h2 class="title is-4">(All ' + cityssm.escapeHTML(exports.aliases.occupancy) + ' Types)</h2></div>' +
'<div class="level-item">' +
('<h2 class="title is-4">(All ' +
cityssm.escapeHTML(exports.aliases.occupancy) +
" Types)</h2>") +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
@ -608,18 +860,33 @@ declare const bulmaJS: BulmaJS;
"</div>" +
"</div>";
occupancyTypePrintsContainerElement.innerHTML = "";
renderOccupancyTypeFields(
containerElement.querySelector("#container--allOccupancyTypeFields") as HTMLElement,
occupancyTypesContainerElement.querySelector(
"#container--allOccupancyTypeFields"
) as HTMLElement,
undefined,
allOccupancyTypeFields
);
(
containerElement.querySelector(".button--addOccupancyTypeField") as HTMLButtonElement
occupancyTypesContainerElement.querySelector(
".button--addOccupancyTypeField"
) as HTMLButtonElement
).addEventListener("click", openAddOccupancyTypeField);
if (occupancyTypes.length === 0) {
containerElement.insertAdjacentHTML(
occupancyTypesContainerElement.insertAdjacentHTML(
"afterbegin",
'<div class="message is-warning>' +
'<p class="message-body">There are no active ' +
exports.aliases.occupancy.toLowerCase() +
" types.</p>" +
"</div>"
);
occupancyTypePrintsContainerElement.insertAdjacentHTML(
"afterbegin",
'<div class="message is-warning>' +
'<p class="message-body">There are no active ' +
@ -632,112 +899,162 @@ declare const bulmaJS: BulmaJS;
}
for (const occupancyType of occupancyTypes) {
const occupancyTypeContainer = document.createElement("div");
// Types and Fields
{
const occupancyTypeContainer = document.createElement("div");
occupancyTypeContainer.className = "panel container--occupancyType";
occupancyTypeContainer.className = "panel container--occupancyType";
occupancyTypeContainer.dataset.occupancyTypeId =
occupancyType.occupancyTypeId.toString();
occupancyTypeContainer.dataset.occupancyTypeId =
occupancyType.occupancyTypeId.toString();
occupancyTypeContainer.innerHTML =
'<div class="panel-heading">' +
'<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item">' +
'<button class="button is-small button--toggleOccupancyTypeFields" data-tooltip="Toggle Fields" type="button" aria-label="Toggle Fields">' +
(expandedOccupancyTypes.has(occupancyType.occupancyTypeId)
? '<i class="fas fa-fw fa-minus" aria-hidden="true"></i>'
: '<i class="fas fa-fw fa-plus" aria-hidden="true"></i>') +
"</button>" +
occupancyTypeContainer.innerHTML =
'<div class="panel-heading">' +
'<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item">' +
'<button class="button is-small button--toggleOccupancyTypeFields" data-tooltip="Toggle Fields" type="button" aria-label="Toggle Fields">' +
(expandedOccupancyTypes.has(occupancyType.occupancyTypeId)
? '<i class="fas fa-fw fa-minus" aria-hidden="true"></i>'
: '<i class="fas fa-fw fa-plus" aria-hidden="true"></i>') +
"</button>" +
"</div>" +
'<div class="level-item">' +
'<h2 class="title is-4">' +
cityssm.escapeHTML(occupancyType.occupancyType) +
"</h2>" +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
'<button class="button is-danger is-small button--deleteOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-trash" aria-hidden="true"></i></span>' +
"<span>Delete</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-primary is-small button--editOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
"<span>Edit " +
exports.aliases.occupancy +
" Type</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-success is-small button--addOccupancyTypeField" type="button">' +
'<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>' +
"<span>Add Field</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<div class="field has-addons">' +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeUp" data-tooltip="Move Up" type="button" aria-label="Move Up">' +
'<i class="fas fa-arrow-up" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeDown" data-tooltip="Move Down" type="button" aria-label="Move Down">' +
'<i class="fas fa-arrow-down" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>" +
"</div>") +
"</div>") +
"</div>" +
'<div class="level-item">' +
'<h2 class="title is-4">' +
cityssm.escapeHTML(occupancyType.occupancyType) +
"</h2>" +
"</div>";
renderOccupancyTypeFields(
occupancyTypeContainer,
occupancyType.occupancyTypeId,
occupancyType.occupancyTypeFields!
);
(
occupancyTypeContainer.querySelector(
".button--toggleOccupancyTypeFields"
) as HTMLButtonElement
).addEventListener("click", toggleOccupancyTypeFields);
(
occupancyTypeContainer.querySelector(
".button--deleteOccupancyType"
) as HTMLButtonElement
).addEventListener("click", deleteOccupancyType);
(
occupancyTypeContainer.querySelector(
".button--editOccupancyType"
) as HTMLButtonElement
).addEventListener("click", openEditOccupancyType);
(
occupancyTypeContainer.querySelector(
".button--addOccupancyTypeField"
) as HTMLButtonElement
).addEventListener("click", openAddOccupancyTypeField);
(
occupancyTypeContainer.querySelector(
".button--moveOccupancyTypeUp"
) as HTMLButtonElement
).addEventListener("click", moveOccupancyTypeUp);
(
occupancyTypeContainer.querySelector(
".button--moveOccupancyTypeDown"
) as HTMLButtonElement
).addEventListener("click", moveOccupancyTypeDown);
occupancyTypesContainerElement.append(occupancyTypeContainer);
}
// Prints
{
const occupancyTypePrintContainer = document.createElement("div");
occupancyTypePrintContainer.className = "panel container--occupancyTypePrintList";
occupancyTypePrintContainer.dataset.occupancyTypeId =
occupancyType.occupancyTypeId.toString();
occupancyTypePrintContainer.innerHTML =
'<div class="panel-heading">' +
'<div class="level is-mobile">' +
('<div class="level-left">' +
'<div class="level-item">' +
'<h2 class="title is-4">' +
cityssm.escapeHTML(occupancyType.occupancyType) +
"</h2>" +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
'<button class="button is-success is-small button--addOccupancyTypePrint" type="button">' +
'<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>' +
"<span>Add Print</span>" +
"</button>" +
"</div>") +
"</div>") +
"</div>" +
"</div>") +
('<div class="level-right">' +
('<div class="level-item">' +
'<button class="button is-danger is-small button--deleteOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-trash" aria-hidden="true"></i></span>' +
"<span>Delete</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-primary is-small button--editOccupancyType" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
"<span>Edit " +
exports.aliases.occupancy +
" Type</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<button class="button is-success is-small button--addOccupancyTypeField" type="button">' +
'<span class="icon is-small"><i class="fas fa-plus" aria-hidden="true"></i></span>' +
"<span>Add Field</span>" +
"</button>" +
"</div>") +
('<div class="level-item">' +
'<div class="field has-addons">' +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeUp" data-tooltip="Move Up" type="button" aria-label="Move Up">' +
'<i class="fas fa-arrow-up" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
'<div class="control">' +
'<button class="button is-small button--moveOccupancyTypeDown" data-tooltip="Move Down" type="button" aria-label="Move Down">' +
'<i class="fas fa-arrow-down" aria-hidden="true"></i>' +
"</button>" +
"</div>" +
"</div>" +
"</div>") +
"</div>") +
"</div>" +
"</div>";
"</div>";
renderOccupancyTypeFields(
occupancyTypeContainer,
occupancyType.occupancyTypeId,
occupancyType.occupancyTypeFields!
);
renderOccupancyTypePrints(
occupancyTypePrintContainer,
occupancyType.occupancyTypeId,
occupancyType.occupancyTypePrints!
);
(
occupancyTypeContainer.querySelector(
".button--toggleOccupancyTypeFields"
) as HTMLButtonElement
).addEventListener("click", toggleOccupancyTypeFields);
(
occupancyTypePrintContainer.querySelector(
".button--addOccupancyTypePrint"
) as HTMLButtonElement
).addEventListener("click", openAddOccupancyTypePrint);
(
occupancyTypeContainer.querySelector(
".button--deleteOccupancyType"
) as HTMLButtonElement
).addEventListener("click", deleteOccupancyType);
(
occupancyTypeContainer.querySelector(
".button--editOccupancyType"
) as HTMLButtonElement
).addEventListener("click", openEditOccupancyType);
(
occupancyTypeContainer.querySelector(
".button--addOccupancyTypeField"
) as HTMLButtonElement
).addEventListener("click", openAddOccupancyTypeField);
(
occupancyTypeContainer.querySelector(
".button--moveOccupancyTypeUp"
) as HTMLButtonElement
).addEventListener("click", moveOccupancyTypeUp);
(
occupancyTypeContainer.querySelector(
".button--moveOccupancyTypeDown"
) as HTMLButtonElement
).addEventListener("click", moveOccupancyTypeDown);
containerElement.append(occupancyTypeContainer);
occupancyTypePrintsContainerElement.append(occupancyTypePrintContainer);
}
}
};

View File

@ -0,0 +1,34 @@
<div class="modal" role="dialog">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<h3 class="modal-card-title">
Add <span class="alias" data-alias="Occupancy"></span> Type Print
</h3>
<button class="delete is-close-modal-button" aria-label="close" type="button"></button>
</header>
<section class="modal-card-body">
<form id="form--occupancyTypePrintAdd">
<input class="input" id="occupancyTypePrintAdd--occupancyTypeId" name="occupancyTypeId" type="hidden" />
<div class="field">
<label class="label" for="occupancyTypePrintAdd--printEJS">Print</label>
<div class="control">
<div class="select is-fullwidth">
<select id="occupancyTypePrintAdd--printEJS" name="printEJS" required>
<option value="">(Select a Print)</option>
<option value="*">(All Available Prints)</option>
</select>
</div>
</div>
</div>
</form>
</section>
<footer class="modal-card-foot justify-right">
<button class="button is-success" type="submit" form="form--occupancyTypePrintAdd">
<span class="icon"><i class="fas fa-plus" aria-hidden="true"></i></span>
<span>Add Print</span>
</button>
<button class="button is-close-modal-button" type="button">Cancel</button>
</footer>
</div>
</div>

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,10 @@ import handler_doUpdateOccupancyTypeField from "../handlers/admin-post/doUpdateO
import handler_doMoveOccupancyTypeFieldUp from "../handlers/admin-post/doMoveOccupancyTypeFieldUp.js";
import handler_doMoveOccupancyTypeFieldDown from "../handlers/admin-post/doMoveOccupancyTypeFieldDown.js";
import handler_doDeleteOccupancyTypeField from "../handlers/admin-post/doDeleteOccupancyTypeField.js";
import handler_doAddOccupancyTypePrint from "../handlers/admin-post/doAddOccupancyTypePrint.js";
import handler_doMoveOccupancyTypePrintUp from "../handlers/admin-post/doMoveOccupancyTypePrintUp.js";
import handler_doMoveOccupancyTypePrintDown from "../handlers/admin-post/doMoveOccupancyTypePrintDown.js";
import handler_doDeleteOccupancyTypePrint from "../handlers/admin-post/doDeleteOccupancyTypePrint.js";
import handler_lotTypes from "../handlers/admin-get/lotTypes.js";
import handler_doAddLotType from "../handlers/admin-post/doAddLotType.js";
import handler_doUpdateLotType from "../handlers/admin-post/doUpdateLotType.js";
@ -79,6 +83,10 @@ router.post("/doUpdateOccupancyTypeField", handler_doUpdateOccupancyTypeField);
router.post("/doMoveOccupancyTypeFieldUp", handler_doMoveOccupancyTypeFieldUp);
router.post("/doMoveOccupancyTypeFieldDown", handler_doMoveOccupancyTypeFieldDown);
router.post("/doDeleteOccupancyTypeField", handler_doDeleteOccupancyTypeField);
router.post("/doAddOccupancyTypePrint", handler_doAddOccupancyTypePrint);
router.post("/doMoveOccupancyTypePrintUp", handler_doMoveOccupancyTypePrintUp);
router.post("/doMoveOccupancyTypePrintDown", handler_doMoveOccupancyTypePrintDown);
router.post("/doDeleteOccupancyTypePrint", handler_doDeleteOccupancyTypePrint);
router.get("/lotTypes", handler_lotTypes);
router.post("/doAddLotType", handler_doAddLotType);
router.post("/doUpdateLotType", handler_doUpdateLotType);

View File

@ -32,6 +32,11 @@ import handler_doMoveOccupancyTypeFieldUp from "../handlers/admin-post/doMoveOcc
import handler_doMoveOccupancyTypeFieldDown from "../handlers/admin-post/doMoveOccupancyTypeFieldDown.js";
import handler_doDeleteOccupancyTypeField from "../handlers/admin-post/doDeleteOccupancyTypeField.js";
import handler_doAddOccupancyTypePrint from "../handlers/admin-post/doAddOccupancyTypePrint.js";
import handler_doMoveOccupancyTypePrintUp from "../handlers/admin-post/doMoveOccupancyTypePrintUp.js";
import handler_doMoveOccupancyTypePrintDown from "../handlers/admin-post/doMoveOccupancyTypePrintDown.js";
import handler_doDeleteOccupancyTypePrint from "../handlers/admin-post/doDeleteOccupancyTypePrint.js";
// Lot Type Management
import handler_lotTypes from "../handlers/admin-get/lotTypes.js";
@ -141,6 +146,16 @@ router.post("/doMoveOccupancyTypeFieldDown", handler_doMoveOccupancyTypeFieldDow
router.post("/doDeleteOccupancyTypeField", handler_doDeleteOccupancyTypeField);
// Occupancy Type Prints
router.post("/doAddOccupancyTypePrint", handler_doAddOccupancyTypePrint);
router.post("/doMoveOccupancyTypePrintUp", handler_doMoveOccupancyTypePrintUp);
router.post("/doMoveOccupancyTypePrintDown", handler_doMoveOccupancyTypePrintDown);
router.post("/doDeleteOccupancyTypePrint", handler_doDeleteOccupancyTypePrint);
/*
* Lot Type Management
*/

View File

@ -41,7 +41,48 @@
</div>
</div>
<div id="container--occupancyTypes"></div>
<div class="tabs is-boxed">
<ul>
<li class="is-active">
<a href="#tab--occupancyTypes">
<i class="fas fa-user-friends" aria-hidden="true"></i>
<span class="ml-2">Types and Fields</span>
</a>
</li>
<li>
<a href="#tab--occupancyTypePrints">
<i class="fas fa-print" aria-hidden="true"></i>
<span class="ml-2">Prints</span>
</a>
</li>
</ul>
</div>
<div class="tab-container">
<div id="tab--occupancyTypes">
<div id="container--occupancyTypes"></div>
</div>
<div class="is-hidden" id="tab--occupancyTypePrints">
<div class="columns">
<div class="column">
<div id="container--occupancyTypePrints"></div>
</div>
<div class="column is-4">
<div class="box">
<h2 class="title is-6">Available Prints</h2>
<ul class="fa-ul">
<% for (const [printEJS, printTitle] of Object.entries(occupancyTypePrintTitles)) { %>
<% const printIconClass = printEJS.startsWith("pdf/") ? "fa-file-pdf" : "fa-file" %>
<li>
<span class="fa-li"><i class="fas <%= printIconClass %>" aria-hidden="true"></i></span>
<%= printTitle %>
</li>
<% } %>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@ -50,6 +91,7 @@
<script>
exports.occupancyTypes = <%- JSON.stringify(occupancyTypes) %>;
exports.allOccupancyTypeFields = <%- JSON.stringify(allOccupancyTypeFields) %>;
exports.occupancyTypePrintTitles = <%- JSON.stringify(occupancyTypePrintTitles) %>;
</script>
<script src="<%= urlPrefix %>/javascripts/adminOccupancyTypes.min.js"></script>

View File

@ -314,8 +314,9 @@
</h2>
<p>
Manage
<%= configFunctions.getProperty("aliases.occupancy").toLowerCase() %> types
and fields associated with them.
<%= configFunctions.getProperty("aliases.occupancy").toLowerCase() %> types,
the fields associated with them,
and their available print options.
</p>
</div>
</div>