diff --git a/source/logic/helpers.ts b/source/logic/helpers.ts index 92e2c29..4cc537c 100644 --- a/source/logic/helpers.ts +++ b/source/logic/helpers.ts @@ -14,14 +14,30 @@ You should have received a copy of the GNU General Public License along with thi */ -/** - * @todo outsource - */ -function template_request( - id : string -) : DocumentFragment -{ - let dom_template = document.querySelector("template#" + id); - // return template["content"].cloneNode(true); - return (document.importNode(dom_template["content"], true) as DocumentFragment) +namespace _espe.helpers +{ + + /** + * @todo outsource + */ + export function template_request( + id : string + ) : DocumentFragment + { + let dom_template = document.querySelector("template#" + id); + // return template["content"].cloneNode(true); + return (document.importNode(dom_template["content"], true) as DocumentFragment) + } + + + /** + * @todo outsource + */ + export function null_when_empty( + str : (null | string) + ) : (null | string) + { + return (((str === null) || (str === "")) ? null : str); + } + } diff --git a/source/pages/group_create/logic.ts b/source/pages/group_create/logic.ts index b25507e..79a69d1 100644 --- a/source/pages/group_create/logic.ts +++ b/source/pages/group_create/logic.ts @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with thi lib_plankton.zoo_page.register( "group_create", (parameters, target_element) => { - target_element.appendChild(template_request("group_create")); + target_element.appendChild(_espe.helpers.template_request("group_create")); target_element.querySelector(".group_create-title").textContent = lib_plankton.translate.get("page.group_create.title"); diff --git a/source/pages/group_list/logic.ts b/source/pages/group_list/logic.ts index 389711d..9d796e8 100644 --- a/source/pages/group_list/logic.ts +++ b/source/pages/group_list/logic.ts @@ -25,7 +25,7 @@ lib_plankton.zoo_page.register( }; const term : (null | string) = (parameters["term"] ?? ""); - target_element.appendChild(template_request("group_list")); + target_element.appendChild(_espe.helpers.template_request("group_list")); target_element.querySelector(".group_list-title").textContent = lib_plankton.translate.get("page.group_list.title"); diff --git a/source/pages/group_view/logic.ts b/source/pages/group_view/logic.ts index e0d4b22..b1283aa 100644 --- a/source/pages/group_view/logic.ts +++ b/source/pages/group_view/logic.ts @@ -18,7 +18,7 @@ lib_plankton.zoo_page.register( async (parameters, target_element) => { const id : int = parseInt(parameters["id"]); - let dom_fragment : DocumentFragment = template_request("group_view"); + let dom_fragment : DocumentFragment = _espe.helpers.template_request("group_view"); dom_fragment.querySelector(".group_view-title").textContent = lib_plankton.translate.get("page.group_view.title"); diff --git a/source/pages/invite_create/logic.ts b/source/pages/invite_create/logic.ts index deea905..60381a0 100644 --- a/source/pages/invite_create/logic.ts +++ b/source/pages/invite_create/logic.ts @@ -16,16 +16,11 @@ You should have received a copy of the GNU General Public License along with thi lib_plankton.zoo_page.register( "invite_create", async (parameters, target_element) => { - target_element.appendChild(template_request("invite_create")); + target_element.appendChild(_espe.helpers.template_request("invite_create")); target_element.querySelector(".invite_create-title").textContent = lib_plankton.translate.get("page.invite_create.title"); const indent = str => (/*"... " + */str); - - /** - * @todo outsource - */ - const null_when_empty = (str) => (((str === null) || (str === "")) ? null : str); /** * @todo cache @@ -131,11 +126,11 @@ lib_plankton.zoo_page.register( representation => ({ "data": { "name_changeable": representation.name.changeable, - "name_value": null_when_empty(representation.name.value), + "name_value": _espe.helpers.null_when_empty(representation.name.value), "label_changeable": representation.label.changeable, - "label_value": null_when_empty(representation.label.value), + "label_value": _espe.helpers.null_when_empty(representation.label.value), "email_address_changeable": representation.email_address.changeable, - "email_address_value": null_when_empty(representation.email_address.value), + "email_address_value": _espe.helpers.null_when_empty(representation.email_address.value), "groups_changeable": representation.groups.changeable, "groups_value": representation.groups.value, "expiry": ( @@ -220,7 +215,7 @@ lib_plankton.zoo_page.register( groups_as_array.map( group_thingy => group_thingy.id.toFixed(0) ), - group_id_encoded => groups_as_map.get(parseInt(group_id_encoded)).name + group_id_encoded => groups_as_map.get(parseInt(group_id_encoded)).label ), (value_inner) => { const array : Array = []; diff --git a/source/pages/invite_handle/logic.ts b/source/pages/invite_handle/logic.ts index dac6161..d85b439 100644 --- a/source/pages/invite_handle/logic.ts +++ b/source/pages/invite_handle/logic.ts @@ -38,7 +38,7 @@ lib_plankton.zoo_page.register( const key : string = parameters["key"]; update_nav({"mode": null}); - target_element.appendChild(template_request("invite_handle")); + target_element.appendChild(_espe.helpers.template_request("invite_handle")); set_state( "load", [ diff --git a/source/pages/invite_list/logic.ts b/source/pages/invite_list/logic.ts index 614b7d4..3c53525 100644 --- a/source/pages/invite_list/logic.ts +++ b/source/pages/invite_list/logic.ts @@ -31,7 +31,7 @@ lib_plankton.zoo_page.register( const term : (null | string) = (parameters["term"] ?? ""); // exec - target_element.appendChild(template_request("invite_list")); + target_element.appendChild(_espe.helpers.template_request("invite_list")); target_element.querySelector(".invite_list-title").textContent = lib_plankton.translate.get("page.invite_list.title"); diff --git a/source/pages/invite_view/logic.ts b/source/pages/invite_view/logic.ts index 4af6a1d..dcb95b8 100644 --- a/source/pages/invite_view/logic.ts +++ b/source/pages/invite_view/logic.ts @@ -31,17 +31,12 @@ lib_plankton.zoo_page.register( // parameters const id : int = parseInt(parameters["id"]); - target_element.appendChild(template_request("invite_view")); + target_element.appendChild(_espe.helpers.template_request("invite_view")); target_element.querySelector(".invite_view-title").textContent = lib_plankton.translate.get("page.invite_view.title"); const indent = str => (/*"... " + */str); - /** - * @todo outsource - */ - const null_when_empty = (str) => (((str === null) || (str === "")) ? null : str); - /** * @todo cache */ @@ -157,7 +152,7 @@ lib_plankton.zoo_page.register( "label_changeable": representation.label.changeable, "label_value": representation.label.value, "email_address_changeable": representation.email_address.changeable, - "email_address_value": null_when_empty(representation.email_address.value), + "email_address_value": _espe.helpers.null_when_empty(representation.email_address.value), "groups_changeable": representation.groups.changeable, "groups_value": representation.groups.value, "url": "", @@ -210,6 +205,24 @@ lib_plankton.zoo_page.register( ), "label": lib_plankton.translate.get("domain.member.label.label"), }, + { + "name": "email_address", + "input": new lib_plankton.zoo_input.class_input_group( + [ + { + "name": "value", + "input": new lib_plankton.zoo_input.class_input_text({"read_only": true}), + "label": indent(lib_plankton.translate.get("common.initial_value")), + }, + { + "name": "changeable", + "input": new lib_plankton.zoo_input.class_input_checkbox({"read_only": true}), + "label": indent(lib_plankton.translate.get("common.changeable")), + }, + ] + ), + "label": lib_plankton.translate.get("domain.member.email_address.label"), + }, { "name": "groups", "input": new lib_plankton.zoo_input.class_input_group( @@ -227,7 +240,7 @@ lib_plankton.zoo_page.register( groups_as_array.map( group_thingy => group_thingy.id.toFixed(0) ), - group_id_encoded => groups_as_map.get(parseInt(group_id_encoded)).name + group_id_encoded => groups_as_map.get(parseInt(group_id_encoded)).label ), (value_inner) => { const array : Array = []; @@ -250,24 +263,6 @@ lib_plankton.zoo_page.register( ), "label": lib_plankton.translate.get("domain.member.groups.label"), }, - { - "name": "email_address", - "input": new lib_plankton.zoo_input.class_input_group( - [ - { - "name": "value", - "input": new lib_plankton.zoo_input.class_input_text({"read_only": true}), - "label": indent(lib_plankton.translate.get("common.initial_value")), - }, - { - "name": "changeable", - "input": new lib_plankton.zoo_input.class_input_checkbox({"read_only": true}), - "label": indent(lib_plankton.translate.get("common.changeable")), - }, - ] - ), - "label": lib_plankton.translate.get("domain.member.email_address.label"), - }, { "name": "expiry", "input": new lib_plankton.zoo_input.class_input_soft( diff --git a/source/pages/login/logic.ts b/source/pages/login/logic.ts index 8af0336..15b6864 100644 --- a/source/pages/login/logic.ts +++ b/source/pages/login/logic.ts @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with thi lib_plankton.zoo_page.register( "login", (parameters, target_element) => { - target_element.appendChild(template_request("login")); + target_element.appendChild(_espe.helpers.template_request("login")); target_element.querySelector(".login-title").textContent = lib_plankton.translate.get("page.login.title"); diff --git a/source/pages/member_list/logic.ts b/source/pages/member_list/logic.ts index 9e9bfcd..f919a0c 100644 --- a/source/pages/member_list/logic.ts +++ b/source/pages/member_list/logic.ts @@ -25,7 +25,7 @@ lib_plankton.zoo_page.register( }; const term : (null | string) = (parameters["term"] ?? ""); - target_element.appendChild(template_request("member_list")); + target_element.appendChild(_espe.helpers.template_request("member_list")); target_element.querySelector(".member_list-title").textContent = lib_plankton.translate.get("page.member_list.title"); diff --git a/source/pages/member_view/logic.ts b/source/pages/member_view/logic.ts index 48ba3f5..3997c56 100644 --- a/source/pages/member_view/logic.ts +++ b/source/pages/member_view/logic.ts @@ -18,7 +18,7 @@ lib_plankton.zoo_page.register( async (parameters, target_element) => { const id : int = parseInt(parameters["id"]); - let dom_fragment : DocumentFragment = template_request("member_view"); + let dom_fragment : DocumentFragment = _espe.helpers.template_request("member_view"); dom_fragment.querySelector(".member_view-title").textContent = lib_plankton.translate.get("page.member_view.title"); @@ -133,7 +133,7 @@ lib_plankton.zoo_page.register( groups_as_array.map( group_thingy => group_thingy.id.toFixed(0) ), - group_id_encoded => groups_as_map.get(parseInt(group_id_encoded)).name + group_id_encoded => groups_as_map.get(parseInt(group_id_encoded)).label ), (value_inner) => { const array : Array = []; diff --git a/source/pages/password_change_exec/logic.ts b/source/pages/password_change_exec/logic.ts index 0b32fc6..aa84fa3 100644 --- a/source/pages/password_change_exec/logic.ts +++ b/source/pages/password_change_exec/logic.ts @@ -38,7 +38,7 @@ lib_plankton.zoo_page.register( const token : string = parameters.token; update_nav({"mode": null}); - target_element.appendChild(template_request("password_change_exec")); + target_element.appendChild(_espe.helpers.template_request("password_change_exec")); target_element.querySelector(".password_change_exec-title").textContent = lib_plankton.translate.get("page.password_change_exec.title"); set_state( "load", diff --git a/source/pages/password_change_init/logic.ts b/source/pages/password_change_init/logic.ts index 1ac5ad3..f9f580f 100644 --- a/source/pages/password_change_init/logic.ts +++ b/source/pages/password_change_init/logic.ts @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with thi lib_plankton.zoo_page.register( "password_change_init", (parameters, target_element) => { - target_element.appendChild(template_request("password_change_init")); + target_element.appendChild(_espe.helpers.template_request("password_change_init")); target_element.querySelector(".password_change_init-title").textContent = lib_plankton.translate.get("page.password_change_init.title"); target_element.querySelector(".password_change_init-info").textContent = lib_plankton.translate.get("page.password_change_init.info");