Bug 17780: Add a comment to explain the line
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / authorities / blinddetail-biblio-search.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 <title>Koha &rsaquo; Authority details</title>
3 [% INCLUDE 'doc-head-close.inc' %]
4 <script type="text/javascript">
5 //<![CDATA[
6     $(document).ready(function(){
7         var index_start = "[% index %]";
8         var whichfield;
9         try {
10             whichfield = opener.opener.document.getElementById(index_start);
11         } catch(e) {
12             return;
13         }
14
15         var field_start = whichfield.parentNode.parentNode;
16
17         // Sets the good number of form fields for the specified subfield
18         // Returns false if the cloning failed
19         function SetSubfieldNumber(subfield_name, nb) {
20             // Nothing to do if we only have one value
21             if(nb <= 1) {
22                 return true;
23             }
24             
25             // Find the subfield we want to clone
26             var re = new RegExp('^subfield' + subfield_name,'g');
27             var subfields = $(field_start).children('div').filter( function() {
28                 return this.id.match(re);
29             });
30
31             // Try to add as many clones as needed
32             try {
33                 for(var i=0; i<nb-subfields.length; i++) {
34                     window.opener.opener.CloneSubfield(subfields[0].getAttribute('id'),'[% advancedMARCEditor %]');
35                 }
36             }
37             catch(err) {
38                 return false;
39             }
40             return true;
41         }
42
43         // Fills the subfield with the values entered in argument
44         function SetSubfieldValues() {
45             // Get the arguments
46             var subfield_name = arguments[0];
47             var values = new Array();
48             for(var i=1; i<arguments.length; i++) {
49                 values.push(arguments[i]);
50             }
51
52             // Create the correct number of form fields for all values
53             // If the field cloning failed, only the first value will be added to the form.
54             SetSubfieldNumber(subfield_name, values.length);
55             
56             // Find the subfields where we will add the new values
57             var re = new RegExp('^subfield' + subfield_name,'g');
58             var subfields = $(field_start).children('div').filter( function() {
59                 return this.id.match(re);
60             });
61
62             // Add the new values to those subfields, empty the additional fields
63             var i=0;
64             subfields.each(function() {
65                 if(i in values) {
66                     this.getElementsByTagName('input')[1].value = values[i];
67                 }
68                 else {
69                     this.getElementsByTagName('input')[1].value = "";
70                 }
71                 i++;
72             });
73         }
74
75         [% UNLESS ( clear ) %]
76         [% FOREACH SUBFIELD_LOO IN SUBFIELD_LOOP %]
77             SetSubfieldValues(
78                 "[% tag_number |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %][% SUBFIELD_LOO.marc_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
79             [% FOREACH marc_value IN SUBFIELD_LOO.marc_values %]
80                 ,"[% marc_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
81             [% END %]
82             );
83         [% END %]
84             var indicators = field_start.getElementsByClassName('indicator flat');
85             indicators[0].value="[% indicator1 %]";
86             indicators[1].value="[% indicator2 %]";
87         [% END %]
88
89         // browse all its subfields (clear and $9)
90         var subfields = field_start.getElementsByTagName('input');
91         var re = /^tag_\d*_code_/;
92         for(var i=0, len = subfields.length ; i< len ; i++) { // browse all subfields
93             if(subfields[i].hasAttribute('name') == 0 ) {continue; }  // div elements specific to Select2
94             if(subfields[i].getAttribute('name').match(re)){ // it s a subfield
95                 var code     = subfields[i];   // code is the first input
96                 var subfield = subfields[i+1]; // subfield the second
97
98             [% IF ( clear ) %]
99                 if (subfield){subfield.value="" ;}
100             [% ELSE %]
101                 if(code.value=='9'){
102                     subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
103                     break;
104                 }
105             [% END %]
106             }
107         }
108
109         opener.close();
110         window.close();
111             
112         return false;
113     });
114 //]]>
115 </script>
116 </head>
117 <body id="auth_blinddetail-biblio-search" class="auth">
118
119 <div id="doc" class="yui-t7">
120    <div id="bd">
121         <div class="yui-g">
122
123
124
125 </div>
126 </div>
127 </div>
128
129 [% INCLUDE 'popup-bottom.inc' %]