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