Bug 23777: Use To.json in authorities.tt
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / authorities / authorities.tt
blob55ddb49f4cdd5a9a10f6d7ffe65552683717c044
1 [% USE raw %]
2 [% USE To %]
3 [% USE Asset %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Koha &rsaquo; Authorities &rsaquo; [% IF ( authid ) %]Modify authority #[% authid | html %] ([% authtypetext | html %])[% ELSE %]Adding authority ([% authtypetext | html %])[% END %]</title>
6 [% INCLUDE 'doc-head-close.inc' %]
7 [% Asset.js("lib/hc-sticky.js") | $raw %]
8 [% Asset.js("js/cataloging.js") | $raw %]
10 <script>
11     $(window).load(function(){
12         $("#loading").hide();
13     });
14     var Sticky;
15          $(document).ready(function() {
16         var tabs = $('#authoritytabs').tabs();
17         $( "ul.sortable_field", tabs ).sortable();
18         $( "ul.sortable_subfield", tabs ).sortable();
19         Sticky = $("#toolbar");
20         Sticky.hcSticky({
21             stickTo: ".main",
22             stickyClass: "floating"
23         });
24         $("#addauth").click(function(){
25             if(Check()){
26                 $("#f").submit();
27             }
28                 });
29         $("#z3950submit").click(function(){
30             if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
31                 var strQuery = GetZ3950Terms();
32                 if(strQuery){
33                     window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
34                 }
35             }
36             return false;
37         });
38          });
40 /**
41  * check if z3950 mandatories are set or not
42  */
43 function GetZ3950Terms(){
44  var strQuery="&authtypecode="+document.forms['f'].authtypecode.value;
45     var mandatories = new Array();
46     var mandatories_label = new Array();
47     [% FOREACH BIG_LOO IN BIG_LOOP %][% FOREACH innerloo IN BIG_LOO.innerloop %][% FOREACH subfield_loo IN innerloo.subfield_loop %][% IF ( subfield_loo.z3950_mandatory ) %]mandatories.push("[% subfield_loo.id | html %]");
48         mandatories_label.push("[% subfield_loo.z3950_mandatory | html %]");[% END %][% END %][% END %][% END %]
50     for(var i=0,len=mandatories.length; i<len ; i++){
51         var field_value = document.getElementById(mandatories[i]).value;
52         if( field_value ){
53             strQuery += "&"+mandatories_label[i]+"="+field_value;
54         }
55     }
56     return strQuery;
59 /**
60  * check if mandatory subfields are written
61  */
62 function AreMandatoriesNotOk(){
63     var mandatories = new Array();
64     var mandatoriesfields = new Array();
65     var   tab = new Array();
66     var label = new Array();
67     [% FOREACH BIG_LOO IN BIG_LOOP %]
68         [% FOREACH innerloo IN BIG_LOO.innerloop %]
69                         [% IF ( innerloo.mandatory ) %]
70                         mandatoriesfields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]"));
71             [% END %]
72                 [% FOREACH subfield_loo IN innerloo.subfield_loop %]
73                         [% IF ( subfield_loo.mandatory ) %]mandatories.push("[% subfield_loo.id | html %]");
74                     tab.push("[% BIG_LOO.number | html %]");
75                     label.push("[% To.json(subfield_loo.marc_lib) | $raw %]");
76                         [% END %]
77                         [% END %]
78                 [% END %]
79         [% END %]
80     var StrAlert = "";
81     for(var i=0,len=mandatories.length; i<len ; i++){
82         var id_string = mandatories[i];
83         // alert (id_string);
84         if( ! $("#" + id_string).val() ){
85             $("#" + id_string).attr('class','subfield_not_filled').focus();
86             StrAlert += "\t* " + _("%s in tab %s").format(label[i], tab[i]) + "\n";
87         }
88     }
89     
90     /* Check for mandatories field(not subfields) */
91     for(var i=0,len=mandatoriesfields.length; i<len; i++){
92         isempty  = true;
93         arr      = mandatoriesfields[i];
94         divid    = "tag_" + arr[0] + "_" + arr[1];
95         varegexp = new RegExp("^tag_" + arr[0] + "_code_");
97                 if(parseInt(arr[0]) >= 10){
98                 elem = document.getElementById(divid);
99                 eleminputs = elem.getElementsByTagName('input');
100                 
101                 for(var j=0,len2=eleminputs.length; j<len2; j++){
102         
103                         if(eleminputs[j].name.match(varegexp) && eleminputs[j].value){
104                                         inputregexp = new RegExp("^tag_" + arr[0] + "_subfield_" + eleminputs[j].value + "_" + arr[2]);
105                                         
106                                         for( var k=0; k<len2; k++){
107                                                 if(eleminputs[k].id.match(inputregexp) && eleminputs[k].value){
108                                                         isempty = false
109                                                 }
110                                         }
111                         }
112                 }
113         }else{
114                 isempty = false;
115         }
116         
117         if(isempty){
118                 flag = 1;
119                 StrAlert += "\t* " + _("Field %s is mandatory, at least one of its subfields must be filled.").format(arr[0]) + "\n";
120         }
121         
122     }
123     
124     
125     if(StrAlert){
126         return _("Can't save this record because the following field aren't filled :") + "\n\n" + StrAlert;
127     }
128     return false;
131 function Check(){
132     var StrAlert = AreMandatoriesNotOk();
133     if( ! StrAlert ){
134         document.f.submit();
135         return true;
136     } else {
137         alert(StrAlert);
138         return false;
139     }
142 function AddField(field,cntrepeatfield) {
143     document.forms['f'].op.value = "addfield";
144     document.forms['f'].addfield_field.value=field;
145     document.forms['f'].repeat_field.value=cntrepeatfield;
146     document.f.submit();
149 function addauthority() {
150     X = document.forms[0].authtype.value;
151     window.location="/cgi-bin/koha/authorities/authorities.pl?authtypecode="+X;
153 function searchauthority() {
154     X = document.forms[0].authtype2.value;
155     Y = document.forms[0].value.value;
156     window.location="/cgi-bin/koha/authorities/authorities-home.pl?op=do_search&type=intranet&authtypecode="+X+"&value="+Y+"&marclist=&and_or=and&excluding=&operator=contains";
158 function confirmnotdup(redirect){
159     $("#confirm_not_duplicate").attr("value","1");
160     Check();
162 </script>
163 [% Asset.css("css/addbiblio.css") | $raw %]
165 [% INCLUDE 'select2.inc' %]
166 <script>
167   $(document).ready(function() {
168     $('.subfield_line select').select2();
169   });
170 </script>
172 </head>
173 <body id="auth_authorities" class="auth">
175 <div id="loading">
176    <div>Loading, please wait...</div>
177 </div>
179 [% INCLUDE 'header.inc' %]
181 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/authorities/authorities-home.pl">Authorities</a> &rsaquo; [% IF ( authid ) %]Modify authority #[% authid | html %] ([% authtypetext | html %])[% ELSE %]Adding authority [% authtypetext | html %][% END %]  </div>
183 <div class="main container-fluid">
184     <div class="row">
185         <div class="col-md-8 col-md-offset-2">
187 [% IF ( authid ) %]
188 <h1>Modify authority #[% authid | html %] [% authtypetext | html %]</h1>
189 [% ELSE %]
190 <h1>Adding authority [% authtypetext | html %]</h1>
191 [% END %]
193 [% IF ( duplicateauthid ) %]
194         <div class="dialog alert">
195                 <h3>Duplicate record suspected</h3>
196                 <p>Is this a duplicate of <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% duplicateauthid | uri %]" class="popup" onclick="openWindow('/cgi-bin/koha/authorities/detail.pl?authid=[% duplicateauthid | html %]&amp;popup=1', 'DuplicateAuthority','800','600'); return false;" class="button">[% duplicateauthvalue | html %]</a> ?</p>
198                 <form action="authorities.pl" method="get">
199                     <input type="hidden" name="authid" value="[% duplicateauthid | html %]" />
200                     <button type="submit" class="new"><i class="fa fa-pencil"></i> Yes: Edit existing authority</button>
201                 </form>
202                 <form action="authorities.pl" method="get">
203                     <button class="new" onclick="confirmnotdup('items'); return false;"><i class="fa fa-save"></i> No: Save as new authority</button>
204                 </form>
205         </div>
206 [% END %]
208 <form method="post" name="f" action="/cgi-bin/koha/authorities/authorities.pl">
209     <input type="hidden" name="op" value="add" />
210     <input type="hidden" name="addfield_field" value="" />
211     <input type="hidden" name="repeat_field" value="" />
212     <input type="hidden" name="authtypecode" value="[% authtypecode | html %]" />
213     <input type="hidden" name="authid" value="[% authid | html %]" />
214     <input type="hidden" name="index" value="[% index | html %]" />
215     <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
217     <div id="toolbar" class="btn-toolbar">
218         <div class="btn-group"><a href="#" id="addauth" class="btn btn-default" accesskey="w"><i class="fa fa-save"></i> Save</a></div>
219         <div class="btn-group">
220             <a class="btn btn-default" id="z3950submit" href="#"><i class="fa fa-search"></i> Z39.50 search</a>
221         </div>
222         <div class="btn-group">
223             [% IF ( authid ) %]
224                 <a class="btn btn-default" id="cancel" href="/cgi-bin/koha/authorities/detail.pl?authid=[% authid | url %]">Cancel</a>
225             [% ELSE %]
226                 <a class="btn btn-default" id="cancel" href="/cgi-bin/koha/authorities/authorities-home.pl">Cancel</a>
227             [% END %]
228         </div>
229     </div>
231 <div id="authoritytabs" class="toptabs numbered">
232     <ul>
233         [% FOREACH BIG_LOO IN BIG_LOOP %]
234         <li><a href="#tab[% BIG_LOO.number | uri %]XX">[% BIG_LOO.number | html %]</a></li>
235         [% END %]
236     </ul>
238 [% FOREACH BIG_LOO IN BIG_LOOP %]
239     <div id="tab[% BIG_LOO.number | html %]XX">
241     [% previous = "" %]
242     [% FOREACH innerloo IN BIG_LOO.innerloop %]
243     [% IF ( innerloo.tag ) %]
244     [% IF innerloo.tag != previous %]
245         [% IF previous != "" %]
246             </ul>
247         [% END %]
248         [% previous = innerloo.tag %]
249         <ul class="sortable_field">
250     [% END %]
251     <li class="tag clearfix" id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">
252         <div class="tag_title" id="div_indicator_tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">
253         [% UNLESS hide_marc %]
254             [% IF advancedMARCEditor %]
255                 <a href="#" tabindex="1" class="tagnum" title="[% innerloo.tag_lib | html %] - Click to Expand this Tag" onclick="ExpandField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;">[% innerloo.tag | html %]</a>
256             [% ELSE %]
257                 <span title="[% innerloo.tag_lib | html %]">[% innerloo.tag | html %]</span>
258             [% END %]
259                 [% IF ( innerloo.fixedfield ) %]
260                     <input type="text"
261                         tabindex="1"
262                         class="indicator flat"
263                         style="display:none;"
264                         name="tag_[% innerloo.tag | html %]_indicator1_[% innerloo.index | html %][% innerloo.random | html %]"
265                         size="1"
266                         maxlength="1"
267                         value="[% innerloo.indicator1 | html %]" />
268                     <input type="text"
269                         tabindex="1"
270                         class="indicator flat"
271                         style="display:none;"
272                         name="tag_[% innerloo.tag | html %]_indicator2_[% innerloo.index | html %][% innerloo.random | html %]"
273                         size="1"
274                         maxlength="1"
275                         value="[% innerloo.indicator2 | html %]" />
276                 [% ELSE %]
277                     <input type="text"
278                         tabindex="1"
279                         class="indicator flat"
280                         name="tag_[% innerloo.tag | html %]_indicator1_[% innerloo.index | html %][% innerloo.random | html %]"
281                         size="1"
282                         maxlength="1"
283                         value="[% innerloo.indicator1 | html %]" />
284                     <input type="text"
285                         tabindex="1"
286                         class="indicator flat"
287                         name="tag_[% innerloo.tag | html %]_indicator2_[% innerloo.index | html %][% innerloo.random | html %]"
288                         size="1"
289                         maxlength="1"
290                         value="[% innerloo.indicator2 | html %]" />
291                 [% END %] -
292         [% ELSE %]
293                 [% IF ( innerloo.fixedfield ) %]
294                     <input type="hidden"
295                         tabindex="1"
296                         name="tag_[% innerloo.tag | html %]_indicator1_[% innerloo.index | html %][% innerloo.random | html %]"
297                         value="[% innerloo.indicator1 | html %]" />
298                     <input type="hidden"
299                         tabindex="1"
300                         name="tag_[% innerloo.tag | html %]_indicator2_[% innerloo.index | html %][% innerloo.random | html %]"
301                         value="[% innerloo.indicator2 | html %]" />
302                 [% ELSE %]
303                     <input type="hidden"
304                         tabindex="1"
305                         name="tag_[% innerloo.tag | html %]_indicator1_[% innerloo.index | html %][% innerloo.random | html %]"
306                         value="[% innerloo.indicator1 | html %]" />
307                     <input type="hidden"
308                         tabindex="1"
309                         name="tag_[% innerloo.tag | html %]_indicator2_[% innerloo.index | html %][% innerloo.random | html %]"
310                         value="[% innerloo.indicator2 | html %]" />
311                 [% END %]
312         [% END %]
314             [% UNLESS advancedMARCEditor %]
315                 <a href="#" tabindex="1" class="expandfield" onclick="ExpandField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;" title="Click to Expand this Tag">[% innerloo.tag_lib | html %]</a>
316             [% END %]
317                 <span class="field_controls">
318                 [% IF ( innerloo.repeatable ) %]
319                     <a href="#" tabindex="1" class="buttonPlus" onclick="CloneField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]','[% hide_marc | html %]','[% advancedMARCEditor | html %]'); return false;" title="Repeat this Tag">
320                         <img src="[% interface | html %]/[% theme | html %]/img/repeat-tag.png" alt="Repeat this Tag" />
321                     </a>
322                 [% END %]
323                     <a href="#" tabindex="1" class="buttonMinus" onclick="UnCloneField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;" title="Delete this Tag">
324                         <img src="[% interface | html %]/[% theme | html %]/img/delete-tag.png" alt="Delete this Tag" />
325                     </a>
326                 </span>
328         </div>
330         <ul class="sortable_subfield">
331         [% FOREACH subfield_loo IN innerloo.subfield_loop %]
332             <!--  One line on the marc editor -->
333             <li class="subfield_line" style="[% subfield_loo.visibility | html %]" id="subfield[% subfield_loo.tag | html %][% subfield_loo.subfield | html %][% subfield_loo.random | html %]">
335                 [% UNLESS advancedMARCEditor %]
336                     [% IF ( subfield_loo.fixedfield ) %]<label for="tag_[% subfield_loo.tag | html %]_subfield_[% subfield_loo.subfield | html %]_[% subfield_loo.index | html %]_[% subfield_loo.index_subfield | html %]" style="display:none;" class="labelsubfield">
337                     [% ELSE %]<label for="tag_[% subfield_loo.tag | html %]_subfield_[% subfield_loo.subfield | html %]_[% subfield_loo.index | html %]_[% subfield_loo.index_subfield | html %]" class="labelsubfield">
338                     [% END %]
339                 [% END %]
340                 
341                 [% UNLESS hide_marc %]
342                 <span class="subfieldcode">
343                         <input type="text"
344                             title="[% subfield_loo.marc_lib | $raw %]"
345                             style=" [% IF ( subfield_loo.fixedfield ) %]display:none; [% END %]border:0;"
346                             name="tag_[% subfield_loo.tag | html %]_code_[% subfield_loo.subfield | html %]_[% subfield_loo.index | html %]_[% subfield_loo.index_subfield | html %]"
347                             value="[% subfield_loo.subfield | html %]"
348                             size="1"
349                             maxlength="1"
350                             class="flat"
351                             tabindex="0" />
352                 </span>
353                 [% ELSE %]
354                     <input type="hidden"
355                         name="tag_[% subfield_loo.tag | html %]_code_[% subfield_loo.subfield | html %]_[% subfield_loo.index | html %]_[% subfield_loo.index_subfield | html %]"
356                         value="[% subfield_loo.subfield | html %]" />
357                 [% END %]
359                 [% UNLESS advancedMARCEditor %]
360                     [% IF ( subfield_loo.mandatory ) %]<span class="subfield subfield_mandatory">[% ELSE %]<span class="subfield">[% END %]
361                         [% subfield_loo.marc_lib | $raw %]
362                         [% IF ( subfield_loo.mandatory ) %]<span class="mandatory_marker" title="This field is mandatory">*</span>[% END %]
363                     </span>
364                     </label>
365                 [% END %]
366                 
367                 [% SET mv = subfield_loo.marc_value %]
368                 [% IF ( mv.type == 'select' ) %]
369                      <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor" id="[%- mv.id | html -%]">
370                      [% FOREACH aval IN mv.values %]
371                          [% IF aval == mv.default %]
372                          <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
373                          [% ELSE %]
374                          <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
375                          [% END %]
376                      [% END %]
377                      </select>
378                 [% ELSIF ( mv.type == 'text1' ) %]
379                     <input type="text" id="[%- mv.id | html -%]" name="[%- mv.id | html -%]" value="[%- mv.value | html -%]" class="input_marceditor" tabindex="1" />
380                     <a href="#" class="buttonDot" onclick="openAuth(this.parentNode.getElementsByTagName('input')[1].id,'[%- mv.authtypecode | html -%]','auth'); return false;" tabindex="1" title="Tag editor">...</a>
381                 [% ELSIF ( mv.type == 'text2' ) %]
382                     <input type="text" id="[%- mv.id | html -%]" size="67" maxlength="[%- mv.maxlength | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor" />
383                     [% IF mv.noclick %]
384                         <a href="#" class="buttonDot tag_editor disabled" tabindex="-1" title="No popup">...</a>
385                     [% ELSE %]
386                         <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor" title="Tag editor">...</a>
387                     [% END %]
388                     [% mv.javascript | $raw %]
389                 [% ELSIF ( mv.type == 'text' ) %]
390                     <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor" tabindex="1" size="67" maxlength="[%- mv.maxlength | html -%]" />
391                 [% ELSIF ( mv.type == 'textarea' ) %]
392                     <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" class="input_marceditor" tabindex="1" size="67" maxlength="[%- mv.maxlength | html -%]">[%- mv.value | html -%]</textarea>
393                 [% ELSIF ( mv.type == 'hidden' ) %]
394                     <input tabindex="1" type="hidden" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" size="67" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
395                 [% ELSIF ( mv.type == 'hidden_simple' ) %]
396                     <input type="hidden" name="[%- mv.name | html -%]" />
397                 [% END %]
399                 <span class="subfield_controls">
400                 [% IF ( subfield_loo.repeatable ) %]
401                     <a href="#" class="buttonPlus" tabindex="1" onclick="CloneSubfield('subfield[% subfield_loo.tag | html %][% subfield_loo.subfield | html %][% subfield_loo.random | html %]','[% advancedMARCEditor | html %]'); return false;">
402                         <img src="[% interface | html %]/[% theme | html %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
403                     </a>
404                     <a href="#" class="buttonMinus" tabindex="1" onclick="UnCloneField('subfield[% subfield_loo.tag | html %][% subfield_loo.subfield | html %][% subfield_loo.random | html %]'); return false;">
405                         <img src="[% interface | html %]/[% theme | html %]/img/delete-subfield.png" alt="Delete" title="Delete this subfield" />
406                     </a>
407                 [% END %]
408                 </span>
409                 
410             </li>
411             <!-- End of the line -->
412         [% END %]
414         </ul> <!-- /.sortable_subfield -->
415     </li>
416     [% END %]<!-- if innerloo.tag -->
417     </ul> <!-- /.sortable_field -->
418     [% END %]<!-- BIG_LOO.innerloop -->
419     </div>
420 [% END %]<!-- BIG_LOOP -->
422 </div><!-- tabs -->
424 <div name="hidden" id="hidden" class="tab">
425 [% FOREACH hidden_loo IN hidden_loop %]
426     <input type="hidden" name="tag" value="[% hidden_loo.tag | html %]" />
427     <input type="hidden" name="subfield" value="[% hidden_loo.subfield | html %]" />
428     <input type="hidden" name="mandatory" value="[% hidden_loo.mandatory | html %]" />
429     <input type="hidden" name="kohafield" value="[% hidden_loo.kohafield | html %]" />
430     <input type="hidden" name="tag_mandatory" value="[% hidden_loo.tag_mandatory | html %]" />
431 [% END %]
432 </div>
433 [% IF ( oldauthnumtagfield ) %]
434     <input type="hidden" name="tag" value="[% oldauthnumtagfield | html %]" />
435     <input type="hidden" name="subfield" value="[% oldauthnumtagsubfield | html %]" />
436     <input type="hidden" name="field_value" value="[% authid | html %]" />
437     <input type="hidden" name="mandatory" value="0" />
438     <input type="hidden" name="kohafield" value="[% kohafield | html %]" />
439     <input type="hidden" name="tag_mandatory" value="[% tag_mandatory | html %]" />
440     <input type="hidden" name="tag" value="[% oldauthtypetagfield | html %]" />
441     <input type="hidden" name="subfield" value="[% oldauthtypetagsubfield | html %]" />
442     <input type="hidden" name="field_value" value="[% authtypecode | html %]" />
443 [% END %]
445 </form>
447 </div>
448 </div>
449 </div>
451 [% INCLUDE 'intranet-bottom.inc' %]