2 * Merging 2 source records into a destination record
6 * Check or uncheck a field or subfield in a source record
7 * @param pField the checkbox clicked
9 function toggleField(pField) {
11 // Getting the key of the clicked checkbox
12 var ckid = $(pField).attr("id");
13 var tab = ckid.split('_');
14 var source = tab[1]; // From which record the click came from
16 var type = $(pField).attr("class");
18 // Getting field/subfield
21 if (type == "subfieldpick") {
22 field = $(pField).parent().parent().parent().find("span.field").text();
23 subfield = $(pField).parent().find("span.subfield").text();
25 field = $(pField).parent().find("span.field").text();
28 // If the field has just been checked
31 // We check for repeatability
32 var canbeadded = true;
33 if (type == "subfieldpick") {
35 var alreadyexists = 0;
36 if (tagslib[field] && tagslib[field][subfield]) {
37 // Note : we can't use the dot notation here (tagslib.021) because the key is a number
38 repeatable = tagslib[field][subfield].repeatable;
39 // TODO : Checking for subfields
43 repeatable = tagslib[field].repeatable;
44 alreadyexists = $("#resultul span.field:contains(" + field + ")");
45 if (repeatable == 0 && alreadyexists.length != 0) {
51 // If the field is not repeatable, we check if it already exists in the result table
52 if (canbeadded == false) {
53 alert(MSG_MERGEREC_ALREADY_EXISTS);
57 // Cloning the field or subfield we picked
58 var clone = $(pField).parent().clone();
60 // Removing the checkboxes from it
61 $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
65 // If we are a subfield
66 if (type == "subfieldpick") {
67 // then we need to find who is our parent field...
68 fieldkey = $(pField).parent().parent().parent().attr("id");
70 // Find where to add the subfield
72 // First, check if the field is not already in the destination record
73 if ($("#resultul li#" + fieldkey).length > 0) {
75 // If so, we add our field to it
76 $("#resultul li#" + fieldkey + " ul").append(clone);
79 // If not, we add the subfield to the first matching field
81 $("#resultul li span.field").each(function() {
82 if (where == 0 && $(this).text() == field) {
87 // If there is no matching field in the destination record
91 // We select the whole field and removing non-selected subfields, instead of...
94 alert(MSG_MERGEREC_SUBFIELD_PRE + " " + field + " " + MSG_MERGEREC_SUBFIELD_POST);
95 pField.checked = false;
97 $(where).nextAll("ul").append(clone);
105 // Find where to add the field
106 $("#resultul li span.field").each(function() {
107 if (where == 0 && $(this).text() > field) {
112 $(where).parent().before(clone);
116 // Else, we remove it from the results tab
117 $("ul#resultul li#k" + key).remove();
122 * Add actions on field and subfields checkboxes
124 $(document).ready(function(){
125 // When a field is checked / unchecked
126 $('input.fieldpick').click(function() {
128 // (un)check all subfields
129 var ischecked = this.checked;
130 $(this).parent().find("input.subfieldpick").each(function() {
131 this.checked = ischecked;
135 // When a field or subfield is checked / unchecked
136 $("input.subfieldpick").click(function() {