diff --git a/loan-custom/caosdb-server/caosdb-webui/build.properties.d/51_box_loan.properties b/loan-custom/caosdb-server/caosdb-webui/build.properties.d/51_box_loan.properties new file mode 100644 index 0000000000000000000000000000000000000000..09b7cf8881f5723ad9901d0d5ca5badc271e0382 --- /dev/null +++ b/loan-custom/caosdb-server/caosdb-webui/build.properties.d/51_box_loan.properties @@ -0,0 +1 @@ +BUILD_MODULE_BOX_LOAN=ENABLED diff --git a/loan-custom/caosdb-server/caosdb-webui/src/ext/js/a_box_loan_config.js b/loan-custom/caosdb-server/caosdb-webui/src/ext/js/a_box_loan_config.js new file mode 100644 index 0000000000000000000000000000000000000000..096613e0bcaaee60cbb1bba54b814429b3ded4c5 --- /dev/null +++ b/loan-custom/caosdb-server/caosdb-webui/src/ext/js/a_box_loan_config.js @@ -0,0 +1,47 @@ +/* + * This file is a part of the LinkAhead Project. + * + * Copyright (C) 2025 Henrik tom Wörden (h.tomwoerden@indiscale.com) + * Copyright (C) 2025 IndiScale GmbH (info@indiscale.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + + + +var box_loan_config = function () { + + var datamodel = { + loan: "Loan", + box: "Box", + returned: "returned", + } + + var init = function () { + } + + return { + init: init, + datamodel: datamodel + }; + +}(); + + +$(document).ready(function() { + if ("${BUILD_MODULE_BOX_LOAN}" == "ENABLED") { + caosdb_modules.register(box_loan_config); + } +}); diff --git a/loan-custom/caosdb-server/caosdb-webui/src/ext/js/box_loan.js b/loan-custom/caosdb-server/caosdb-webui/src/ext/js/box_loan.js index c7dfc6a2a81f03000af23af156913e2d1fbbabd0..da61f5da8a168112d370f27d6caff77bfca55861 100644 --- a/loan-custom/caosdb-server/caosdb-webui/src/ext/js/box_loan.js +++ b/loan-custom/caosdb-server/caosdb-webui/src/ext/js/box_loan.js @@ -43,22 +43,16 @@ var getHTMLForm = async function(pageName, variables) { } /** - * AWI Box Loan, refactored code. + * Box Loan, refactored code. */ -var awi_box_loan = function () { +var box_loan = function (logger, box_loan_config) { - var logger = log.getLogger("awi_box_loan"); - - var datamodel = { - loan: "Loan", - box: "Box", - returned: "returned", - } + var datamodel = box_loan_config.datamodel; const _dismiss_button = '<button class="btn btn-secondary box-loan-btn">OK</button>' const _server_did_not_respond = "The server did not respond. Please reload the page."; - const _return_box_button = '<a title="Return Box." class="btn btn-link box-loan-btn">Return Box</a>'; - const _borrow_box_button = '<a title="Borrow Box." class="btn btn-link box-loan-btn">Borrow Box</a>'; + const _return_box_button = `<a title="Return ${datamodel.box}." class="btn btn-link box-loan-btn">Return ${datamodel.box}</a>`; + const _borrow_box_button = `<a title="Borrow ${datamodel.box}." class="btn btn-link box-loan-btn">Borrow ${datamodel.box}</a>`; const _confirm_loan_button = '<a title="Confirm Loan." class="btn btn-link box-loan-btn">Confirm Loan</a>'; const _manual_return_button = '<a title="Manual Return." class="btn btn-link box-loan-btn">Manual Return</a>'; const _accept_return_button = '<a title="Accept Return" class="btn btn-link box-loan-btn">Accept Return</a>'; @@ -747,9 +741,10 @@ var awi_box_loan = function () { var init = function (boxes) { const init_boxes = boxes || $(".caosdb-entity-panel") .not("[data-version-successor]") - /* TODO: This fails easily (BoxType) */ - .has(".caosdb-parent-name:contains('Box')") - .not(":has(.caosdb-parent-name:contains('BoxT'))").toArray(); + .filter(function() { + return $(this).find(".caosdb-parent-name").text().trim() === datamodel.box; + }) + .toArray(); add_buttons(init_boxes); } @@ -760,13 +755,11 @@ var awi_box_loan = function () { get_loan_state_string: get_loan_state_string, }; -}(); +}(log.getLogger("box_loan"), box_loan_config); -/** - * Add the extensions to the webui. - */ -$(document).ready(function () { - // TODO build variable - awi_box_loan.init(); +$(document).ready(function() { + if ("${BUILD_MODULE_BOX_LOAN}" == "ENABLED") { + caosdb_modules.register(box_loan); + } });