Bug 13943: Prevent the deletion of items if the user cancels
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / en / modules / cataloguing / additem.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 <title>Koha &rsaquo; Cataloging &rsaquo; [% title |html %] [% IF ( author ) %] by [% author %][% END %] (Record #[% biblionumber %]) &rsaquo; Items</title>
3 <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
4 [% INCLUDE 'doc-head-close.inc' %]
5 [% INCLUDE 'datatables.inc' %]
6 <script type="text/javascript" src="[% themelang %]/js/cataloging.js"></script>
7 [% INCLUDE 'browser-strings.inc' %]
8 <!--[if lt IE 9]>
9 <script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
10 <![endif]-->
11 <script type="text/javascript" src="[% interface %]/js/browser.js"></script>
12 <script type="text/javascript">
13 //<![CDATA[
14     var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
15     browser.show();
16
17 $(document).ready(function(){
18
19     // Remove the onclick event defined in browser.js,
20     // otherwise the deletion confirmation will not work correctly
21     $('a[href*="biblionumber="]').off('click');
22
23     [% IF (popup) %]
24         [% IF (opisadd) %]
25             window.close();
26         [% END %]
27     [% END %]
28             $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
29             /* Inline edit/delete links */
30             var biblionumber = $("input[name='biblionumber']").attr("value");
31             $("tr.editable").each(function(){
32                 $(this).find("td:not(:first)").on('click', function(){
33                     var rowid = $(this).parent().attr("id");
34                     num_rowid = rowid.replace("row","");
35                     $(".linktools").remove();
36                     var edit_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&frameworkcode=[% frameworkcode %]&biblionumber=[% biblionumber %]&itemnumber='+num_rowid+'&searchid=[% searchid %]#edititem">' + _("Edit item") + '</a>');
37                     var delete_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=delitem&frameworkcode=[% frameworkcode %]&biblionumber=[% biblionumber %]&itemnumber='+num_rowid+'&searchid=[% searchid %]">' + _("Delete item") + '</a></span>');
38                     $(delete_link).on('click', function(e) {
39                         return confirm_deletion();
40                     });
41                     var tools_node = $('<span class="linktools"></span>');
42                     $(tools_node).append(edit_link);
43                     $(tools_node).append(delete_link);
44                     $(this).append(tools_node);
45                 });
46             });
47
48     var itemst = $("#itemst").dataTable($.extend(true, {}, dataTablesDefaults, {
49         "aoColumnDefs": [
50           { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
51         ],
52         'bPaginate': false,
53         'bInfo': false,
54         "bAutoWidth": false
55     } ) );
56
57 });
58 function Check(f) {
59     var total_errors = CheckMandatorySubfields(f);
60     if (total_errors==0) {
61         // Explanation about this line:
62         // In case of limited edition permission, we have to prevent user from modifying some fields.
63         // But there is no such thing as readonly attribute for select elements.
64         // So we use disabled instead. But disabled prevent values from being passed through the form at submit.
65         // So we "un-disable" the elements just before submitting.
66         // That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that.
67         $("select[name=field_value]").removeAttr("disabled");
68         return true;
69     } else {
70         var alertString2 = _("Form not submitted because of the following problem(s)");
71         alertString2 += "\n------------------------------------------------------------------------------------\n";
72         alertString2 += "\n- " + _("%s mandatory fields empty (highlighted)").format(total_errors);
73         alert(alertString2);
74         return false;
75     }
76     return true;
77 }
78 function CheckMultipleAdd(f) {
79
80     if (!f || isNaN(f) || !parseInt(f) == f || f <= 0) {
81         alert(_("Please enter a number of items to create."));
82         return false;
83     }
84     <!-- Add a soft-limit of 99 with a reminder about potential data entry error -->
85     if (f>99) {
86         return confirm(_("You are about to add %s items. Continue?").format(f));
87     }
88 }
89 function Dopop(link,i) {
90     defaultvalue=document.forms[0].field_value[i].value;
91     newin=window.open(link+"&result="+defaultvalue,"valuebuilder",'width=500,height=400,toolbar=false,scrollbars=yes');
92 }
93
94 function confirm_deletion() {
95     return confirm(_("Are you sure you want to delete this item?"));
96 }
97
98 //]]>
99 </script>
100 <link type="text/css" rel="stylesheet" href="[% themelang %]/css/addbiblio.css" />
101 [% IF ( bidi ) %]
102    <link rel="stylesheet" type="text/css" href="[% themelang %]/css/right-to-left.css" />
103 [% END %]
104 </head>
105 <body id="cat_additem" class="cat">
106 [% INCLUDE 'header.inc' %]
107 [% INCLUDE 'cataloging-search.inc' %]
108
109 <div id="breadcrumbs">
110           <a href="/cgi-bin/koha/mainpage.pl">Home</a>
111  &rsaquo; <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Cataloging</a>
112  &rsaquo; Edit <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]">[% title |html %] [% IF ( author ) %] by [% author %][% END %] (Record #[% biblionumber %])</a>
113  &rsaquo; <a href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber %]">Items</a>
114 </div>
115
116 <div id="doc3" class="yui-t7">
117
118    <div id="bd">
119         <div id="yui-main">
120
121 <h1>Items for [% title |html %] [% IF ( author ) %] by [% author %][% END %] (Record #[% biblionumber %])</h1>
122
123 [% IF ( barcode_not_unique ) %]<div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div>[% END %]
124 [% IF ( no_next_barcode ) %]<div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div>[% END %]
125 [% IF ( book_on_loan ) %]<div class="dialog alert"><strong>Cannot delete</strong>: item is checked out.</div>[% END %]
126 [% IF ( book_reserved ) %]<div class="dialogalert"><strong>Cannot delete</strong>: item has a waiting hold.</div>[% END %]
127 [% IF ( not_same_branch ) %]<div class="dialog alert"><strong>Cannot delete</strong>: The items do not belong to your library.</div>[% END %]
128 [% IF ( linked_analytics ) %]<div class="dialog alert"><strong>Cannot delete</strong>: item has linked <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber %]&amp;analyze=1">analytics.</a>.</div>[% END %]
129
130 <div id="cataloguing_additem_itemlist">
131     [% IF ( item_loop ) %]
132         <div>
133         <table id="itemst">
134           <thead>
135             <tr>
136                 <th>&nbsp;</th>
137                 [% FOREACH item_header_loo IN item_header_loop %]
138                     <th>
139                         [% item_header_loo.header_value %]
140                     </th>
141                 [% END %]
142             </tr>
143           </thead>
144           <tbody>
145                 [% FOREACH item_loo IN item_loop %]
146                     [% IF ( item_loo.itemnumber == itemnumber) %]
147                         [% IF item_loo.nomod %]
148                            <tr id="row[% item_loo.itemnumber %]" class="active highlight">
149                         [% ELSE %]
150                             <tr id="row[% item_loo.itemnumber %]" class="active editable highlight">
151                         [% END %]
152                     [% ELSE %]
153                         [% IF item_loo.nomod %]
154                            <tr id="row[% item_loo.itemnumber %]">
155                         [% ELSE %]
156                             <tr id="row[% item_loo.itemnumber %]" class="editable">
157                         [% END %]
158                     [% END %]
159                     [% IF ( item_loo.nomod ) %]
160                       <td>&nbsp;</td>
161                     [% ELSE %]
162                       <td>
163                         [% IF ( item_loo.hostitemflag ) %]
164                           <a href="additem.pl?op=edititem&amp;biblionumber=[% item_loo.hostbiblionumber %]&amp;itemnumber=[% item_loo.itemnumber %]#edititem">Edit in host</a> &nbsp; <a class="delete" href="/cgi-bin/koha/cataloguing/additem.pl?op=delinkitem&amp;biblionumber=[% biblionumber %]&amp;hostitemnumber=[% item_loo.itemnumber %]&searchid=[% searchid %]">Delink</a>
165                         [% ELSE %]
166                           <a href="additem.pl?op=edititem&amp;biblionumber=[% biblionumber %]&amp;itemnumber=[% item_loo.itemnumber %]&searchid=[% searchid %]#edititem">Edit</a>
167                           [% IF ( item_loo.countanalytics ) %]
168                             <a href="/cgi-bin/koha/catalogue/search.pl?idx=hi&amp;q=% item_loo.itemnumber %]">View analytics</a>
169                           [% ELSE %]
170                             <a class="delete" href="/cgi-bin/koha/cataloguing/additem.pl?op=delitem&amp;biblionumber=[% biblionumber %]&amp;itemnumber=[% item_loo.itemnumber %]&searchid=[% searchid %]" onclick="return confirm_deletion();">Delete</a>
171                           [% END %]
172                         [% END %]
173                       </td>
174                     [% END %]
175                 [% FOREACH item_valu IN item_loo.item_value %]
176                     <td>[% item_valu.field |html %]</td>
177                 [% END %]
178                 </tr>
179                 [% END %]
180           </tbody>
181         </table>
182         </div>
183     [% END %]
184 </div>
185 <div class="yui-gf">
186 <div class="yui-u first">
187 [% INCLUDE 'biblio-view-menu.inc' %]
188 </div>
189 <div class="yui-u">
190 <div id="cataloguing_additem_newitem">
191     <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl" name="f">
192     <input type="hidden" name="op" value="[% op %]" />
193     [% IF (popup) %]
194         <input type="hidden" name="popup" value="1" />
195     [% END %]
196     <input type="hidden" name="biblionumber" value="[% biblionumber %]" />
197     [% IF ( opisadd ) %]
198         <h2 id="additema">Add item [% IF (circborrowernumber) %]<em>(fast cataloging)</em>[% END %]</h2>
199     [% ELSE %]
200         <h2 id="edititem">Edit Item #[% itemnumber %][% IF ( barcode ) %] / Barcode [% barcode %][% END %]</h2>
201     [% END %]
202         <fieldset class="rows">
203         <ol>
204         [% FOREACH ite IN item %]
205                <li><div class="subfield_line" style="[% ite.visibility %]" id="subfield[% ite.tag %][% ite.subfield %][% ite.random %]">
206                 [% IF ( ite.mandatory ) %]
207                <label class="required">[% ite.subfield %] - [% ite.marc_lib %]</label>
208                [% ELSE %]
209                <label>[% ite.subfield %] - [% ite.marc_lib %]</label>
210                [% END %]
211
212                 [% SET mv = ite.marc_value %]
213                 [% IF ( mv.type == 'hidden' ) %]
214                     <input type="hidden" id="[%- mv.id -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength -%]" value="[%- mv.value -%]">
215                 [% ELSIF ( mv.type == 'select' ) %]
216                     [% IF ( mv.readonlyselect ) %]
217                         <select name="field_value" id="[%- mv.id -%]" size="1" class="input_marceditor" readonly="readonly" disabled="disabled">
218                     [% ELSE %]
219                         <select name="field_value" id="[%- mv.id -%]" size="1" class="input_marceditor">
220                     [% END %]
221                     [% FOREACH aval IN mv.values %]
222                         [% IF aval == mv.default %]
223                         <option value="[%- aval -%]" selected="selected">[%- mv.labels.$aval -%]</option>
224                         [% ELSE %]
225                         <option value="[%- aval -%]">[%- mv.labels.$aval -%]</option>
226                         [% END %]
227                     [% END %]
228                     </select>
229                 [% ELSIF ( mv.type == 'text_auth' ) %]
230                     <input type="text" id="[%- mv.id -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength -%]" value="[%- mv.value -%]" />
231                     [% SET dopop = "Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=\"${mv.authtypecode}\"&index=${mv.id}','${mv.id}')" %]
232                     <a href="#" class="buttonDot"  onclick="[%- dopop -%]; return false;" title="Tag editor">...</a>
233                 [% ELSIF ( mv.type == 'text_plugin' ) %]
234                     <input type="text" id="[%- mv.id -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength -%]" value="[%- mv.value -%]" />
235                     [% IF ( mv.nopopup ) %]
236                         <a href="#" id="buttonDot_[%- mv.id -%]" class="[%- mv.class -%]" title="No popup">...</a>
237                     [% ELSE  %]
238                         <a href="#" id="buttonDot_[%- mv.id -%]" class="[%- mv.class -%]" title="Tag editor">...</a>
239                     [% END %]
240                     [%- mv.javascript -%]
241                 [% ELSIF ( mv.type == 'text' ) %]
242                     <input type="text" id="[%- mv.id -%]" name="field_value" class="input_marceditor" size="50" maxlength="[%- mv.maxlength -%]" value="[%- mv.value -%]" />
243                 [% ELSIF ( mv.type == 'textarea' ) %]
244                     <textarea id="[%- mv.id -%]" name="field_value" class="input_marceditor" rows="5" cols="64" >[% mv.value %]</textarea>
245                 [% END %]
246
247                 <input type="hidden" name="tag"       value="[% ite.tag %]" />
248                 <input type="hidden" name="subfield"  value="[% ite.subfield %]" />
249                 <input type="hidden" name="mandatory" value="[% ite.mandatory %]" />
250                 [% IF ( ite.repeatable ) %]
251                     <a href="#" class="buttonPlus" onclick="CloneItemSubfield(this.parentNode); return false;">
252                         <img src="[% interface %]/[% theme %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
253                     </a>
254                 [% END %]
255                 [% IF ( ite.mandatory ) %] <span class="required">Required</span>[% END %]
256             </div></li>
257         [% END %]
258     </ol>
259     </fieldset>
260     <input type="hidden" name="indicator" value=" " />
261     <input type="hidden" name="indicator" value=" " />
262     <input type="hidden" name="itemnumber" value="[% itemnumber %]" />
263
264 <fieldset class="action">    [% IF ( opisadd ) %]
265     <input type="submit" name="phony_submit" value="phony_submit" id="phony_submit" style="display:none;" onclick="return false;" />
266     <!-- Note : We use here a false submit button because we have several submit buttons and we don't want the user to believe he validated the adding of multiple items
267                 when pressing the enter key, while in fact it is the first submit button that is validated, in our case the "add (single) item" button.
268                 It is a bit tricky, but necessary in the sake of UI correctness.
269     -->
270
271     <input type="submit" name="add_submit" value="Add item" onclick="return Check(this.form)" />
272     <input type="submit" name="add_duplicate_submit" value="Add &amp; duplicate" onclick="return Check(this.form)" />
273     <input type="submit" name="add_multiple_copies" value="Add multiple items" onclick="javascript:this.nextSibling.style.visibility='visible';document.f.number_of_copies.focus(); return false;" /><span id="add_multiple_copies_span" style="visibility:hidden">
274     <label for="number_of_copies">Number of items to add : </label>
275     <input type="text" id="number_of_copies" name="number_of_copies" value="" />
276         <input type="submit" id="add_multiple_copies_submit" name="add_multiple_copies_submit" value="Add" onclick="javascript:return Check(this.form) &amp;&amp; CheckMultipleAdd(this.form.number_of_copies.value);" />
277     </span>
278
279     [% ELSE %]
280     <input type="hidden" name="tag" value="[% itemtagfield %]" />
281     <input type="hidden" name="subfield" value="[% itemtagsubfield %]" />
282     <input type="hidden" name="field_value" value="[% itemnumber %]" />
283     <input type="submit" value="Save changes" onclick="return Check(this.form)" />
284     [% END %]</fieldset>
285     
286     [%# Fields for fast cataloging %]
287     <input type="hidden" name="circborrowernumber" value="[% circborrowernumber %]" />
288     <input type="hidden" name="stickyduedate" value="[% stickyduedate %]" />
289     <input type="hidden" name="barcode" value="[% barcode %]" />
290     <input type="hidden" name="duedatespec" value="[% duedatespec %]" />
291     [%# End fields for fast cataloging %]
292
293
294     </form>
295 </div>
296 </div><!-- /yui-u -->
297 </div><!-- /yui-gf -->
298
299 </div>
300 </div>
301 [% INCLUDE 'intranet-bottom.inc' %]