bug_6210: Select framework if merging two records with different frameworks
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / cataloguing / merge.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 <title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
3 [% INCLUDE 'doc-head-close.inc' %]
4 <style type="text/css">
5 div.record ul, div.record li { float:none; display:block; }
6 div#result { margin-top: 1em; }
7 /* We use this style "against" the li ui-tabs-nav style automatically applied */
8 </style>
9 <script type="text/javascript">
10 //<![CDATA[
11
12     // When submiting the form
13     function mergeformsubmit() {
14             $("ul#ulrecord1").remove();
15             $("ul#ulrecord2").remove();
16 }
17
18
19 $(document).ready(function(){
20     // Creating tabs
21     $("#tabs > ul").tabs();
22
23     // Getting marc structure via ajax
24     tagslib = [];
25     $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
26         tagslib = json;
27     });
28
29
30     // Toggle a field / subfield
31     function toggleField(pField) {
32
33         // Getting the key of the clicked checkbox
34         var ckid   = $(pField).attr("id");
35         var tab    = ckid.split('_');
36         var source = tab[1]; // From which record the click came from
37         var key    = tab[2];
38         var type   = $(pField).attr("class");
39
40         // Getting field/subfield
41         var field;
42         var subfield;
43         if (type == "subfieldpick") {
44
45                     field = $(pField).parent().parent().parent().find("span.field").text();
46                     subfield = $(pField).parent().find("span.subfield").text();
47         } else {
48
49                     field = $(pField).parent().find("span.field").text();
50         }
51
52         // If the field has just been checked
53         if (pField.checked) {
54
55             // We check for repeatability
56             var canbeadded = true;
57             if (type == "subfieldpick") {
58                 var repeatable = 1;
59                 var alreadyexists = 0;
60                 if (tagslib[field] && tagslib[field][subfield]) {
61                     repeatable = tagslib[field][subfield].repeatable; // Note : we can't use the dot notation here (tagslib.021) because the key is a number 
62                     // TODO : Checking for subfields
63                 }
64             } else {
65                 if (tagslib[field]) {
66                     repeatable = tagslib[field].repeatable;
67                     alreadyexists = $("#resultul span.field:contains(" + field + ")");
68                     if (repeatable == 0 && alreadyexists.length != 0) {
69                         canbeadded = false;
70                     }
71                 }
72             }
73             // If the field is not repeatable, we check if it already exists in the result table
74             if (canbeadded == false) {
75                 alert(_('The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it.'));
76                 pField.checked = 0;
77             } else {
78
79                 // Cloning the field or subfield we picked
80                 var clone = $(pField).parent().clone();
81
82                 // Removing the checkboxes from it
83                 $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
84                     $(this).remove();
85                 });
86
87
88                 // If we are a subfield
89                 if (type == "subfieldpick") {
90                     // then we need to find who is our parent field...
91                     fieldkey = $(pField).parent().parent().parent().attr("id");
92
93                     // Find where to add the subfield
94
95                     // First, check if the field is not already in the destination record
96                     if ($("#resultul li#" + fieldkey).length > 0) { 
97                         // If so, we add our field to it
98                         $("#resultul li#" + fieldkey + " ul").append(clone);
99                     } else {
100                         // If not, we add the subfield to the first matching field
101                         var where = 0;
102                         $("#resultul li span.field").each(function() {
103                             if (where == 0 && $(this).text() == field) {
104                                 where = this;
105                             }
106                         });
107
108                         // If there is no matching field in the destination record
109                         if (where == 0) {
110
111                             // TODO: 
112                             // We select the whole field and removing non-selected subfields, instead of...
113
114                             // Alerting the user 
115                             alert(_('This subfield cannot be added: there is no ' + field + ' field in the destination record.'));
116                             pField.checked = false;
117
118                         } else {
119                             $(where).nextAll("ul").append(clone);
120                         }
121
122                     }
123
124                     
125                     
126                 } else {
127                     // If we are a field
128                     var where = 0;
129                     // Find where to add the field
130                     $("#resultul li span.field").each(function() {
131                         if (where == 0 && $(this).text() > field) {
132                             where = this;
133                         }
134                     });
135
136                     $(where).parent().before(clone);
137                 }
138             }
139         } else {
140
141             // Else, we remove it from the results tab
142             $("ul#resultul li#k" + key).remove();
143         }
144 }
145
146
147     // When a field is checked / unchecked 
148     $('input.fieldpick').click(function() {
149         toggleField(this);
150         // (un)check all subfields
151         var ischecked = this.checked;
152         $(this).parent().find("input.subfieldpick").each(function() {
153             this.checked = ischecked;
154         });
155     });
156
157     // When a field or subfield is checked / unchecked
158     $("input.subfieldpick").click(function() {
159         toggleField(this);
160     });
161
162 });
163
164 function changeFramework(fw) {
165     $("#Frameworks").val(fw);
166 }
167
168 //]]>
169 </script>
170 </head>
171 <body>
172 [% INCLUDE 'header.inc' %]
173 [% INCLUDE 'cataloging-search.inc' %]
174 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Cataloging</a>  &rsaquo; [% IF ( biblionumber ) %]Editing <em>[% title |html %]</em> (Record Number [% biblionumber %])[% ELSE %]Add MARC Record[% END %]</div>
175
176 <div id="doc" class="yui-t7">
177
178 <div id="bd">
179         <div id="yui-main">
180
181
182 <h1>Merging records</h1>
183 [% IF ( result ) %]
184     [% IF ( errors ) %]
185         [% FOREACH error IN errors %]
186             <div class="dialog alert">[% error.error %].<br />Therefore, the record to be merged has not been deleted.</div>
187         [% END %]
188
189         [% ELSE %]
190         <script type="text/javascript">window.location.href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]"</script> 
191         <p>The merging was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]">Click here to see the merged record.</a></p>
192         [% END %]
193
194 [% ELSE %]
195
196 [% IF ( choosereference ) %]
197 <p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
198 <form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
199     <fieldset class="rows">
200         <legend>Merge reference</legend>
201     <table>
202       <tr>
203         <td style="border-width: 0px; text-align: left">
204         <ol>
205         <li class="radio"><input type="radio" value="[% biblio1 %]" checked="checked" id="mergereference1" name="mergereference" onclick="changeFramework('[% frameworkcode1 %]')" /><label style="float:none" for="mergereference1">[% title1 %] ([% biblio1 %])</label></li>
206         <li class="radio"><input type="radio" value="[% biblio2 %]" id="mergereference2" name="mergereference" onclick="changeFramework('[% frameworkcode2 %]')" /><label style="float:none" for="mergereference2">[% title2 %] ([% biblio2 %])</label></li>
207 </ol>
208         </td>
209         <td style="border-width: 0px">
210     [% IF frameworkselect %]
211           <label style="float:none" for="frameworkcode">Framework:</label><br>
212             <select name="frameworkcode" id="Frameworks">
213                             <option value="Default">Default</option>
214                             [% FOREACH frameworkcodeloo IN frameworkselect %]
215                                 [% IF ( frameworkcodeloo.selected ) %]
216                                     <option value="[% frameworkcodeloo.value %]" selected="selected">
217                                 [% ELSE %]
218                                     <option value="[% frameworkcodeloo.value %]">
219                                 [% END %]
220                                  [% frameworkcodeloo.frameworktext %]
221                                  </option>
222                             [% END %]
223             </select>
224     [% END %]
225         </td>
226       </tr>
227     </table>
228
229         <input type="hidden" name="biblionumber" value="[% biblio1 %]" />
230         <input type="hidden" name="biblionumber" value="[% biblio2 %]" />
231         <fieldset class="action"><input type="submit" value="Next" /></fieldset>
232     </fieldset>
233 </form>
234 [% ELSE %]
235 [% IF ( errors ) %]
236     [% FOREACH error IN errors %]
237         <div class="error">[% error.error %]</div>
238     [% END %]
239 [% ELSE %]
240 <form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
241
242 <div class="yui-g">
243 <div class="yui-u first">
244 <div id="tabs" class="toptabs">
245 <h2>Source records</h2>
246     <ul>
247         <li><a href="#tabrecord1">[% biblio1 %]</a></li>
248         <li><a href="#tabrecord2">[% biblio2 %]</a></li>
249     </ul>
250     <div id="tabrecord1">
251         [% IF ( record1 ) %]
252
253             <div class="record">
254                 <ul id="ulrecord1">
255                 [% FOREACH record IN record1 %]
256                         [% FOREACH fiel IN record.field %]
257                         <li id="k[% fiel.key %]">
258                             <input type="checkbox" checked="checked" class="fieldpick" id="rec_1_[% fiel.key %]" /> 
259                             <span class="field">[% fiel.tag %]</span>
260
261                             <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
262                             <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
263                             [% IF ( fiel.value ) %] / [% fiel.value %]
264                                 <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
265                                 <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
266                             [% END %]
267
268                             [% IF ( fiel.subfield ) %]
269                                 <ul>
270                                     [% FOREACH subfiel IN fiel.subfield %]
271                                         <li id="k[% subfiel.subkey %]">
272                                             <input type="checkbox" checked="checked" class="subfieldpick" id="rec_1_[% subfiel.subkey %]" /> 
273                                             <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
274                                     <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
275                                     <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
276                                         </li>
277                                     [% END %]
278                                 </ul>
279                             [% END %]
280                     [% END %]
281                     </li>
282                 [% END %]
283                 </ul>
284             </div><!-- /div.record -->
285 [% END %]
286     </div><!-- /div#tabrecord1 -->
287     <div id="tabrecord2">
288         [% IF ( record2 ) %]
289
290            <div class="record">
291                 <ul id="ulrecord2">
292                 [% FOREACH record IN record2 %]
293                     [% FOREACH fiel IN record.field %]
294                     <li id="k[% fiel.key %]">
295                         <input type="checkbox" class="fieldpick" id="rec_2_[% fiel.key %]" /> 
296                         <span class="field">[% fiel.tag %]</span>
297
298                         <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
299                         <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
300                         [% IF ( fiel.value ) %] / [% fiel.value %]
301                         <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
302                         <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
303                         [% END %]
304
305                         [% IF ( fiel.subfield ) %]
306                             <ul>
307                                 [% FOREACH subfiel IN fiel.subfield %]
308                                     <li id="k[% subfiel.subkey %]">
309                                         <input type="checkbox" class="subfieldpick" id="rec_2_[% subfiel.subkey %]" />
310                                         <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
311                                     <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
312                                     <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
313                                     </li>
314                                 [% END %]
315                             </ul>
316                         [% END %]
317                     [% END %]
318                     </li>
319                 [% END %]
320                 </ul>
321             </div>
322             <!-- /div.record -->
323
324
325
326
327         [% END %]
328     </div><!-- /div#tabrecord2 -->
329 </div> <!-- // #tabs -->
330 </div>
331 <div class="yui-u">
332 <div id="result">
333     <h2>Destination record</h2>
334     <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
335             <ul id="resultul">
336         [% FOREACH record IN record1 %]
337                     [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]"><span class="field">[% fiel.tag %]</span>  
338                         <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
339                         <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
340                     [% IF ( fiel.value ) %] /
341                         [% fiel.value %]
342                         <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
343                         <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
344                     [% END %]
345                         
346                     [% IF ( fiel.subfield ) %]
347                         <ul>
348                             [% FOREACH subfiel IN fiel.subfield %]
349                                 <li id="k[% subfiel.subkey %]">
350                                     <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
351                                     <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
352                                     <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
353                                 </li>
354                             [% END %]
355                         </ul>
356                     [% END %]
357
358                     [% END %]
359                     </li>
360                 [% END %]
361
362             </ul>
363 </div>
364 </div> <!-- // #result -->
365 </div> <!-- .yui-u -->
366
367 <input type="hidden" name="biblio1" value="[% biblio1 %]" />
368 <input type="hidden" name="biblio2" value="[% biblio2 %]" />
369 <input type="hidden" name="mergereference" value="[% mergereference %]" />
370 <input type="hidden" name="frameworkcode" value="[% framework %]" />
371
372 <fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
373 </div>
374 </form>
375 [% END %]
376 [% END %]
377 [% END %]
378
379 </div>
380 </div>
381 </div>
382
383 [% INCLUDE 'intranet-bottom.inc' %]