Bug 7977: QOTD uploader to enable uploading csv files containing quotes
[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     <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6     <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/dataTables.fnReloadAjax.js"></script>
7     [% INCLUDE 'datatables-strings.inc' %]
8     </script>
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 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                     "sAjaxSource"       : "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
24                     "aoColumns"         : [
25                                             { "sWidth": "3%"  },
26                                             { "sWidth": "11%" },
27                                             { "sWidth": "75%" },
28                                             { "sWidth": "11%" },
29                                           ],
30                    "oLanguage"          : {
31                                             "sEmptyTable": sEmptyTable,
32                                           },
33                    "fnPreDrawCallback": function(oSettings) {
34                         return true;
35                     },
36                     "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
37                         /* do foo on the current row and its child nodes */
38                         var noEditFields = [];
39                         var quoteID = $('td', nRow)[0].innerHTML;
40                         $(nRow).attr("id", quoteID); /* set row ids to quote id */
41                         $('td:eq(0)', nRow).click(function() {$(this.parentNode).toggleClass('selected',this.clicked);}); /* add row selectors */
42                         $('td:eq(0)', nRow).attr("title", "Click ID to select/deselect quote");
43                         if (isNaN(quoteID)) {
44                             noEditFields = [0,1,2,3]; /* all fields when adding a quote */
45                         }
46                         else {
47                             noEditFields = [0,3]; /* id, timestamp */
48                         }
49                         /* apply no_edit id to noEditFields */
50                         for (i=0; i<noEditFields.length; i++) {
51                             $('td', nRow)[noEditFields[i]].setAttribute("id","no_edit");
52                         }
53                         return nRow;
54                     },
55                    "fnDrawCallback": function(oSettings) {
56                         /* Apply the jEditable handlers to the table on all fields w/o the no_edit id */
57                         $('#quotes_editor tbody td[id!="no_edit"]').editable( "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", {
58                             "submitdata"    : function ( value, settings ) {
59                                                   return {
60                                                       "column"        : oTable.fnGetPosition( this )[2],
61                                                       "action"        : "edit",
62                                                   };
63                                               },
64                             "height"        : "14px",
65                             "placeholder"   : "Saving data...",
66                         });
67                    },
68         });
69     });
70
71         function fnClickAddQuote(e, node) {
72             if (e.charCode) {
73                 /* some browsers only give charCode, so this will need to be */
74                 /* fixed up to handle that */
75                 console.log('charCode: '+e.charCode);
76             }
77             if (e.keyCode == 13) {
78                 var quoteSource = $('#quoteSource').val();
79                 var quoteText = $('#quoteText').val()
80                 /* If passed a quote source, add the quote to the db */
81                 if (quoteSource && quoteText) {
82                     $.ajax({
83                         url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
84                         type: "POST",
85                         data: {
86                                 "source"    : quoteSource,
87                                 "text"      : quoteText,
88                                 "action"    : "add",
89                         },
90                         success: function(data){
91                                     var newQuote = data[0];
92                                     var aRow = oTable.fnUpdate(
93                                         newQuote,
94                                         node,
95                                         false,
96                                         false
97                                     );
98                                     oTable.fnPageChange( 'last' );
99                                     $('.add_quote_button').attr('onclick', 'fnClickAddRow()'); // re-enable add button
100                             }
101                     });
102                 }
103                 else {
104                     alert('Please supply both the text and source of the quote before saving.');
105                 }
106             }
107             else if (e.keyCode == 27) {
108                 if (confirm('Are you sure you want to cancel adding this quote?')) {
109                     oTable.fnDeleteRow(node);
110                 }
111                 else {
112                     return;
113                 }
114             }
115         }
116
117         function fnClickAddRow() {
118             $('.add_quote_button').removeAttr('onclick'); // disable add button once it has been clicked
119             var aRow = oTable.fnAddData(
120                 [
121                     'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list...
122                     '<input id="quoteSource" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
123                     '<input id="quoteText" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
124                     '0000-00-00 00:00:00',
125                 ],
126                 false
127             );
128             oTable.fnPageChange( 'last' );
129             $('#quoteSource').focus();
130         }
131
132         function fnClickDeleteRow() {
133             var idsToDelete = oTable.$('.selected').map(function() {
134                   return this.id;
135             }).get().join(', ');
136             if (!idsToDelete) {
137                 alert('Please select a quote(s) by clicking the quote id(s) you desire to delete.');
138             }
139             else if (confirm('Are you sure you wish to delete quote(s) '+idsToDelete+'?')) {
140                 oTable.$('.selected').each(function(){
141                         var quoteID = $(this).attr('id');
142                             $.ajax({
143                                 url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
144                                 type: "POST",
145                                 data: {
146                                         "id"        : quoteID,
147                                         "action"    : "delete",
148                                 },
149                                 /* Delete the row from the datatable */
150                                 success: function(){
151                                     oTable.fnDeleteRow(this);
152                                     oTable.fnReloadAjax(null, null, true);
153                                 }
154                             });
155                     });
156             }
157             else {
158                 return;
159             }
160         }
161     //]]>
162     </script>
163 </head>
164 <body id="tools_quotes" class="tools">
165 [% INCLUDE 'header.inc' %]
166 [% INCLUDE 'cat-search.inc' %]
167
168 <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>
169
170 <div id="doc3" class="yui-t2">
171     <div id="bd">
172         <div id="yui-main">
173             <div class="yui-b">
174                 [% INCLUDE 'quotes-toolbar.inc' %]
175                 <h2>Quote editor</h2>
176                 <table id="quotes_editor" style="float: left; width: 100%;">
177                 <thead>
178                     <tr>
179                         <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>
180                         <th>Source</th>
181                         <th>Text</th>
182                         <th>Last Displayed</th>
183 <!--                        <th>Actions</th>-->
184                     </tr>
185                 </thead>
186                 <tbody>
187                     <!-- tbody content is generated by DataTables -->
188                     <tr>
189                         <td></td>
190                         <td></td>
191                         <td>Loading data...</td>
192                         <td></td>
193 <!--                        <td></td>-->
194                     </tr>
195                 </tbody>
196                 </table>
197                 <fieldset id="footer" class="action" style="height:25px;">
198                 </fieldset>
199             </div>
200         </div>
201     <div class="yui-b noprint">
202         [% INCLUDE 'tools-menu.inc' %]
203     </div>
204 </div>
205 [% INCLUDE 'intranet-bottom.inc' %]