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