-
Name:
-
Initials:
-
Other name:
-
Library:
-
Card number:
-
Category:
+
Surname:
+
First name:
+
Preferred name:
+
Initials:
+
Other name:
+
Library:
+
Card number:
+
Category:
-
Address line 1:
-
Address line 2:
-
City:
-
State:
-
ZIP/Postal code:
-
Country:
+
Address line 1:
+
Address line 2:
+
City:
+
State:
+
ZIP/Postal code:
+
Country:
-
Registration date:
-
Renewal date:
-
Expiration date:
-
Date of birth:
-
Restricted:
-
Primary email:
-
Secondary email:
-
Primary phone:
-
Secondary phone:
-
Other phone:
-
Gender:
-
Updated on:
-
Username:
+
Registration date:
+
Renewal date:
+
Expiration date:
+
Date of birth:
+
Restricted:
+
Primary email:
+
Secondary email:
+
Primary phone:
+
Secondary phone:
+
Other phone:
+
Gender:
+
Updated on:
+
Username:
[% FOREACH p IN patrons %]
@@ -273,7 +285,9 @@
-[% IF ( p.surname ) %][% p.surname | html %], [% p.firstname | html %][% ELSE %]-[% END %]
+[% IF ( p.surname ) %][% p.surname | html %][% ELSE %]-[% END %]
+[% IF ( p.firstname ) %][% p.firstname | html %][% ELSE %]-[% END %]
+[% IF ( p.preferred_name ) %][% p.preferred_name | html %][% ELSE %]-[% END %]
[% IF ( p.initials ) %][% p.initials | html %][% ELSE %]-[% END %]
[% IF ( p.othernames ) %][% p.othernames | html %][% ELSE %]-[% END %]
[% IF ( p.branchcode ) %][% p.branchcode | html %][% ELSE %]-[% END %]
@@ -332,9 +346,13 @@
$("#patron-merge-table").on("change", "input", function () {
if ($(".keeper:checked").length > 0) {
controls.prop("disabled", false);
+ $("#copy-ui").prop("disabled", false);
} else {
controls.prop("disabled", true);
}
+ if ($("#copy-checkbox").is(":checked")) {
+ loadCopyUI();
+ }
});
$("#compare_patrons").on("click", function (e) {
@@ -352,13 +370,101 @@
var diffs = diffString(diff2, diff1);
/* Load the diff HTML in the empty columns */
- $(".col2 pre, .col3 pre").html(diffs);
+ $("#compareModal .col2 pre, #compareModal .col3 pre").html(diffs);
});
$("#submit-merge-form").on("click", function () {
$("#patron-merge-form").submit();
});
+
+ $("#copy-checkbox").on("change", function () {
+ $("#copy-fields").prop("hidden", !this.checked);
+ $("#compare_patrons").prop("disabled", this.checked);
+ if (this.checked) {
+ loadCopyUI();
+ }
+ });
});
+
+ function loadCopyUI() {
+ $("#copy-fields").empty();
+ /* Find which column is the basis for merging */
+ let col0 = $(".keeper:checked").data("borrowernumber");
+ let col1 = $(".keeper:not(:checked)").data("borrowernumber");
+ /* Get the original patron data for comparison */
+ let diff1 = $("#col-" + col0 + "-orig pre")
+ .text()
+ .split("\n")
+ .filter(e => e !== "");
+ let diff2 = $("#col-" + col1 + "-orig pre")
+ .text()
+ .split("\n")
+ .filter(e => e !== "");
+ let labels = $("#col-label strong")
+ .text()
+ .split(":")
+ .filter(e => e !== "");
+ let fields = $("#col-label strong")
+ .map((_, e) => e.dataset.field)
+ .get();
+
+ const container = $("#copy-fields");
+ container.append(
+ `
+
` +
+ _("Field") +
+ `
+
` +
+ _("Destination record") +
+ `
+
` +
+ _("Source record") +
+ `
+
` +
+ _("Copy value") +
+ `
+
`
+ );
+
+ labels.forEach((label, i) => {
+ if (diff1[i] !== diff2[i]) {
+ container.append(
+ `
+
+
+
+
+
+
+
+
`
+ );
+
+ let diffs = diffString(diff2[i], diff1[i]);
+ container.find(".row:last-child pre").html(diffs);
+ }
+ });
+
+ $("#copy-fields .row input[type=checkbox]").on("click", function () {
+ let ins = $(this).closest(".row").find(".col2 pre").data("og").toString();
+ let del = $(this).closest(".row").find(".col3 pre").data("og").toString();
+ let diffs = diffString(ins, del);
+
+ $(this).closest(".row").find(".col3 pre, .col2 pre").html(diffs);
+
+ $(this)
+ .closest(".row")
+ .find(".col2, .col3")
+ .each(function () {
+ $(this).toggleClass("col2", "col3");
+ $(this).toggleClass("col3", "col2");
+ });
+ });
+ }
[% END %]