Bug 5917 : Swapping templates over
[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 //]]>
165 </script>
166 </head>
167 <body>
168 [% INCLUDE 'header.inc' %]
169 [% INCLUDE 'cataloging-search.inc' %]
170 <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>
171
172 <div id="doc" class="yui-t7">
173
174 <div id="bd">
175         <div id="yui-main">
176
177
178 <h1>Merging records</h1>
179 [% IF ( result ) %]
180     [% IF ( errors ) %]
181         [% FOREACH error IN errors %]
182             <div class="dialog alert">[% error.error %].<br />Therefore, the record to be merged has not been deleted.</div>
183         [% END %]
184
185         [% ELSE %]
186         <script type="text/javascript">window.location.href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]"</script> 
187         <p>The merging was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]">Click here to see the merged record.</a></p>
188         [% END %]
189
190 [% ELSE %]
191
192 [% IF ( choosereference ) %]
193 <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>
194 <form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
195     <fieldset class="rows">
196         <legend>Merge reference</legend>
197         <ol>
198         <li class="radio"><input type="radio" value="[% biblio1 %]" checked="checked" id="mergereference1" name="mergereference" /><label style="float:none" for="mergereference1">[% title1 %] ([% biblio1 %])</label></li>
199         <li class="radio"><input type="radio" value="[% biblio2 %]" id="mergereference2" name="mergereference" /><label style="float:none" for="mergereference2">[% title2 %] ([% biblio2 %])</label></li>
200 </ol>
201         <input type="hidden" name="biblionumber" value="[% biblio1 %]" />
202         <input type="hidden" name="biblionumber" value="[% biblio2 %]" />
203         <fieldset class="action"><input type="submit" value="Next" /></fieldset>
204     </fieldset>
205 </form>
206 [% ELSE %]
207 [% IF ( errors ) %]
208     [% FOREACH error IN errors %]
209         <div class="error">[% error.error %]</div>
210     [% END %]
211 [% ELSE %]
212 <form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
213
214 <div class="yui-g">
215 <div class="yui-u first">
216 <div id="tabs" class="toptabs">
217 <h2>Source records</h2>
218     <ul>
219         <li><a href="#tabrecord1">[% biblio1 %]</a></li>
220         <li><a href="#tabrecord2">[% biblio2 %]</a></li>
221     </ul>
222     <div id="tabrecord1">
223         [% IF ( record1 ) %]
224
225             <div class="record">
226                 <ul id="ulrecord1">
227                 [% FOREACH record IN record1 %]
228                         [% FOREACH fiel IN record.field %]
229                         <li id="k[% fiel.key %]">
230                             <input type="checkbox" checked="checked" class="fieldpick" id="rec_1_[% fiel.key %]" /> 
231                             <span class="field">[% fiel.tag %]</span>
232
233                             <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
234                             <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
235                             [% IF ( fiel.value ) %] / [% fiel.value %]
236                                 <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
237                                 <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
238                             [% END %]
239
240                             [% IF ( fiel.subfield ) %]
241                                 <ul>
242                                     [% FOREACH subfiel IN fiel.subfield %]
243                                         <li id="k[% subfiel.subkey %]">
244                                             <input type="checkbox" checked="checked" class="subfieldpick" id="rec_1_[% subfiel.subkey %]" /> 
245                                             <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
246                                     <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
247                                     <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value %]" />
248                                         </li>
249                                     [% END %]
250                                 </ul>
251                             [% END %]
252                     [% END %]
253                     </li>
254                 [% END %]
255                 </ul>
256             </div><!-- /div.record -->
257 [% END %]
258     </div><!-- /div#tabrecord1 -->
259     <div id="tabrecord2">
260         [% IF ( record2 ) %]
261
262            <div class="record">
263                 <ul id="ulrecord2">
264                 [% FOREACH record IN record2 %]
265                     [% FOREACH fiel IN record.field %]
266                     <li id="k[% fiel.key %]">
267                         <input type="checkbox" class="fieldpick" id="rec_2_[% fiel.key %]" /> 
268                         <span class="field">[% fiel.tag %]</span>
269
270                         <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
271                         <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
272                         [% IF ( fiel.value ) %] / [% fiel.value %]
273                         <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
274                         <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
275                         [% END %]
276
277                         [% IF ( fiel.subfield ) %]
278                             <ul>
279                                 [% FOREACH subfiel IN fiel.subfield %]
280                                     <li id="k[% subfiel.subkey %]">
281                                         <input type="checkbox" class="subfieldpick" id="rec_2_[% subfiel.subkey %]" />
282                                         <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
283                                     <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
284                                     <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value %]" />
285                                     </li>
286                                 [% END %]
287                             </ul>
288                         [% END %]
289                     [% END %]
290                     </li>
291                 [% END %]
292                 </ul>
293             </div>
294             <!-- /div.record -->
295
296
297
298
299         [% END %]
300     </div><!-- /div#tabrecord2 -->
301 </div> <!-- // #tabs -->
302 </div>
303 <div class="yui-u">
304 <div id="result">
305     <h2>Destination record</h2>
306     <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
307             <ul id="resultul">
308         [% FOREACH record IN record1 %]
309                     [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]"><span class="field">[% fiel.tag %]</span>  
310                         <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
311                         <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
312                     [% IF ( fiel.value ) %] /
313                         [% fiel.value %]
314                         <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
315                         <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
316                     [% END %]
317                         
318                     [% IF ( fiel.subfield ) %]
319                         <ul>
320                             [% FOREACH subfiel IN fiel.subfield %]
321                                 <li id="k[% subfiel.subkey %]">
322                                     <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
323                                     <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
324                                     <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value %]" />
325                                 </li>
326                             [% END %]
327                         </ul>
328                     [% END %]
329
330                     [% END %]
331                     </li>
332                 [% END %]
333
334             </ul>
335
336 <input type="hidden" name="biblio1" value="[% biblio1 %]" />
337 <input type="hidden" name="biblio2" value="[% biblio2 %]" />
338 <input type="hidden" name="mergereference" value="[% mergereference %]" />
339
340 </div>
341 </div> <!-- // #result -->
342 </div> <!-- .yui-u -->
343 <fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
344 </div>
345 </form>
346 [% END %]
347 [% END %]
348 [% END %]
349
350 </div>
351 </div>
352 </div>
353
354 [% INCLUDE 'intranet-bottom.inc' %]