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