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