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