Bug 9755 QA follow-up: fix template compliance
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / merge-record.inc
1 [% BLOCK sourcetab %]
2     <div id="tabrecord[% recordnumber %]">
3     [% IF ( records ) %]
4
5         <div class="record">
6         <ul id="ulrecord[% recordnumber %]">
7         [% FOREACH record IN records %]
8             [% FOREACH fiel IN record.field %]
9             <li id="k[% fiel.key %]">
10                 [% IF (defaultrecord) %]
11                     <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% recordnumber %]_[% fiel.key %]" />
12                 [% ELSE %]
13                     <input type="checkbox" class="fieldpick" id="rec_[% recordnumber %]_[% fiel.key %]" />
14                 [% END %]
15                 <span class="field">[% fiel.tag %]</span>
16
17                 <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
18                 <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
19                 [% IF ( fiel.value ) %] / [% fiel.value %]
20                 <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
21                 <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
22                 [% END %]
23
24                 [% IF ( fiel.subfield ) %]
25                 <ul>
26                     [% FOREACH subfiel IN fiel.subfield %]
27                     <li id="k[% subfiel.subkey %]">
28                         [% IF (defaultrecord) %]
29                             <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% recordnumber %]_[% subfiel.subkey %]" />
30                         [% ELSE %]
31                             <input type="checkbox" class="subfieldpick" id="rec_[% recordnumber %]_[% subfiel.subkey %]" />
32                         [% END %]
33                         <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
34                     <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
35                     <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
36                     </li>
37                     [% END %]
38                 </ul>
39                 [% END %]
40             [% END %]
41             </li>
42         [% END %]
43         </ul>
44         </div><!-- /div.record -->
45     [% END %]
46     </div><!-- /div#tabrecord[% recordnumber %] -->
47 [% END %]
48 [% BLOCK mergejs %]
49     // Creating tabs
50     $("#tabs").tabs();
51
52     // Toggle a field / subfield
53     function toggleField(pField) {
54
55     // Getting the key of the clicked checkbox
56     var ckid   = $(pField).attr("id");
57     var tab    = ckid.split('_');
58     var source = tab[1]; // From which record the click came from
59     var key    = tab[2];
60     var type   = $(pField).attr("class");
61
62     // Getting field/subfield
63     var field;
64     var subfield;
65     if (type == "subfieldpick") {
66
67             field = $(pField).parent().parent().parent().find("span.field").text();
68             subfield = $(pField).parent().find("span.subfield").text();
69     } else {
70
71             field = $(pField).parent().find("span.field").text();
72     }
73
74     // If the field has just been checked
75     if (pField.checked) {
76
77         // We check for repeatability
78         var canbeadded = true;
79         if (type == "subfieldpick") {
80         var repeatable = 1;
81         var alreadyexists = 0;
82         if (tagslib[field] && tagslib[field][subfield]) {
83             repeatable = tagslib[field][subfield].repeatable; // Note : we can't use the dot notation here (tagslib.021) because the key is a number
84             // TODO : Checking for subfields
85         }
86         } else {
87         if (tagslib[field]) {
88             repeatable = tagslib[field].repeatable;
89             alreadyexists = $("#resultul span.field:contains(" + field + ")");
90             if (repeatable == 0 && alreadyexists.length != 0) {
91             canbeadded = false;
92             }
93         }
94         }
95         // If the field is not repeatable, we check if it already exists in the result table
96         if (canbeadded == false) {
97         alert(_("The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it."));
98         pField.checked = 0;
99         } else {
100
101         // Cloning the field or subfield we picked
102         var clone = $(pField).parent().clone();
103
104         // Removing the checkboxes from it
105         $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
106             $(this).remove();
107         });
108
109
110         // If we are a subfield
111         if (type == "subfieldpick") {
112             // then we need to find who is our parent field...
113             fieldkey = $(pField).parent().parent().parent().attr("id");
114
115             // Find where to add the subfield
116
117             // First, check if the field is not already in the destination record
118             if ($("#resultul li#" + fieldkey).length > 0) {
119             // If so, we add our field to it
120             $("#resultul li#" + fieldkey + " ul").append(clone);
121             } else {
122             // If not, we add the subfield to the first matching field
123             var where = 0;
124             $("#resultul li span.field").each(function() {
125                 if (where == 0 && $(this).text() == field) {
126                 where = this;
127                 }
128             });
129
130             // If there is no matching field in the destination record
131             if (where == 0) {
132
133                 // TODO:
134                 // We select the whole field and removing non-selected subfields, instead of...
135
136                 // Alerting the user
137                 alert(_("This subfield cannot be added: there is no") + " " + field + " " + _("field in the destination record."));
138                 pField.checked = false;
139
140             } else {
141                 $(where).nextAll("ul").append(clone);
142             }
143
144             }
145
146
147
148         } else {
149             // If we are a field
150             var where = 0;
151             // Find where to add the field
152             $("#resultul li span.field").each(function() {
153             if (where == 0 && $(this).text() > field) {
154                 where = this;
155             }
156             });
157
158             $(where).parent().before(clone);
159         }
160         }
161     } else {
162
163         // Else, we remove it from the results tab
164         $("ul#resultul li#k" + key).remove();
165     }
166 }
167
168
169     // When a field is checked / unchecked
170     $('input.fieldpick').click(function() {
171     toggleField(this);
172     // (un)check all subfields
173     var ischecked = this.checked;
174     $(this).parent().find("input.subfieldpick").each(function() {
175         this.checked = ischecked;
176     });
177     });
178
179     // When a field or subfield is checked / unchecked
180     $("input.subfieldpick").click(function() {
181     toggleField(this);
182     });
183 [% END %]
184 [% BLOCK mergesource %]
185 <div id="tabs" class="toptabs">
186 <h2>Source records</h2>
187     <ul>
188     <li><a href="#tabrecord1">[% recordid1 %]</a></li>
189     <li><a href="#tabrecord2">[% recordid2 %]</a></li>
190     </ul>
191     [% PROCESS sourcetab records=record1 recordnumber=1 defaultrecord=1 %]
192     [% PROCESS sourcetab records=record2 recordnumber=2 defaultrecord=0 %]
193 </div> <!-- // #tabs -->
194 [% END %]
195 [% BLOCK mergetarget %]
196 <div id="result">
197     <h2>Destination record</h2>
198     <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
199         <ul id="resultul">
200         [% FOREACH record IN record1 %]
201             [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]">
202                 <span class="field">[% fiel.tag %]</span>
203                 <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
204                 <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
205                 [% IF ( fiel.value ) %] /
206                     [% fiel.value %]
207                     <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
208                     <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
209                 [% END %]
210
211                 [% IF ( fiel.subfield ) %]
212                     <ul>
213                         [% FOREACH subfiel IN fiel.subfield %]
214                             <li id="k[% subfiel.subkey %]">
215                                 <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
216                                 <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
217                                 <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
218                             </li>
219                         [% END %]
220                     </ul>
221                 [% END %]
222             </li>[% END %]
223         [% END %]
224         </ul>
225     </div>
226 </div> <!-- // #result -->
227 [% END %]