diff --git a/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/NunjucksTemplate.js b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/NunjucksTemplate.js new file mode 100644 index 00000000..13729891 --- /dev/null +++ b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/NunjucksTemplate.js @@ -0,0 +1,30 @@ +const nunjucks = require('nunjucks'); +const path = require('path'); + +class WTVRegisterTemplate { + page_args = {}; + + constructor(page_args) { + this.page_args = page_args; + } + + getTemplatePage() { + // Configure nunjucks with the templates directory + const templatesPath = path.join(__dirname, '../templates'); + const env = nunjucks.configure(templatesPath, { + autoescape: false, // Disabled to allow HTML content in main_content and form_buttons + throwOnUndefined: false + }); + + try { + // Render the template with the provided arguments + const rendered = env.render(this.page_args.template_name, this.page_args); + return rendered; + } catch (error) { + console.error('Error rendering Nunjucks template:', error); + return null; + } + } +} + +module.exports = WTVRegisterTemplate; diff --git a/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/register_new_build.njk b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/register_new_build.njk new file mode 100644 index 00000000..c7b501de --- /dev/null +++ b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/register_new_build.njk @@ -0,0 +1,56 @@ + + + + {{ title }} + + + + + + + + + +
+ + + +
+ + + + + +{{ title }} + +
+ +
+ + + + + + + + +
+ +{{ main_content | safe }} + +
+ +
+
+ + + + +{{ form_buttons | safe }} + +
+ + diff --git a/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/register_old_build.njk b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/register_old_build.njk new file mode 100644 index 00000000..21e4ed8d --- /dev/null +++ b/zefie_wtvp_minisrv/includes/ServiceDeps/templates/wtv-register/templates/register_old_build.njk @@ -0,0 +1,52 @@ + + + + {{ title }} + + + + + + + + +
+ + + + + + + + +
+ {{ title }} +
+
+
+
+ + + + +
+ + {{ main_content | safe }} +

+ +

+
+

+ + + + + +
+ + {{ form_buttons | safe }} + +     +
+ + diff --git a/zefie_wtvp_minisrv/includes/classes/WTVRegister.js b/zefie_wtvp_minisrv/includes/classes/WTVRegister.js index 70fde42c..ed88629d 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVRegister.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVRegister.js @@ -5,11 +5,14 @@ class WTVRegister { minisrv_config = []; service_owner = "a minisrv user"; session_store_dir = null; + wtvshared = null; constructor(minisrv_config, session_store_dir = null) { this.minisrv_config = minisrv_config; this.service_owner = minisrv_config.config.service_owner || "a minisrv user"; this.session_store_dir = session_store_dir || this.minisrv_config.config.SessionStore; + const WTVShared = require("./WTVShared.js")['WTVShared']; + this.wtvshared = new WTVShared(minisrv_config); } getServiceOperator(first_letter_lower = false) { @@ -108,7 +111,7 @@ class WTVRegister { /** - * Generations regnstration template + * Generates registration template using Nunjucks * @param {string} title HTML Page Title * @param {string} main_content Main center content * @param {string} form_buttons Form and buttons @@ -116,120 +119,33 @@ class WTVRegister { * @returns {string} HTML Page */ getHTMLTemplate(title, main_content, form_buttons, is_old_build) { - var data; - if (is_old_build) { - data = ` - - - ${title} - - - - - - - - -
- - - - - - - - -
- ${title} -
-
-
-
- - - - -
- - ${main_content} -

- -

-


-

- - - - - -
- - ${form_buttons} - -     -
- - -`; - } else { - data = ` - - - ${title} - - - - - - - - - -
- - - -
- - - - - -${title} - -
- -
- - - - - - - - -
- -${main_content} - -
- -
-
- - - - -${form_buttons} - -
- -`; + try { + var template = this.wtvshared.getTemplate("wtv-register", "templates/NunjucksTemplate.js", true); + if (this.fs.existsSync(template)) { + const WTVRegisterTemplate = require(template); + + // Determine which template to use based on build type + const template_name = is_old_build ? 'register_old_build.njk' : 'register_new_build.njk'; + + const template_args = { + template_name: template_name, + title: title, + main_content: main_content, + form_buttons: form_buttons, + service_logo: this.minisrv_config.config.service_logo + }; + + const wtvt = new WTVRegisterTemplate(template_args); + const data = wtvt.getTemplatePage(); + + if (data) { + return data; + } + } + } catch (error) { + console.error('Error using Nunjucks template for registration:', error); } - return data; + return ''; } }