Bug 5735: Expanding/collapsing cloned fields in editor takes original field
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / cataloguing / addbiblio.tmpl
1 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2 <title>Koha &rsaquo; Cataloging &rsaquo; <!-- TMPL_IF NAME="biblionumber" -->Editing <!-- TMPL_VAR NAME="title" escape="html" --> (Record Number <!-- TMPL_VAR name="biblionumber" -->)<!-- TMPL_ELSE -->Add MARC Record<!-- /TMPL_IF --></title>
3 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4 <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/yui/plugins/bubbling-min.js"></script>
5 <script type="text/javascript">
6 //<![CDATA[
7
8      var fields_in_use = {};
9          $(document).ready(function() {
10                 $('#addbibliotabs > ul').tabs().bind('show.ui-tabs', function(e, ui) {
11                         $("#"+ui.panel.id+" input:eq(0)").focus();
12                 });
13         $('.tag').each(function() {
14             var field_id = this.getAttribute('id').substring(0, 7);
15             if (field_id in fields_in_use) {
16                 fields_in_use[field_id]++;
17             } else {
18                 fields_in_use[field_id] = 1;
19             }
20         });
21         $('.subfield_line').each(function() {
22             var field_id = this.getAttribute('id').substring(0, 12);
23             if (field_id in fields_in_use) {
24                 fields_in_use[field_id]++;
25             } else {
26                 fields_in_use[field_id] = 1;
27             }
28         });
29          });
30          
31          $('#header_search > ul').tabs().bind('show.ui-tabs', function(e, ui) { $('#header_search > div:not(.ui-tabs-hide)').find('input').eq(0).focus(); });
32
33 function confirmnotdup(){
34         $("#confirm_not_duplicate").attr("value","1");
35         // alert(_("Not a duplicate confirmed. Please click on Add biblio to save the record"));
36         var checkform = $("#f");
37         Check(checkform);
38 }
39
40 /**
41  * 
42  * 
43  */
44 function Check(dest){
45     var StrAlert = AreMandatoriesNotOk();
46     if( ! StrAlert ){
47         document.f.submit();
48         return true;
49     } else {
50         alert(StrAlert);
51         return false;
52     }
53 }
54
55 function Dopop(link,i) {
56     defaultvalue = document.getElementById(i).value;
57     window.open(link+"&result="+defaultvalue,"valuebuilder",'width=700,height=550,toolbar=false,scrollbars=yes');
58 }
59
60 /**
61  * this function open a popup to search on z3950 server.
62  */
63 function PopupZ3950() {
64     var strQuery = GetZ3950Terms();
65         if(strQuery){
66         window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
67     } 
68 }
69
70 function PopupMARCFieldDoc(field, blocknumber) {
71     <!-- TMPL_IF NAME="MARC21" -->
72         _MARC21FieldDoc(field);
73     <!-- TMPL_ELSE -->
74         _UNIMARCFieldDoc(field, blocknumber);
75     <!-- /TMPL_IF -->
76 }
77
78 function _MARC21FieldDoc(field) {
79     if(field == 0) {
80         window.open("http://www.loc.gov/marc/bibliographic/bdleader.html");
81     } else if (field < 900) {
82         window.open("http://www.loc.gov/marc/bibliographic/bd" + ("000"+field).slice(-3) + ".html");
83     } else {
84         window.open("http://www.loc.gov/marc/bibliographic/bd9xx.html");
85     }
86 }
87
88 function _UNIMARCFieldDoc(field, blocknumber) {
89     /* http://archive.ifla.org/VI/3/p1996-1/ is an outdated version of UNIMARC, but
90        seems to be the only version available that can be linked to per tag.  More recent
91        versions of the UNIMARC standard are available on the IFLA website only as
92        PDFs!
93     */
94     if(field == 0) {
95         window.open("http://archive.ifla.org/VI/3/p1996-1/uni.htm");
96     } else if (field < 100) {
97         window.open("http://archive.ifla.org/VI/3/p1996-1/uni"+blocknumber+".htm#b" + ("000"+field).slice(-3));
98     } else if (field < 900) {
99         window.open("http://archive.ifla.org/VI/3/p1996-1/uni"+blocknumber+".htm#" + ("000"+field).slice(-3));
100     } else {
101         window.open("http://archive.ifla.org/VI/3/p1996-1/uni9.htm");
102     }
103 }
104
105 /**
106  * check if mandatory subfields are written
107  */
108 function AreMandatoriesNotOk(){
109     var mandatories = new Array();
110     var mandatoriesfields = new Array();
111     var tab = new Array();
112     var label = new Array();
113     var flag=0;
114     var tabflag= new Array();  
115     <!-- TMPL_LOOP NAME='BIG_LOOP' -->
116         <!-- TMPL_LOOP NAME='innerloop' -->
117                 <!-- TMPL_IF NAME="mandatory" -->
118                 mandatoriesfields.push(new Array("<!-- TMPL_VAR NAME="tag" -->","<!-- TMPL_VAR NAME="index" --><!-- TMPL_VAR NAME="random" -->","<!-- TMPL_VAR NAME="index" -->"));
119                 <!-- /TMPL_IF -->
120                 <!-- TMPL_LOOP NAME='subfield_loop'-->
121                         <!-- TMPL_IF NAME='mandatory'-->mandatories.push("<!-- TMPL_VAR NAME='id' -->");
122                         tab.push("<!-- TMPL_VAR NAME='number' -->");
123                         label.push("<!-- TMPL_VAR NAME='marc_lib' -->");
124                 <!-- /TMPL_IF -->
125             <!-- /TMPL_LOOP -->
126         <!-- /TMPL_LOOP -->
127     <!-- /TMPL_LOOP -->
128     var StrAlert = _("Can't save this record because the following field aren't filled:");
129     StrAlert += "\n\n";
130     for(var i=0,len=mandatories.length; i<len ; i++){
131         var tag=mandatories[i].substr(4,3);
132         var subfield=mandatories[i].substr(17,1);
133         var tagnumber=mandatories[i].substr(19,mandatories[i].lastIndexOf("_")-19);
134         tabflag[tag+subfield+tagnumber]=new Array();
135         tabflag[tag+subfield+tagnumber][0]=0;
136         if( ! document.getElementById(mandatories[i]).value){
137             tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ;
138             document.getElementById(mandatories[i]).setAttribute('class','subfield_not_filled');
139             document.getElementById(mandatories[i]).focus();
140             tabflag[tag+subfield+tagnumber][1]=label[i];
141             tabflag[tag+subfield+tagnumber][2]=tab[i];
142         } else {
143             tabflag[tag+subfield+tagnumber][0] = 1;
144         }    
145     }
146     for (var tagsubfieldid in tabflag){
147       if (tabflag[tagsubfieldid][0]==0){
148         var tag=tagsubfieldid.substr(0,3);
149         var subfield=tagsubfieldid.substr(3,1);    
150         StrAlert += "\t* "+_("tag ")+tag+_(" subfield ")+subfield+" "+tabflag[tagsubfieldid][1]+_(" in tab ")+tabflag[tagsubfieldid][2]+"\n";
151         //StrAlert += "\t* "+label[i]+_(" in tab ")+tab[i]+"\n"; 
152         flag=1;    
153       }   
154     }   
155     
156     /* Check for mandatories field(not subfields) */
157     for(var i=0,len=mandatoriesfields.length; i<len; i++){
158             isempty  = true;
159                 arr      = mandatoriesfields[i];
160         divid    = "tag_" + arr[0] + "_" + arr[1];
161         varegexp = new RegExp("^tag_" + arr[0] + "_code_");
162         
163                 if(parseInt(arr[0]) >= 10){
164                 elem = document.getElementById(divid);
165                 eleminputs = elem.getElementsByTagName('input');
166                 
167                 for(var j=0,len2=eleminputs.length; j<len2; j++){
168         
169                         if(eleminputs[j].name.match(varegexp) && eleminputs[j].value){
170                                         inputregexp = new RegExp("^tag_" + arr[0] + "_subfield_" + eleminputs[j].value + "_" + arr[2]);
171                                         
172                                         for( var k=0; k<len2; k++){
173                                                 if(eleminputs[k].id.match(inputregexp) && eleminputs[k].value){
174                                                         isempty = false
175                                                 }
176                                         }
177                                         
178                                         elemselect = elem.getElementsByTagName('select');
179                                         for( var k=0; k<elemselect.length; k++){
180                                                 if(elemselect[k].id.match(inputregexp) && elemselect[k].value){
181                                                         isempty = false
182                                                 }
183                                         }
184                         }
185                 }
186
187                 elemtextareas = elem.getElementsByTagName('textarea');
188                 for(var j=0,len2=elemtextareas.length; j<len2; j++){
189                 // this bit assumes that the only textareas in this context would be for subfields
190                 if (elemtextareas[j].value) {
191                     isempty = false;
192                 }
193             }
194         }else{
195                 isempty = false;
196         }
197         
198         if(isempty){
199                 flag = 1;
200                 StrAlert += _("\t* Field ") + arr[0] + _(" is mandatory, at least one of its subfields must be filled.") + "\n";
201         }
202         
203     }
204     
205     if(flag){
206             return StrAlert;
207         } else {
208                 return flag;
209         }
210 }
211
212 /** 
213  * check if z3950 mandatories are set or not
214  */
215 function GetZ3950Terms(){
216  var strQuery="&frameworkcode="+document.forms['f'].frameworkcode.value;
217     var mandatories = new Array();
218     var mandatories_label = new Array();
219     <!-- TMPL_LOOP NAME='BIG_LOOP' --><!-- TMPL_LOOP NAME='innerloop' --><!-- TMPL_LOOP NAME='subfield_loop'--><!-- TMPL_IF NAME='z3950_mandatory'-->mandatories.push("<!-- TMPL_VAR NAME='id' -->");
220         mandatories_label.push("<!-- TMPL_VAR NAME='z3950_mandatory' -->");<!-- /TMPL_IF --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP -->
221     
222     for(var i=0,len=mandatories.length; i<len ; i++){
223         var field_value = document.getElementById(mandatories[i]).value;
224         if( field_value ){
225             strQuery += "&"+mandatories_label[i]+"="+field_value;
226         }
227     }
228     return strQuery;
229 }
230
231 function Changefwk(FwkList) {
232         var fwk = FwkList.options[FwkList.selectedIndex].value;
233         window.location = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=<!--TMPL_VAR Name="biblionumber"-->&breedingid=<!-- TMPL_VAR name="breedingid" -->&frameworkcode="+fwk;
234
235 }
236
237 // returns the subfieldcode based upon subfieldid writing
238 function getSubfieldcode(tagsubfieldid){
239     // 3 : tag +3 : tagnumber +4 : number of _ +8 subfield -1 begins at 0  
240     return tagsubfieldid.substr(3+3+4+8-1,1);
241 }
242
243 // Take the base of tagsubfield information (removing the subfieldcodes and subfieldindexes)
244 // returns the filter
245 function getTagInputnameFilter(tagsubfieldid){
246     var tagsubfield=tagsubfieldid.substr(0,tagsubfieldid.lastIndexOf("_"));  
247     var tagcode=tagsubfield.substr(tagsubfield.lastIndexOf("_"));
248     tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_"));
249     tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_"));
250     tagsubfield=tagsubfield+"_."+tagcode;
251     return tagsubfield;  
252 }
253
254 function openAuth(tagsubfieldid,authtype) {
255     // let's take the base of tagsubfield information (removing the indexes and the codes
256     var element=document.getElementById(tagsubfieldid);
257     var tagsubfield=getTagInputnameFilter(tagsubfieldid);
258     var elementsubfcode=getSubfieldcode(element.name);
259     var mainmainstring=element.value;
260     var mainstring="";  
261     var inputs = element.parentNode.parentNode.getElementsByTagName("input");
262
263     for (var myindex =0; myindex<inputs.length;myindex++){
264         if (inputs[myindex].name && inputs[myindex].name.match(tagsubfield)){
265             var subfieldcode=getSubfieldcode(inputs[myindex].name);
266             if (isNaN(parseInt(subfieldcode)) && inputs[myindex].value != "" && subfieldcode!=elementsubfcode){
267                 mainstring=inputs[myindex].value+" "+mainstring;
268             }      
269         }
270     }           
271         newin=window.open("../authorities/auth_finder.pl?authtypecode="+  authtype+ "&index="+tagsubfieldid+"&value_mainstr="+encodeURI(mainmainstring)+"&value_main="+encodeURI(mainstring), "_blank",'width=700,height=550,toolbar=false,scrollbars=yes');
272 }
273
274
275 function ExpandField(index) {
276     var original = document.getElementById(index); //original <div>
277     var divs = original.getElementsByTagName('div');
278     for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
279         if(divs[i].getAttribute('id').match(/^subfield/)){  // if it s a subfield
280             if (divs[i].style.display == 'block') {
281                 divs[i].style.display = 'none';
282             } else {
283                 divs[i].style.display = 'block';
284             }
285         }
286     }
287 }
288
289 /**
290  * To clone a field or a subfield by clicking on '+' button
291  */ 
292 function CloneField(index) {
293     var original = document.getElementById(index); //original <div>
294     fields_in_use[index.substr(0, 7)]++;
295     var clone = original.cloneNode(true);
296     var new_key = CreateKey();
297     var new_id  = original.getAttribute('id')+new_key;
298     
299     clone.setAttribute('id',new_id); // setting a new id for the parent div
300     
301     var divs = clone.getElementsByTagName('div');
302     
303     <!-- TMPL_UNLESS NAME='hide_marc'--> // No indicator if hide_marc
304         // setting a new name for the new indicator
305         for(var i=0; i < 2; i++) {
306             var indicator = clone.getElementsByTagName('input')[i];
307             indicator.setAttribute('name',indicator.getAttribute('name')+new_key);
308         }
309     <!-- /TMPL_UNLESS -->
310         
311     // settings all subfields
312     for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
313         if(divs[i].getAttribute("id").match(/^subfield/)){  // if it s a subfield
314             
315             // set the attribute for the new 'div' subfields
316             divs[i].setAttribute('id',divs[i].getAttribute('id')+new_key);
317             
318             var inputs   = divs[i].getElementsByTagName('input');
319             var id_input = "";
320             
321             for( j = 0 ; j < inputs.length ; j++ ) {
322                 if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
323                         inputs[j].value = "";
324                 }
325             }
326             
327             inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
328             inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
329             var id_input;
330             try {
331                 id_input = inputs[1].getAttribute('id')+new_key;
332                 inputs[1].setAttribute('id',id_input);
333                 inputs[1].setAttribute('name',inputs[1].getAttribute('name')+new_key);
334             } catch(e) {
335                 try{ // it s a select if it is not an input
336                     var selects = divs[i].getElementsByTagName('select');
337                     id_input = selects[0].getAttribute('id')+new_key;
338                     selects[0].setAttribute('id',id_input);
339                     selects[0].setAttribute('name',selects[0].getAttribute('name')+new_key);
340                 }catch(e2){ // it is a textarea if it s not a select or an input
341                         var textaeras = divs[i].getElementsByTagName('textarea');
342                         id_input = textaeras[0].getAttribute('id')+new_key;
343                         textaeras[0].setAttribute('id',id_input);
344                     textaeras[0].setAttribute('name',textaeras[0].getAttribute('name')+new_key);
345                 }
346             }
347             
348             <!-- TMPL_UNLESS NAME='advancedMARCEditor'-->
349             // when cloning a subfield, re set its label too.
350             var labels = divs[i].getElementsByTagName('label');
351             labels[0].setAttribute('for',id_input);
352             <!-- /TMPL_UNLESS -->
353             
354             <!-- TMPL_UNLESS NAME='hide_marc'-->
355                 // updating javascript parameters on button up
356                 var imgs = divs[i].getElementsByTagName('img');
357                 imgs[0].setAttribute('onclick',"upSubfield(\'"+divs[i].getAttribute('id')+"\');");
358             <!-- /TMPL_UNLESS -->
359             
360             // setting its '+' and '-' buttons
361             try {
362                 var anchors = divs[i].getElementsByTagName('a');
363                 for (var j = 0; j < anchors.length; j++) {
364                     if(anchors[j].getAttribute('class') == 'buttonPlus'){
365                         anchors[j].setAttribute('onclick',"CloneSubfield('" + divs[i].getAttribute('id') + "')");
366                     } else if (anchors[j].getAttribute('class') == 'buttonMinus') {
367                         anchors[j].setAttribute('onclick',"UnCloneField('" + divs[i].getAttribute('id') + "')");
368                     }
369                 }
370             }
371             catch(e){
372                 // do nothig if ButtonPlus & CloneButtonPlus don t exist.
373             }
374             
375             // button ...
376             var spans=0;
377             try {
378                 spans = divs[i].getElementsByTagName('a');
379             } catch(e) {
380                 // no spans
381             }
382             if(spans){
383                 var buttonDot;
384                 if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
385                     buttonDot = spans[0];
386                     if(buttonDot){
387                         // 2 possibilities :
388                         try{
389                             var buttonDotOnClick = buttonDot.getAttribute('onclick');
390                             if(buttonDotOnClick.match('Clictag')){   // -1- It s a plugin
391                                 var re = /\('.*'\)/i;
392                                 buttonDotOnClick = buttonDotOnClick.replace(re,"('"+inputs[1].getAttribute('id')+"')");
393                                 if(buttonDotOnClick){
394                                     buttonDot.setAttribute('onclick',buttonDotOnClick);
395                                 }
396                             } else {
397                                 if(buttonDotOnClick.match('Dopop')) {  // -2- It's a auth value
398                                     var re1 = /&index=.*',/;
399                                     var re2 = /,.*\)/;
400
401                                     buttonDotOnClick = buttonDotOnClick.replace(re1,"&index="+inputs[1].getAttribute('id')+"',");
402                                     buttonDotOnClick = buttonDotOnClick.replace(re2,",'"+inputs[1].getAttribute('id')+"')");
403                                     
404                                     if(buttonDotOnClick){
405                                             buttonDot.setAttribute('onclick',buttonDotOnClick);
406                                     }
407                                 }
408                             }
409                             try {
410                                 // do not copy the script section.
411                                 var script = spans[0].getElementsByTagName('script')[0];
412                                 spans[0].removeChild(script);
413                             } catch(e) {
414                                 // do nothing if there is no script
415                             }
416                         }catch(e){}
417                         }
418                 }
419             }
420             <!-- TMPL_UNLESS NAME='hide_marc'-->
421                 var buttonUp = divs[i].getElementsByTagName('img')[0];
422                 buttonUp.setAttribute('onclick',"upSubfield('" + divs[i].getAttribute('id') + "')");
423             <!-- /TMPL_UNLESS -->
424             
425         } else { // it's a indicator div
426             if(divs[i].getAttribute('id').match(/^div_indicator/)){
427                 var inputs = divs[i].getElementsByTagName('input');
428                 inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
429                 inputs[1].setAttribute('id',inputs[1].getAttribute('id')+new_key);
430                 
431                 var CloneButtonPlus;
432                 try {
433                     var anchors = divs[i].getElementsByTagName('a');
434                     for (var j = 0; j < anchors.length; j++) {
435                         if (anchors[j].getAttribute('class') == 'buttonPlus') {
436                             anchors[j].setAttribute('onclick',"CloneField('" + new_id + "')");
437                         } else if (anchors[j].getAttribute('class') == 'buttonMinus') {
438                             anchors[j].setAttribute('onclick',"UnCloneField('" + new_id + "')");
439                         } else if (anchors[j].getAttribute('class') == 'expandfield') {
440                             anchors[j].setAttribute('onclick',"ExpandField('" + new_id + "')");
441                         }
442                     }
443                 }
444                 catch(e){
445                     // do nothig CloneButtonPlus doesn't exist.
446                 }
447
448             }
449         }
450     }
451     
452     // insert this line on the page
453     original.parentNode.insertBefore(clone,original.nextSibling);
454 }
455
456 function CloneSubfield(index){
457     var original = document.getElementById(index); //original <div>
458     fields_in_use[index.substr(0, 12)]++;
459     var clone = original.cloneNode(true);
460     var new_key = CreateKey();
461     var new_id  = original.getAttribute('id')+new_key;
462     // set the attribute for the new 'div' subfields
463     var inputs     = clone.getElementsByTagName('input');
464     var selects    = clone.getElementsByTagName('select');
465     var textareas  = clone.getElementsByTagName('textarea');
466     var linkid;
467
468     // input
469     var id_input = "";
470     for(var i=0,len=inputs.length; i<len ; i++ ){
471         id_input = inputs[i].getAttribute('id')+new_key;
472         inputs[i].setAttribute('id',id_input);
473         inputs[i].setAttribute('name',inputs[i].getAttribute('name')+new_key);
474         linkid = id_input;
475     }
476     
477     // select 
478     for(var i=0,len=selects.length; i<len ; i++ ){
479         id_input = selects[i].getAttribute('id')+new_key;
480         selects[i].setAttribute('id',selects[i].getAttribute('id')+new_key);
481         selects[i].setAttribute('name',selects[i].getAttribute('name')+new_key);
482     }
483     
484     // textarea
485     for(var i=0,len=textareas.length; i<len ; i++ ){
486         id_input = textareas[i].getAttribute('id')+new_key;
487         textareas[i].setAttribute('id',textareas[i].getAttribute('id')+new_key);
488         textareas[i].setAttribute('name',textareas[i].getAttribute('name')+new_key);
489     }
490
491     // Changing the "..." link's onclick attribute for plugin callback
492     var links  = clone.getElementsByTagName('a');
493     var link = links[0];
494     var buttonDotOnClick = link.getAttribute('onclick');
495     if(buttonDotOnClick.match('Clictag')){   // -1- It s a plugin
496         var re = /\('.*'\)/i;
497         buttonDotOnClick = buttonDotOnClick.replace(re,"('"+linkid+"')");
498         if(buttonDotOnClick){
499             link.setAttribute('onclick',buttonDotOnClick);
500         }
501     }
502
503
504     <!-- TMPL_UNLESS NAME='advancedMARCEditor' -->
505     // when cloning a subfield, reset its label too.
506     var label = clone.getElementsByTagName('label')[0];
507     label.setAttribute('for',id_input);
508     <!-- /TMPL_UNLESS -->
509     
510     // setting a new id for the parent div
511     clone.setAttribute('id',new_id);
512     
513     try {
514         var buttonUp = clone.getElementsByTagName('img')[0];
515         buttonUp.setAttribute('onclick',"upSubfield('" + new_id + "')");
516         var anchors = clone.getElementsByTagName('a');
517         if(anchors.length){
518             for(var i = 0 ,lenanchors = anchors.length ; i < lenanchors ; i++){
519                 if(anchors[i].getAttribute('class') == 'buttonPlus'){
520                     anchors[i].setAttribute('onclick',"CloneSubfield('" + new_id + "')");
521                 } else if (anchors[i].getAttribute('class') == 'buttonMinus') {
522                     anchors[i].setAttribute('onclick',"UnCloneField('" + new_id + "')");
523                 }
524             }
525         }
526     }
527     catch(e){
528         // do nothig if ButtonPlus & CloneButtonPlus don't exist.
529     }
530     // insert this line on the page
531     original.parentNode.insertBefore(clone,original.nextSibling);
532 }
533
534  /**
535  * This function removes or clears unwanted subfields
536  */
537 function UnCloneField(index) {
538     var original = document.getElementById(index);
539     var field_id;
540     if (index.match("tag")) {
541         field_id = index.substr(0, 7);
542     } else {
543         field_id = index.substr(0, 12);
544     }
545     if (1 == fields_in_use[field_id]) {
546         // clear inputs, but don't delete
547         $(":input.input_marceditor", original).each(function(){
548             // thanks to http://www.learningjquery.com/2007/08/clearing-form-data for
549             // hint about clearing selects correctly
550             var type = this.type;
551             var tag = this.tagName.toLowerCase();
552             if (type == 'text' || type == 'password' || tag == 'textarea') {
553                 this.value = "";
554             } else if (type == 'checkbox' || type == 'radio') {
555                 this.checked = false;
556             } else if (tag == 'select') {
557                 this.selectedIndex = -1;
558             }
559         });
560         $(":input.indicator", original).val("");
561     } else {
562         original.parentNode.removeChild(original);
563         fields_in_use[field_id]--;
564     }
565 }
566
567 /**
568  * This function create a random number
569  */
570 function CreateKey(){
571     return parseInt(Math.random() * 100000);
572 }
573
574 /**
575  * This function allows to move a subfield up by clickink on the 'up' button .
576  */
577 function upSubfield(index) {
578     try{
579         var line = document.getElementById(index); // get the line where the user has clicked.
580     } catch(e) {
581         return; // this line doesn't exist...
582     }
583     var tag = line.parentNode; // get the dad of this line. (should be "<div id='tag_...'>")
584     
585     // getting all subfields for this tag
586     var subfields = tag.getElementsByTagName('div');
587     var subfieldsLength = subfields.length;
588     
589     if(subfieldsLength<=1) return; // nothing to do if there is just one subfield.
590     
591     // among all subfields 
592     for(var i=0;i<subfieldsLength;i++){ 
593         if(subfields[i].getAttribute('id') == index){ //looking for the subfield which is clicked :
594             if(i==1){ // if the clicked subfield is on the top
595                 tag.appendChild(subfields[1]);
596                 return;
597             } else {
598                 var lineAbove = subfields[i-1];
599                 tag.insertBefore(line,lineAbove);
600                 return;
601             }
602         }
603     }
604 }
605
606 function unHideSubfield(index,labelindex) { // FIXME :: is it used ?
607     subfield = document.getElementById(index);
608     subfield.style.display = 'block';
609     label = document.getElementById(labelindex);
610     label.style.display='none'; 
611 }
612 //]]>
613 </script>
614 <link type="text/css" rel="stylesheet" href="<!-- TMPL_VAR NAME="themelang" -->/css/addbiblio.css" />
615 </head>
616 <body>
617 <div id="yui-cms-loading">
618       <div id="yui-cms-float">
619           Loading, please wait...
620       </div>
621   </div>
622 <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/yui/plugins/loading-min.js"></script>
623 <script type="text/javascript">
624 //<![CDATA[
625 (function() {
626         // configuring the loading mask
627         YAHOO.widget.Loading.config({
628                 opacity: 0.8
629         });
630 })();
631 //]]>
632 </script>
633 <!-- TMPL_INCLUDE NAME="header.inc" -->
634 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Cataloging</a>  &rsaquo; <!-- TMPL_IF NAME="biblionumber" -->Editing <em><!-- TMPL_VAR NAME="title" escape="html" --></em> (Record Number <!-- TMPL_VAR name="biblionumber" -->)<!-- TMPL_ELSE -->Add MARC Record<!-- /TMPL_IF --></div>
635
636 <div id="doc" class="yui-t7">
637
638 <div id="bd">
639         <div id="yui-main">
640         <div class="yui-g">
641
642
643
644 <h1><!-- TMPL_IF NAME="biblionumber" -->Editing <em><!-- TMPL_VAR NAME="title" escape="html" --></em> (Record Number <!-- TMPL_VAR name="biblionumber" -->)</h1><!-- TMPL_ELSE -->Add MARC Record</h1><!-- /TMPL_IF -->
645
646 <!-- TMPL_UNLESS name="number" -->
647     <!-- show duplicate warning on tab 0 only -->
648         <!-- TMPL_IF name="duplicatebiblionumber" -->
649                     <div class="dialog alert">
650                         <h4>Duplicate Record suspected</h4>
651                         <p>Is this a duplicate of <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR name="duplicatebiblionumber" -->" onclick="openWindow('../MARCdetail.pl?biblionumber=<!-- TMPL_VAR name="duplicatebiblionumber" -->&amp;popup=1', 'Duplicate biblio'; return false;)"><!-- TMPL_VAR name="duplicatetitle" --></a>?</p>
652                         <form action="/cgi-bin/koha/cataloguing/additem.pl" method="get">
653                             <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR name="duplicatebiblionumber" -->" />
654                             <input type="submit" class="edit" value="Yes: Edit existing items" />
655                         </form>
656                         <form action="/cgi-bin/koha/cataloguing/addbiblio.pl" method="get">
657                             <input type="submit" class="save" onclick="confirmnotdup(); return false;" value="No: Save as New Record" />
658                         </form>
659                     </div>
660         <!-- /TMPL_IF -->
661     <!-- /TMPL_UNLESS -->
662
663 <!--TMPL_IF Name="done"-->
664     <script type="text/javascript">
665         opener.document.forms['f'].biblionumber.value=<!--TMPL_VAR Name="biblionumber"-->;
666         opener.document.forms['f'].title.value='<!--TMPL_VAR Name="title" ESCAPE="HTML"-->';
667         window.close();
668     </script>
669 <!--TMPL_ELSE-->
670     <form method="post" name="f" id="f" action="/cgi-bin/koha/cataloguing/addbiblio.pl" onsubmit="return Check();">
671     <input type="hidden" value="" id="redirect" name="redirect" />
672         <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
673 <!-- /TMPL_IF -->
674         
675 <div id="toolbar">
676
677 <script type="text/javascript">
678         //<![CDATA[
679
680         // prepare DOM for YUI Toolbar
681
682          $(document).ready(function() {
683                 $("#z3950searchc").empty();
684         $("#savebutton").empty();
685             yuiToolbar();
686          });
687
688     var onOption = function () {
689         return Check();
690     }
691
692     function redirect(dest){
693         $("#redirect").attr("value",dest);
694         return Check();
695     }
696
697     var savemenu = [
698         { text: _("Save and view record"), value: 1, onclick: {fn:function(){redirect("view");}} },
699         { text: _("Save and edit items"), value: 2, onclick: {fn:function(){redirect("items");}} }
700     ];
701
702
703         // YUI Toolbar Functions
704
705         function yuiToolbar() {
706             // new YAHOO.widget.Button("addbiblio");
707
708         var savesplitmenu = new YAHOO.widget.Button({
709             type: "split",
710             label: _("Save"),
711             id: "addbiblio",
712             name: "savemenubutton",
713             menu: savemenu,
714             container: "savebutton"
715          });
716
717         savesplitmenu.on("click", onOption); 
718
719                 new YAHOO.widget.Button({
720             id: "z3950search",
721             type: "button",
722             label: _("Z39.50 Search"),
723             container: "z3950searchc",
724                         onclick: {fn:function(){PopupZ3950()}}
725         });
726         }
727
728         //]]>
729         </script>
730
731                 <ul class="toolbar">
732                         <li id="savebutton"><input id="addbiblio" type="submit" value="Save" /></li>
733                         <li id="z3950searchc"><input type="button" id="z3950search" value="Z39.50 Search" onclick="PopupZ3950(); return false;" /></li>
734                         <li id="changeframework"><label for="Frameworks">Change framework: </label>
735                         <select name="Frameworks" id="Frameworks" onchange="Changefwk(this);">
736                                         <option value="Default">Default</option>
737                                                         <!-- TMPL_LOOP NAME="frameworkcodeloop" -->                                             
738                                 <option value="<!-- TMPL_VAR NAME="value"-->" <!-- TMPL_VAR NAME="selected" -->>
739                                                      <!-- TMPL_VAR NAME="frameworktext" -->                                      
740                                  </option>                          
741                                                 <!-- /TMPL_LOOP -->
742                         </select> 
743 <input type="hidden" name="op" value="addbiblio" /></li>
744                 </ul>
745 </div>
746
747 <!--TMPL_IF Name="popup"-->
748         <input type="hidden" name="mode" value="popup" />
749 <!--/TMPL_IF-->
750         <input type="hidden" name="frameworkcode" value="<!-- TMPL_VAR NAME="frameworkcode" -->" />
751         <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
752         <input type="hidden" name="breedingid" value="<!-- TMPL_VAR NAME="breedingid" -->" />
753
754 <div id="addbibliotabs" class="toptabs numbered">
755         <ul><!-- TMPL_LOOP name="BIG_LOOP" -->
756           <li>  <!-- TMPL_IF name="number" -->
757                 <a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
758             <!-- TMPL_ELSE -->
759                 <a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
760             <!-- /TMPL_IF --></li>
761         <!--  /TMPL_LOOP --></ul>
762
763 <!-- TMPL_LOOP name="BIG_LOOP" -->
764 <!-- hide every tab except the 1st -->
765 <!-- TMPL_IF name="number" -->
766     <div id="tab<!-- TMPL_VAR name="number" -->XX">
767 <!-- TMPL_ELSE -->
768     <div id="tab<!-- TMPL_VAR name="number" -->XX">
769 <!-- /TMPL_IF -->
770
771     
772     <!-- TMPL_LOOP NAME="innerloop" -->
773         <!-- TMPL_IF NAME="tag" -->
774         <div class="tag" id="tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->">
775         <div class="tag_title" id="div_indicator_tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->">
776             <!-- TMPL_UNLESS name="hide_marc" -->
777                 <!-- TMPL_IF NAME="advancedMARCEditor" -->
778                 <a href="#" tabindex="1" class="tagnum" title="<!-- TMPL_VAR NAME="tag_lib"--> - Click to Expand this Tag" onclick="ExpandField('tag_<!-- TMPL_VAR NAME="tag"-->_<!-- TMPL_VAR NAME='index' --><!-- TMPL_VAR NAME="random" -->'); return false;"><!-- TMPL_VAR NAME="tag" --></a>
779                 <!-- TMPL_ELSE -->
780                         <span class="tagnum" title="<!-- TMPL_VAR NAME="tag_lib" -->"><!-- TMPL_VAR NAME="tag" --><a 
781                  onclick="PopupMARCFieldDoc('<!-- TMPL_VAR NAME="tag" -->', <!-- TMPL_VAR NAME="number" -->); return false;">&nbsp;?</a></span>
782                 <!-- /TMPL_IF -->
783                 <!-- TMPL_IF NAME="fixedfield" -->
784                         <input tabindex="1" class="indicator flat" type="text" style="display:none;" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator1" -->" />
785                         <input tabindex="1" class="indicator flat" type="text" style="display:none;" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator2" -->" />
786                 <!-- TMPL_ELSE -->
787                         <input tabindex="1" class="indicator flat" type="text" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator1" -->" />
788                         <input tabindex="1" class="indicator flat" type="text" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator2" -->" />
789                 <!-- /TMPL_IF --> -
790             <!-- TMPL_ELSE -->
791                 <!-- TMPL_IF NAME="fixedfield" -->
792                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator1" -->" />
793                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator2" -->" />
794                 <!-- TMPL_ELSE -->
795                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator1" -->" />
796                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator2" -->" />
797                 <!-- /TMPL_IF -->
798             <!-- /TMPL_UNLESS -->
799
800             <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
801                     <a href="#" tabindex="1" class="expandfield" onclick="ExpandField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Click to Expand this Tag"><!-- TMPL_VAR NAME="tag_lib" --></a>
802             <!-- /TMPL_UNLESS -->
803             <!-- TMPL_IF name="repeatable" -->
804                 <a href="#" tabindex="1" class="buttonPlus" onclick="CloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Repeat this Tag">+</a>
805             <!-- /TMPL_IF -->
806                 <a href="#" tabindex="1" class="buttonMinus" onclick="UnCloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Delete this Tag">&#8722;</a>
807             
808         </div>
809         
810         <!-- TMPL_LOOP NAME="subfield_loop" -->
811             <!--  One line on the marc editor -->
812             <div class="subfield_line" style="<!-- TMPL_VAR NAME='visibility' -->; float: left; clear: left; width: 100%;" id="subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->">
813             
814                 <!--TMPL_UNLESS NAME="advancedMARCEditor" -->
815                     <label for="tag_<!-- TMPL_VAR NAME='tag'-->_subfield_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> class="labelsubfield">
816                 <!-- /TMPL_UNLESS --> 
817                 
818                 <!-- TMPL_UNLESS name="hide_marc" -->
819                 <span class="subfieldcode"><!-- TMPL_IF NAME="fixedfield" --> 
820                         <img class="buttonUp" style="display:none;" src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')" alt="Move Up" title="Move Up" />
821                     <!-- TMPL_ELSE -->
822                         <img class="buttonUp" src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')" alt="Move Up" title="Move Up" />
823                     <!-- /TMPL_IF -->
824                         <input title="<!-- TMPL_VAR NAME='marc_lib_plain' -->" style=" <!-- TMPL_IF NAME="fixedfield" -->display:none; <!-- /TMPL_IF -->border:0;" type="text" tabindex="0" name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" value="<!-- TMPL_VAR NAME="subfield" -->" size="1" maxlength="1" class="flat" />
825  </span>
826                 <!-- TMPL_ELSE -->
827                     <input type="hidden" name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" value="<!-- TMPL_VAR NAME="subfield" -->" />
828  </span>
829                 <!-- /TMPL_UNLESS -->
830             
831                 <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
832                     <!-- TMPL_IF name="mandatory" --><span class="subfield subfield_mandatory"><!-- TMPL_ELSE --><span class="subfield"><!-- /TMPL_IF -->
833                         <!-- TMPL_VAR NAME="marc_lib_plain" -->
834                         <!-- TMPL_IF NAME="mandatory" --><span class="mandatory_marker" title="This field is mandatory">*</span><!-- /TMPL_IF -->
835                     </span>
836                     </label>
837                 <!-- /TMPL_UNLESS -->
838                 
839                 <!-- TMPL_VAR NAME="marc_value" -->
840                 
841                 <!-- TMPL_IF NAME="repeatable" -->
842                     <span class="subfield_controls"><a href="#" class="buttonPlus" tabindex="1" onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/clone-subfield.png" alt="Clone" title="Clone this subfield" /></a>
843                                         <a href="#" class="buttonMinus" tabindex="1" onclick="UnCloneField('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/delete-subfield.png" alt="Delete" title="Delete this subfield" /></a></span>
844                 <!-- /TMPL_IF -->
845
846                 
847             </div>
848             <!-- End of the line -->
849             
850         <!-- /TMPL_LOOP -->
851         </div>
852         <!-- /TMPL_IF --><!-- tag -->
853     <!-- /TMPL_LOOP -->
854     </div>
855 <!-- /TMPL_LOOP -->
856 </div>
857 </form>
858
859 </div>
860 </div>
861 </div>
862
863 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->