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