Bug 5790 - Prevent deletion of records with holds - QA Followup
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / cat-toolbar.inc
1 <div id="toolbar">
2         
3         <script type="text/javascript">
4         //<![CDATA[
5         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
6         /* this function open a popup to search on z3950 server.  */
7         function PopupZ3950() {
8                 var strQuery = GetZ3950Terms();
9                 if(strQuery){
10                         window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=[% biblionumber %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
11                 } 
12         }
13     function PopupZ3950Confirmed() {
14         if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
15             PopupZ3950();
16         }
17     }
18
19         /* provide Z3950 search points */
20         function GetZ3950Terms(){
21                 var strQuery="&frameworkcode=";
22                 [% FOREACH z3950_search_param IN z3950_search_params %]
23                         strQuery += "&" + "[% z3950_search_param.name |html %]" + "=" + "[% z3950_search_param.encvalue |html %]";
24                 [% END %]
25                 return strQuery;
26         }
27         [% END %]
28         function addToCart() { addRecord('[% biblionumber %]'); }
29         function addToShelf() { window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=[% biblionumber %]','Add_to_virtualshelf','width=500,height=400,toolbar=false,scrollbars=yes');
30         }
31     function printBiblio() {window.print(); }
32 [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
33     function confirm_deletion() {
34         var count = [% count %];
35         var holdcount = [% holdcount %];
36
37         var is_confirmed;
38         if (count > 0){
39             is_confirmed = alert( count + " " +_("item(s) are attached to this record.\nYou must delete all items before deleting this record.") );
40         } else if ( holdcount > 0 ) {
41             is_confirmed = confirm( holdcount + " " + _("holds(s) for this record \n Are you sure you want to delete this record?."));
42         } else {
43             is_confirmed = confirm(_("Are you sure you want to delete this record?"));
44         }
45
46         if (is_confirmed) {
47             if ( count > 0 || holdcount > 0 ){
48                 return false;
49             } else {
50                 window.location="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&amp;biblionumber=[% biblionumber %]";
51             }
52         } else {
53             return false;
54         }
55     }
56 [% END %]
57
58 [% IF ( CAN_user_editcatalogue_edit_items ) %]
59     function confirm_items_deletion() {
60         var count = [% count %];
61         var holdcount = [% holdcount %];
62
63         if ( holdcount > 0 ) {
64             alert( holdcount + " " + _("holds(s) for this record \n You must delete all holds before deleting all items.") );
65         } else if ( count > 0 ) {
66             if( confirm( _("Are you sure you want to delete the") + " " + count + " " + _("attached items?") ) ) {
67                 window.location="/cgi-bin/koha/cataloguing/additem.pl?op=delallitems&amp;biblionumber=[% biblionumber %]";
68             } else {
69                 return false;
70             }
71         } else {
72             alert(_("This record has no items."));
73             return false;
74         }
75     }
76 [% END %]
77         // prepare DOM for YUI Toolbar
78
79          $(document).ready(function() {
80             [% IF ( CAN_user_editcatalogue_edit_items ) %]$("#edititems").parent().remove();
81                 $("#newitem").parent().remove();[% END %]
82             [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]$("#duplicatebiblio").parent().remove();
83                 $("#deletebiblio").parent().remove();
84                 $("#z3950searchc").empty();[% END %]
85                 [% IF ( CAN_user_serials_create_subscription ) %]$("#newsub").parent().remove();[% END %]
86             $("#newbiblio").parent().remove();
87                 $("#editbiblio").parent().remove();
88                 $("#addtoshelf").parent().remove();
89                 $("#printbiblio").parent().remove();
90                 $("#placehold").parent().remove();
91                 $("#export").remove();
92          });
93
94         YAHOO.util.Event.onContentReady("cattoolbar", function () {
95                 //      Menu for new record, new item, new subscription
96                 var newmenu = [
97                         [% IF CAN_user_editcatalogue_edit_catalogue %]
98             {text: _("New record"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl" },
99             [% END %]
100                         [% IF ( CAN_user_editcatalogue_edit_items ) %]
101             {text: _("New item"), url: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber %]#additema" },
102             [% END %]
103             [% IF ( CAN_user_serials_create_subscription ) %]
104                 {text: _("New subscription"), url: "/cgi-bin/koha/serials/subscription-add.pl?biblionumber_for_new_subscription=[% biblionumber %]"},
105             [% END %]
106             [% IF ( EasyAnalyticalRecords && CAN_user_editcatalogue_edit_catalogue ) %]
107                 {text: _("Analyze items"), url: "/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber %]&analyze=1" },
108             [% END %]
109             [% IF CAN_user_editcatalogue_edit_catalogue %]
110                 {text: _("New child record"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl?parentbiblionumber=[% biblionumber %]" },
111             [% END %]
112                 ];
113                 if(newmenu.length){
114                         new YAHOO.widget.Button({
115                                 type: "menu",
116                                 label: _("New"),
117                                 id: "newmenuc",
118                                 name: "newmenubutton",
119                                 menu: newmenu,
120                                 container: this
121                          });
122                  }
123             var editmenu = [
124             [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Edit record"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&amp;frameworkcode=&amp;op=" },[% END %]
125             [% IF ( CAN_user_editcatalogue_edit_items ) %]{ text: _("Edit items"), url: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber %]" },[% END %]
126             [% IF ( CAN_user_tools_items_batchmod ) %]{ text: _("Edit items in batch"), url: "/cgi-bin/koha/tools/batchMod.pl?op=show&biblionumber=[% biblionumber %]&src=CATALOGUING" },[% END %]
127             [% IF ( CAN_user_tools_items_batchdel ) %]{ text: _("Delete items in batch"), url: "/cgi-bin/koha/tools/batchMod.pl?del=1&op=show&biblionumber=[% biblionumber %]&src=CATALOGUING" },[% END %]
128             [% IF ( CAN_user_editcatalogue_edit_items ) %]{ text: _("Attach item"), url: "/cgi-bin/koha/cataloguing/moveitem.pl?biblionumber=[% biblionumber %]" },[% END %]
129             [% IF ( EasyAnalyticalRecords ) %][% IF ( CAN_user_editcatalogue_edit_items ) %]{ text: _("Link to host item"), url: "/cgi-bin/koha/cataloguing/linkitem.pl?biblionumber=[% biblionumber %]" },[% END %][% END %]
130             [% IF ( LocalCoverImages || OPACLocalCoverImages) %][% IF ( CAN_user_tools_upload_local_cover_images ) %]{ text: _("Upload image"), url: "/cgi-bin/koha/tools/upload-cover-image.pl?biblionumber=[% biblionumber %]&filetype=image" },[% END %][% END %]
131             [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Edit as new (duplicate)"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&amp;frameworkcode=&amp;op=duplicate" },[% END %]
132             [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Replace record via Z39.50"), onclick: {fn: PopupZ3950 } },[% END %]
133             [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Delete record"), onclick: {fn: confirm_deletion }[% IF ( count || holdcount ) %],id:'disabled'[% END %] },[% END %]
134             [% IF ( CAN_user_editcatalogue_edit_items ) %]{ text: _("Delete all items"), onclick: {fn: confirm_items_deletion }[% IF ( count < 1 || holdcount ) %],id:'disabled2'[% END %] },[% END %]
135             ];
136                 if(editmenu.length){
137                         new YAHOO.widget.Button({
138                                 type: "menu",
139                                 label: _("Edit"),
140                                 id: "editmenuc",
141                                 name: "editmenubutton",
142                                 menu: editmenu,
143                                 container: this
144                          });
145                 }
146                 var savemenu = [
147                         { text: _("MODS (XML)"), url: "/cgi-bin/koha/catalogue/export.pl?format=mods&op=export&bib=[% biblionumber %]" },
148                         { text: _("Dublin Core (XML)"), url: "/cgi-bin/koha/catalogue/export.pl?format=dc&op=export&bib=[% biblionumber %]" },
149                         { text: _("MARCXML"), url: "/cgi-bin/koha/catalogue/export.pl?format=marcxml&op=export&bib=[% biblionumber %]" },
150                         { text: _("MARC (non-Unicode/MARC-8)"), url: "/cgi-bin/koha/catalogue/export.pl?format=marc8&op=export&bib=[% biblionumber %]" },
151             { text: _("MARC (Unicode/UTF-8)"), url: "/cgi-bin/koha/catalogue/export.pl?format=utf8&op=export&bib=[% biblionumber %]" },
152             { text: _("MARC (Unicode/UTF-8, Standard)"), url: "/cgi-bin/koha/catalogue/export.pl?format=marcstd&op=export&bib=[% biblionumber %]" }
153                 ];
154
155             new YAHOO.widget.Button({
156                 type: "menu",
157                 label: _("Save"),
158                 id: "savemenuc",
159                 name: "savemenubutton",
160                 menu: savemenu,
161                 container: this
162             });
163
164             var addtomenu = [
165                         { text: _("Cart"), onclick: { fn: addToCart } },
166                         { text: _("List"),  onclick: { fn: addToShelf } }
167                 ];
168
169                 new YAHOO.widget.Button({
170                 type: "menu",
171                 label: _("Add to"),
172                 name: "addtomenubutton",
173                 menu: addtomenu,
174                 container: this
175             });
176
177                 new YAHOO.widget.Button({
178                 id: "printbiblio",
179                 type: "button",
180                 label: _("Print"),
181                 container: this,
182                         onclick: {fn: printBiblio }
183                 });
184                 [% IF ( CAN_user_reserveforothers ) %][% UNLESS ( norequests ) %]
185                 [% IF ( holdfor ) %]
186                 //      Create an array of YAHOO.widget.MenuItem configuration properties
187                 var onButtonClick = function () { 
188                         location.href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblionumber %]";
189                 }
190                 var HoldForButtonMenu = [
191                         { text: _("Place hold"), url: "/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblionumber %]" },
192                         { text: _("Place hold for")+ " [% holdfor_firstname %] [% holdfor_surname %] ([% holdfor_cardnumber %])", url: "/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblionumber %]&findborrower=[% holdfor_cardnumber %]" }
193                 ];
194
195                 //      Instantiate a Split Button using the array of YAHOO.widget.MenuItem 
196                 //      configuration properties as the value for the "menu" 
197                 //      configuration attribute.
198
199                 var HoldForButton = new YAHOO.widget.Button({
200                                 id: "holdfor",
201                                 type: "split",
202                                 label: _("Place hold"),
203                                 name: "holdfor",
204                                 menu: HoldForButtonMenu,
205                                 container: this,
206                                 onclick: { fn: onButtonClick }
207                 });
208             [% ELSE %]
209             new YAHOO.widget.Button({
210                         id: "placehold",
211                         type: "link",
212                         label: _("Place hold"),
213                         container: this,
214                         href: "/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblionumber %]"
215              });
216             [% END %]
217             [% END %][% END %]
218
219         });
220         //]]>
221         </script>
222         
223 <form method="post" name="f" id="f" action="/cgi-bin/koha/cataloguing/addbiblio.pl" onsubmit="return Check();">
224
225 <ul class="toolbar" id="cattoolbar">
226
227         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
228     <li><a id="newbiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl">New record</a></li>
229         [% END %]
230         [% IF ( CAN_user_editcatalogue_edit_items ) %]
231     <li><a id="newitem" href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber %]">New item</a></li>
232         [% END %]
233         [% IF ( CAN_user_serials_create_subscription ) %]
234     <li><a id="newsub" href="/cgi-bin/koha/serials/subscription-add.pl?biblionumber_for_new_subscription=[% biblionumber %]">New subscription</a></li>
235         [% END %]
236
237         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
238     <li><a id="editbiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&amp;frameworkcode=[% current_framework %]&amp;op=">Edit record</a></li>
239         [% END %]
240         [% IF ( CAN_user_editcatalogue_edit_items ) %]
241     <li><a id="edititems" href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber %]">Edit items</a></li>
242         [% END %]
243         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
244     <li><a id="duplicatebiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&amp;frameworkcode=[% current_framework %]&amp;op=duplicate">Duplicate record</a></li>
245         [% END %]
246         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
247         <li><a id="deletebiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&amp;biblionumber=[% biblionumber %]">Delete</a></li>
248         [% END %]       
249
250         <li><a id="addtoshelf" href="/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=[% biblionumber %]">Add to shelf</a></li>
251     <li><span id="printbiblio"></span></li>
252         [% IF ( CAN_user_reserveforothers ) %]
253     [% UNLESS ( norequests ) %]<li><a id="placehold" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblionumber %]">Place hold</a></li>[% END %]
254         [% END %]
255         [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]<li id="z3950searchc"><input type="button" id="z3950search" value="Z39.50 Search" onclick="PopupZ3950Confirmed(); return false;" /></li>[% END %]
256     </ul>
257 </form>
258 </div>
259