forked from UKSOURCE/cms.lams
Implement a more flexible, configuration-driven approach for CMS editors across accreditation, admissions, and partnerships modules. - Move UI labels, help texts, and field limits from hardcoded views to `editorUi` configurations in config files. - Add server-side and client-side validation to prevent duplicate category tabs in accreditation and partnerships editors. - Refactor partnership and admission views to dynamically render tabs and fields based on the provided configuration. - Update field length constraints and default values across multiple content editors to better align with frontend requirements. - Improve the admissions calculator editor with dynamic field configurations and default value fallbacks.
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
const AccreditationPage = require("../models/accreditationPage");
|
|
const AUDIT_ACTIONS = require("../constants/auditAction");
|
|
const accreditationConfig = require("../utils/contentEditors/accreditationConfig");
|
|
const createPageContentController = require("./_createPageContentController");
|
|
const createRenderSingletonPageView = require("./_renderSingletonPageView");
|
|
|
|
const controller = createPageContentController({
|
|
model: AccreditationPage,
|
|
modelName: "AccreditationPage",
|
|
auditAction: AUDIT_ACTIONS.UPDATE_ACCREDITATION,
|
|
editorConfig: accreditationConfig,
|
|
preparePayload(rawPayload) {
|
|
const payload = JSON.parse(JSON.stringify(rawPayload || {}));
|
|
const tabs = Array.isArray(payload?.grid?.tabs) ? payload.grid.tabs : [];
|
|
const seenTabs = new Set();
|
|
const duplicateTabs = [];
|
|
|
|
tabs.forEach((tab) => {
|
|
const normalizedTab = String(tab || "").trim().toLowerCase();
|
|
if (!normalizedTab) {
|
|
return;
|
|
}
|
|
|
|
if (seenTabs.has(normalizedTab)) {
|
|
duplicateTabs.push(String(tab || "").trim());
|
|
return;
|
|
}
|
|
|
|
seenTabs.add(normalizedTab);
|
|
});
|
|
|
|
if (duplicateTabs.length > 0) {
|
|
throw new Error(
|
|
`Category tab already exists: ${duplicateTabs[0]}. Please use unique tab names.`,
|
|
);
|
|
}
|
|
|
|
return payload;
|
|
},
|
|
});
|
|
|
|
controller.index = async function index(req, res) {
|
|
try {
|
|
return await createRenderSingletonPageView({
|
|
model: AccreditationPage,
|
|
editorConfig: accreditationConfig,
|
|
view: "admin/accreditation/index",
|
|
})(req, res);
|
|
} catch (error) {
|
|
console.error("accreditation index error:", error);
|
|
req.flash("error_msg", "Error loading Accreditation Management");
|
|
return req.session.save(() => res.redirect("/admin/dashboard"));
|
|
}
|
|
};
|
|
|
|
module.exports = controller;
|