Bug 19785: Move template JavaScript to the footer: Authorities, part 1
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / authorities_js.inc
1 <script type="text/javascript">
2
3 function mergeAuth(authid, summary) {
4     var alreadySelected = $.cookie('auth_to_merge');
5     if (alreadySelected !== undefined) {
6         alreadySelected = JSON.parse(alreadySelected);
7         $.cookie('auth_to_merge', '', { 'path': '/', 'expires': -1 });
8         var refstring = "";
9         if (typeof alreadySelected.mergereference !== 'undefined') {
10             refstring = "&mergereference=" + alreadySelected.mergereference;
11         }
12         window.location.href = "/cgi-bin/koha/authorities/merge.pl?authid=" + authid + "&authid=" + alreadySelected.authid + refstring;
13     } else {
14         $.cookie('auth_to_merge', JSON.stringify({ 'authid': authid, 'summary': summary }), { 'path' : '/' });
15         showMergingInProgress();
16     }
17 }
18
19 function showMergingInProgress() {
20     var alreadySelected = $.cookie('auth_to_merge');
21     if (alreadySelected !== undefined) {
22         alreadySelected = JSON.parse(alreadySelected);
23         $('#merge_in_progress').html(_("Merging with authority: ") + "<a href='detail.pl?authid=" + alreadySelected.authid + "'><span class='authorizedheading'>" + alreadySelected.summary + "</span> (" + alreadySelected.authid + ")</a> <a href='#' id='cancel_merge'>" + _("Cancel merge") + "</a>");
24         $('#cancel_merge').click(function(event) {
25             event.preventDefault();
26             $.cookie('auth_to_merge', '', { 'path': '/', 'expires': -1 });
27             $('#merge_in_progress').empty();
28         });
29     } else {
30         $('#merge_in_progress').empty();
31     }
32 }
33
34 function confirm_deletion(id) {
35     var is_confirmed = confirm(_("Are you sure you want to delete this authority?"));
36     if( !id ){
37         id = "[% authid %]";
38     }
39     if (is_confirmed) {
40       window.location="authorities-home.pl?op=delete"
41           + "&authid=" + id
42           + "&type=intranet"
43           + "&authtypecode=[% authtypecode %]"
44           + "&marclist=[% marclist %]"
45           + "&and_or=[% and_or %]"
46           + "&excluding=[% excluding %]"
47           + "&operator=[% operator %]"
48           + "&orderby=[% orderby %]"
49           + "&value=[% value |url %]"
50           + "&startfrom=[% startfrom %]"
51           + "&resultsperpage=[% resultsperpage %]"
52           + "&csrf_token=[% csrf_token %]";
53     }
54 }
55
56 $(document).ready(function () {
57     showMergingInProgress();
58     $('.merge_auth').click(function (event) {
59         event.preventDefault();
60         mergeAuth($(this).parents('tr').attr('data-authid'), $(this).parents('tr').find('div.authorizedheading').text());
61     });
62
63     $("#delAuth").click(function(){
64         confirm_deletion();
65         return false;
66     });
67
68     $("#z3950submit").click(function(){
69         [% IF ( authid ) %]
70             if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
71                 window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid %]","z3950search",'width=800,height=500,location=yes,toolbar=no,scrollbars=yes,resize=yes');
72             }
73         [% ELSE %]
74             window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl","z3950search",'width=800,height=500,location=yes,toolbar=no,scrollbars=yes,resize=yes');
75         [% END %]
76         return false;
77     });
78
79     var searchType = '[% marclist %]';
80     if (searchType) {
81         if ('mainentry' == searchType) {
82             $("#header_search").tabs( "option", "selected", 0 );
83         } else if ('match' == searchType) {
84             $("#header_search").tabs( "option", "selected", 1 );
85         } else if ('all' == searchType) {
86             $("#header_search").tabs( "option", "selected", 2 );
87         }
88     }
89
90 });
91
92 </script>