Skip to content
Snippets Groups Projects
Commit 182ce921 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: refactor creating destination drop down

parent ab3fa686
No related branches found
No related tags found
1 merge request!6F borrow all
Pipeline #61764 passed with warnings
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body>
<body> <div id="caosdb-form">
<div id="caosdb-form"> <div class="row" id="checkout-form-{boxid}" style="margin:0px">
<div class="row" id="checkout-form-{boxid}" style="margin:0px"> <div class="col-lg-12">
<div id="caosdb-f-borrow-all-form-modal" class="modal fade" style="max-width:900px" role="dialog"> <h2>Borrow Box</h2>
<div class="modal-dialog"> <form class="caosdb-awi-box-checkout-form" autocomplete="on">
<div class="modal-content"> <div>
<div class="modal-header"> <h5>Please enter your full name and your email address. If you are doing this for the first time, a new user record will be created.</h5>
<h4 class="modal-title">Borrow all bookmarked items</h4> </div>
<div class="row caosdb-form-row">
<div class="col-sm-4">
<div class="form-group">
<label>First Name:
<input name="first-name" type="name" class="form-control" id="first-name" placeholder="Enter name" required="required" value="{first_name}" />
</label>
</div>
</div> </div>
<div class="modal-body "> <div class="col-sm-4">
<form class="caosdb-awi-box-checkout-form" autocomplete="on"> <div class="form-group">
<div> <label>Last Name:
Please enter your full name and your email address. If you are doing this for the first time, a <input name="last-name" type="name" class="form-control" id="last-name" placeholder="Enter name" required="required" value="{last_name}" />
new user record will be created. </label>
</div> </div>
<div class="row caosdb-form-row">
<div class="col-sm-4">
<div class="form-group">
<label>First Name:
<input name="first-name" type="name" class="form-control" id="first-name"
placeholder="Enter name" required="required" value="{first_name}" />
</label>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Last Name:
<input name="last-name" type="name" class="form-control" id="last-name" placeholder="Enter name"
required="required" value="{last_name}" />
</label>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Email:
<input name="email" type="email" class="form-control" id="email" placeholder="Enter email"
required="required" value="{email}" />
</label>
</div>
</div>
</div>
<div class="row caosdb-form-row">
<div class="col-sm-4">
<div class="form-group">
<label>Expected Return Date:
<input name="expectedreturn" min="{mindate}" type="date" class="form-control"
id="expected-return" required="required" value="{expected_return_date}" />
</label>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Destination:
<input id="loan-destination" required="required" />
</label>
</div>
</div>
</div>
<div class="row caosdb-form-row">
<div class="col-sm-12">
<div class="form-group">
<label for="loan-comment" style="margin-bottom:0px">Purpose:
<textarea id="loan-comment" class="form-control" rows="4" style="width:100%"
placeholder="Please indicate the purpose of the loan.">{purpose}</textarea>
</label>
</div>
</div>
</div>
<div class="row caosdb-form-row">
<div class="col-sm-12">
<div class="form-check">
<label class="form-check-label">Are you going to completely exhaust the contents of this box?
<input type="checkbox" class="form-check-input" id="exhaust-contents" value="no" />
</label>
</div>
</div>
</div>
</form>
</div> </div>
<div class="modal-footer"> <div class="col-sm-4">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <div class="form-group">
<button type="submit" class="btn btn-secondary" form="borrow-all-form">Submit</button> <label>Email:
<input name="email" type="email" class="form-control" id="email" placeholder="Enter email" required="required" value="{email}" />
</label>
</div>
</div> </div>
</div> </div>
</div> <div class="row caosdb-form-row">
<div class="col-sm-4">
<div class="form-group">
<label>Expected Return Date:
<input name="expectedreturn" min="{mindate}" type="date" class="form-control" id="expected-return" required="required" value="{expected_return_date}" />
</label>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Destination:
<input id="loan-destination" required="required"/>
</label>
</div>
</div>
</div>
<div class="row caosdb-form-row">
<div class="col-sm-12">
<div class="form-group">
<label for="loan-comment" style="margin-bottom:0px">Purpose:
<textarea id="loan-comment" class="form-control" rows="4" style="width:100%"
placeholder="Please indicate the purpose of the loan.">{purpose}</textarea>
</label>
</div>
</div>
</div>
<div class="row caosdb-form-row">
<div class="col-sm-12">
<div class="form-check">
<label class="form-check-label">Are you going to completely exhaust the contents of this box?
<input type="checkbox" class="form-check-input" id="exhaust-contents" value="no" />
</label>
</div>
</div>
</div>
<div class="text-right">
<button type="submit" class="btn btn-secondary">Submit</button>
</div>
</form>
</div>
</div> </div>
</div> </div>
</div> </body>
</body> </html>
</html>
\ No newline at end of file
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
* *
*/ */
/** /**
* Return the formatted date of today. * Return the formatted date of today.
*/ */
...@@ -51,9 +48,6 @@ var getHTMLForm = async function(pageName, variables) { ...@@ -51,9 +48,6 @@ var getHTMLForm = async function(pageName, variables) {
var box_loan = function(logger, box_loan_config) { var box_loan = function(logger, box_loan_config) {
const datamodel = box_loan_config.datamodel; const datamodel = box_loan_config.datamodel;
const _dismiss_button = '<button class="btn btn-secondary box-loan-btn">OK</button>' 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 _server_did_not_respond = "The server did not respond. Please reload the page.";
const _return_box_button = `<a title="Return ${datamodel.box}." class="btn btn-link box-loan-btn">Return ${datamodel.box}</a>`; const _return_box_button = `<a title="Return ${datamodel.box}." class="btn btn-link box-loan-btn">Return ${datamodel.box}</a>`;
...@@ -381,19 +375,10 @@ var box_loan = function(logger, box_loan_config) { ...@@ -381,19 +375,10 @@ var box_loan = function(logger, box_loan_config) {
const but = $(_borrow_box_button); const but = $(_borrow_box_button);
get_actions_panel(box).append(but); get_actions_panel(box).append(but);
const config = {
type: "reference_drop_down",
name: "destination",
label: "",
required: true,
query: `FIND Record ${datamodel.location}`,
make_desc: getEntityName,
}
const dd = form_elements.make_form_field(config);
const form = await _add_form(box, generate_form_borrow_checkout, borrow_function); const form = await _add_form(box, generate_form_borrow_checkout, borrow_function);
$(dd).find(".col-sm-9").removeClass("col-sm-9");
$(dd).find(".col-sm-3").removeClass("col-sm-3"); replace_loan_destination(form);
$(form).find("#loan-destination").replaceWith(dd);
$(form).find("label").css("display", "block"); $(form).find("label").css("display", "block");
_init_validator(form); _init_validator(form);
...@@ -660,12 +645,7 @@ var box_loan = function(logger, box_loan_config) { ...@@ -660,12 +645,7 @@ var box_loan = function(logger, box_loan_config) {
show_result(actions_panel, result, box); show_result(actions_panel, result, box);
} }
var add_menu_entry = async function () { var replace_loan_destination = async function(node) {
if ($("#caosdb-f-bookmarks-borrow-all").length > 0) {
return;
}
const config = { const config = {
type: "reference_drop_down", type: "reference_drop_down",
name: "destination", name: "destination",
...@@ -677,9 +657,18 @@ var box_loan = function(logger, box_loan_config) { ...@@ -677,9 +657,18 @@ var box_loan = function(logger, box_loan_config) {
const dd = form_elements.make_form_field(config); const dd = form_elements.make_form_field(config);
$(dd).find(".col-sm-9").removeClass("col-sm-9"); $(dd).find(".col-sm-9").removeClass("col-sm-9");
$(dd).find(".col-sm-3").removeClass("col-sm-3"); $(dd).find(".col-sm-3").removeClass("col-sm-3");
$(node).find("#loan-destination").replaceWith(dd);
}
var add_menu_entry = async function () {
if ($("#caosdb-f-bookmarks-borrow-all").length > 0) {
return;
}
var modal = $(await generate_form_borrow_checkout(undefined, "loan-forms/borrow_all_bookmarked")).find(".modal"); var modal = $(await generate_form_borrow_checkout(undefined, "loan-forms/borrow_all_bookmarked")).find(".modal");
$(modal).find("#loan-destination").replaceWith(dd); replace_loan_destination(modal);
$(modal).find("label").css("display", "block"); $(modal).find("label").css("display", "block");
$('body').append(modal); $('body').append(modal);
...@@ -744,7 +733,6 @@ var box_loan = function(logger, box_loan_config) { ...@@ -744,7 +733,6 @@ var box_loan = function(logger, box_loan_config) {
exp_return = ""; exp_return = "";
} }
formhtml = formhtml || 'loan-forms/borrow_checkout'; formhtml = formhtml || 'loan-forms/borrow_checkout';
console.log("formhtml", formhtml);
return getHTMLForm(formhtml, { return getHTMLForm(formhtml, {
boxid: boxid, boxid: boxid,
first_name: firstname, first_name: firstname,
...@@ -768,14 +756,11 @@ var box_loan = function(logger, box_loan_config) { ...@@ -768,14 +756,11 @@ var box_loan = function(logger, box_loan_config) {
* currentlocation (pre-filled) * currentlocation (pre-filled)
* comment * comment
*/ */
var generate_return_form = async function(box) { var generate_return_form = async function(boxid) {
const loan = (await get_active_loans(box.id))[0]; const loan = (await get_active_loans(boxid))[0];
if (typeof loan === "undefined") { if (typeof loan === "undefined") {
// no loan found // no loan found
logger.error("No loan found for box", boxid);
console.log(loan);
console.log(box);
logger.error("No loan found for box", box);
return ; return ;
} }
const borrower = (await retrieve(getProperty(loan, "Borrower", case_sensitive = false)))[0]; const borrower = (await retrieve(getProperty(loan, "Borrower", case_sensitive = false)))[0];
...@@ -794,7 +779,7 @@ var box_loan = function(logger, box_loan_config) { ...@@ -794,7 +779,7 @@ var box_loan = function(logger, box_loan_config) {
var cur_loc = getProperty(loan, "destination", case_sensitive = false); var cur_loc = getProperty(loan, "destination", case_sensitive = false);
return getHTMLForm("loan-forms/return_box", { return getHTMLForm("loan-forms/return_box", {
boxid: getEntityID(box), boxid: boxid,
first_name: first_name, first_name: first_name,
last_name: last_name, last_name: last_name,
email: email, email: email,
...@@ -804,8 +789,6 @@ var box_loan = function(logger, box_loan_config) { ...@@ -804,8 +789,6 @@ var box_loan = function(logger, box_loan_config) {
}); });
} }
var init = function(boxes) { var init = function(boxes) {
const init_boxes = boxes || $(".caosdb-entity-panel") const init_boxes = boxes || $(".caosdb-entity-panel")
.not("[data-version-successor]") .not("[data-version-successor]")
...@@ -816,11 +799,6 @@ var box_loan = function(logger, box_loan_config) { ...@@ -816,11 +799,6 @@ var box_loan = function(logger, box_loan_config) {
add_menu_entry(); add_menu_entry();
add_buttons(init_boxes); add_buttons(init_boxes);
} }
const is_authorized = function() {
// return true //for testing
return isAuthenticated() //&& (userHasRole("stockmanager") || userHasRole("administration"))
}
return { return {
init: init, init: init,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment