Bug 11360 - Disable barcode field and submit button when a hold is found
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / quotes.tt
1     [% INCLUDE 'doc-head-open.inc' %]
2     <title>Koha &rsaquo; Tools &rsaquo; Quote editor</title>
3     [% INCLUDE 'doc-head-close.inc' %]
4     <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/quotes.css" />
5     <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
6     [% INCLUDE 'datatables.inc' %]
7     <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/dataTables.fnReloadAjax.js"></script>
8     <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.jeditable.mini.js"></script>
9     <script type="text/javascript">
10     //<![CDATA[
11
12     var oTable; /* oTable needs to be global */
13     var sEmptyTable = _("No quotes available. Please use the 'Add quote' button to add a quote."); /* override the default message in datatables.inc */
14     $(document).ready(function() {
15         /* NOTE: This is an ajax-source datatable and *not* a server-side sourced datatable. */
16         /* See the datatable docs if you don't understand this difference. */
17         oTable = $("#quotes_editor").dataTable({
18                     "bAutoWidth"        : false,
19                     "bProcessing"       : true,
20                     "bPaginate"         : true,
21                     "sPaginationType"   : "full_numbers",
22                     "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
23                     "sAjaxSource"       : "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
24                     "aoColumns"         : [
25                                             { "sWidth": "3%"  },
26                                             { "sWidth": "11%" },
27                                             { "sWidth": "75%" },
28                                             { "sWidth": "11%" },
29                                           ],
30                    "oLanguage"          : {
31                                             "oPaginate": {
32                                                            "sFirst": MSG_DT_FIRST,
33                                                            "sLast": MSG_DT_LAST,
34                                                            "sNext": MSG_DT_NEXT,
35                                                            "sPrevious": MSG_DT_PREVIOUS,
36                                                          },
37                                             "sEmptyTable": MSG_DT_EMPTY_TABLE,
38                                             "sInfo": MSG_DT_INFO,
39                                             "sInfoEmpty": MSG_DT_INFO_EMPTY,
40                                             "sInfoFiltered": MSG_DT_INFO_FILTERED,
41                                             "sLengthMenu": MSG_DT_LENGTH_MENU,
42                                             "sLoadingRecords": MSG_DT_LOADING_RECORDS,
43                                             "sProcessing": MSG_DT_PROCESSING,
44                                             "sSearch": MSG_DT_SEARCH,
45                                             "sZeroRecords": MSG_DT_ZERO_RECORDS,
46                                           },
47                    "fnPreDrawCallback": function(oSettings) {
48                         return true;
49                     },
50                     "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
51                         /* do foo on the current row and its child nodes */
52                         var noEditFields = [];
53                         var quoteID = $('td', nRow)[0].innerHTML;
54                         $(nRow).attr("id", quoteID); /* set row ids to quote id */
55                         $('td:eq(0)', nRow).click(function() {$(this.parentNode).toggleClass('selected',this.clicked);}); /* add row selectors */
56                         $('td:eq(0)', nRow).attr("title", _("Click ID to select/deselect quote"));
57                         $('td', nRow).attr("id",quoteID); /* FIXME: this is a bit of a hack */
58                         if (isNaN(quoteID)) {
59                             noEditFields = [0,1,2,3]; /* all fields when adding a quote */
60                         }
61                         else {
62                             noEditFields = [0,3]; /* id, timestamp */
63                         }
64                         /* apply no_edit id to noEditFields */
65                         for (i=0; i<noEditFields.length; i++) {
66                             $('td', nRow)[noEditFields[i]].setAttribute("id","no_edit");
67                         }
68                         return nRow;
69                     },
70                    "fnDrawCallback": function(oSettings) {
71                         /* Apply the jEditable handlers to the table on all fields w/o the no_edit id */
72                         $('#quotes_editor tbody td[id!="no_edit"]').editable( "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", {
73                             "submitdata"    : function ( value, settings ) {
74                                                   return {
75                                                       "column"        : oTable.fnGetPosition( this )[2],
76                                                       "action"        : "edit",
77                                                   };
78                                               },
79                             "height"        : "14px",
80                             "placeholder"   : "Saving data...",
81                         });
82                    },
83         });
84         $("#add_quote").click(function(){
85             fnClickAddRow();
86             return false;
87         });
88         $("#delete_quote").click(function(){
89             fnClickDeleteRow();
90             return false;
91         });
92         $("#id_help").on("click",function(e){
93             e.stopPropagation();
94             alert( _("Click on the quote's id to select or deselect the quote. Multiple quotes may be selected.") );
95         });
96     });
97
98         function fnClickAddQuote(e, node) {
99             if (e.charCode) {
100                 /* some browsers only give charCode, so this will need to be */
101                 /* fixed up to handle that */
102                 console.log('charCode: '+e.charCode);
103             }
104             if (e.keyCode == 13) {
105                 var quoteSource = $('#quoteSource').val();
106                 var quoteText = $('#quoteText').val()
107                 /* If passed a quote source, add the quote to the db */
108                 if (quoteSource && quoteText) {
109                     $.ajax({
110                         url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
111                         type: "POST",
112                         data: {
113                                 "source"    : quoteSource,
114                                 "text"      : quoteText,
115                                 "action"    : "add",
116                         },
117                         success: function(data){
118                                     var newQuote = data[0];
119                                     var aRow = oTable.fnUpdate(
120                                         newQuote,
121                                         node,
122                                         undefined,
123                                         false,
124                                         false
125                                     );
126                                     oTable.fnPageChange( 'last' );
127                                     $('.add_quote_button').attr('onclick', 'fnClickAddRow()'); // re-enable add button
128                             }
129                     });
130                 }
131                 else {
132                     alert(_("Please supply both the text and source of the quote before saving."));
133                 }
134             }
135             else if (e.keyCode == 27) {
136                 if (confirm(_("Are you sure you want to cancel adding this quote?"))) {
137                     oTable.fnDeleteRow(node);
138                 }
139                 else {
140                     return;
141                 }
142             }
143         }
144
145         function fnClickAddRow() {
146             $('.add_quote_button').removeAttr('onclick'); // disable add button once it has been clicked
147             var aRow = oTable.fnAddData(
148                 [
149                     'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list...
150                     '<input id="quoteSource" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
151                     '<input id="quoteText" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
152                     '0000-00-00 00:00:00',
153                 ],
154                 false
155             );
156             oTable.fnPageChange( 'last' );
157             $('#quoteSource').focus();
158         }
159
160         function fnClickDeleteRow() {
161             var idsToDelete = oTable.$('.selected').map(function() {
162                   return this.id;
163             }).get().join(', ');
164             if (!idsToDelete) {
165                 alert(_("Please select a quote(s) by clicking the quote id(s) you desire to delete."));
166             }
167             else if (confirm(_("Are you sure you wish to delete quote(s) %s?").format(idsToDelete))) {
168                 oTable.$('.selected').each(function(){
169                         var quoteID = $(this).attr('id');
170                             $.ajax({
171                                 url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
172                                 type: "POST",
173                                 data: {
174                                         "id"        : quoteID,
175                                         "action"    : "delete",
176                                 },
177                                 /* Delete the row from the datatable */
178                                 success: function(){
179                                     oTable.fnDeleteRow(this);
180                                     oTable.fnReloadAjax(null, null, true);
181                                 }
182                             });
183                     });
184             }
185             else {
186                 return;
187             }
188         }
189     //]]>
190     </script>
191 </head>
192 <body id="tools_quotes" class="tools">
193 [% INCLUDE 'header.inc' %]
194 [% INCLUDE 'cat-search.inc' %]
195
196 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; Quote editor</div>
197
198 <div id="doc3" class="yui-t2">
199     <div id="bd">
200         <div id="yui-main">
201             <div class="yui-b">
202                 [% INCLUDE 'quotes-toolbar.inc' %]
203                 <h2>Quote editor</h2>
204                 <div id="instructions">
205                 <fieldset id="quote_editor_help" class="rows">
206                     <legend>Instructions</legend>
207                     <div id="quote_editor_inst">
208                         <ul>
209                         <li>Click on the 'Add quote' button to add a single quote; Press the &lt;Enter&gt; key to save the quote.<br />
210                             <b>Note: </b>Both the 'source' and 'text' fields must have content in order for the quote to be saved.</li>
211                         <li>Click on any field to edit the contents; Press the &lt;Enter&gt; key to save edit.</li>
212                         <li>Click on one or more quote numbers to select entire quotes for deletion; Click the 'Delete quote(s)' button to delete selected quotes.</li>
213                         <li>Click the 'Import quotes' button in the toolbar to import a CSV file of quotes.</li>
214                         </ul>
215                     </div>
216                 </fieldset>
217                 </div>
218                 <table id="quotes_editor">
219                 <thead>
220                     <tr>
221                         <th><span style="cursor: help" id="id_help">ID</span></th>
222                         <th>Source</th>
223                         <th>Text</th>
224                         <th>Last displayed</th>
225                     </tr>
226                 </thead>
227                 <tbody>
228                     <!-- tbody content is generated by DataTables -->
229                     <tr>
230                         <td></td>
231                         <td></td>
232                         <td>Loading data...</td>
233                         <td></td>
234                     </tr>
235                 </tbody>
236                 </table>
237                 <fieldset id="footer" class="action">
238                 </fieldset>
239             </div>
240         </div>
241     <div class="yui-b noprint">
242         [% INCLUDE 'tools-menu.inc' %]
243     </div>
244 </div>
245 [% INCLUDE 'intranet-bottom.inc' %]