4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Koha › Tools › Quote editor</title>
6 [% INCLUDE 'doc-head-close.inc' %]
7 [% Asset.css("css/quotes.css") | $raw %]
10 <body id="tools_quotes" class="tools">
11 [% INCLUDE 'header.inc' %]
12 [% INCLUDE 'cat-search.inc' %]
14 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › Quote editor</div>
16 <div class="main container-fluid">
18 <div class="col-sm-10 col-sm-push-2">
21 [% INCLUDE 'quotes-toolbar.inc' %]
23 <div id="instructions">
24 <fieldset id="quote_editor_help" class="rows">
25 <legend>Instructions</legend>
26 <div id="quote_editor_inst">
28 <li>Click on the 'Add quote' button to add a single quote; Press the <Enter> 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 <Enter> 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>
37 <table id="quotes_editor">
40 <th><span style="cursor: help" id="id_help">ID</span></th>
43 <th>Last displayed</th>
47 <!-- tbody content is generated by DataTables -->
51 <td>Loading data...</td>
56 <fieldset id="footer" class="action">
60 </div> <!-- /.col-sm-10.col-sm-push-2 -->
62 <div class="col-sm-2 col-sm-pull-10">
64 [% INCLUDE 'tools-menu.inc' %]
66 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
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 %]
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({
84 "sPaginationType" : "full_numbers",
85 "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
86 "sAjaxSource" : "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
93 "oLanguage": dataTablesDefaults.oLanguage,
94 "fnPreDrawCallback": function(oSettings) {
97 "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
98 /* do foo on the current row and its child nodes */
99 var noEditFields = [];
100 var quoteID = $('td', nRow)[0].innerHTML;
101 $(nRow).attr("id", quoteID); /* set row ids to quote id */
102 $('td:eq(0)', nRow).click(function() {$(this.parentNode).toggleClass('selected',this.clicked);}); /* add row selectors */
103 $('td:eq(0)', nRow).attr("title", _("Click ID to select/deselect quote"));
104 $('td', nRow).attr("id",quoteID); /* FIXME: this is a bit of a hack */
105 if (isNaN(quoteID)) {
106 noEditFields = [0,1,2,3]; /* all fields when adding a quote */
108 noEditFields = [0,3]; /* id, timestamp */
110 /* apply no_edit id to noEditFields */
111 for (i=0; i<noEditFields.length; i++) {
112 $('td', nRow)[noEditFields[i]].setAttribute("id","no_edit");
116 "fnDrawCallback": function(oSettings) {
117 /* Apply the jEditable handlers to the table on all fields w/o the no_edit id */
118 $('#quotes_editor tbody td[id!="no_edit"]').editable( "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", {
119 "submitdata" : function ( value, settings ) {
121 "column" : oTable.fnGetPosition( this )[2],
126 "placeholder" : "Saving data...",
130 $("#add_quote").click(function(){
134 $("#delete_quote").click(function(){
138 $("#id_help").on("click",function(e){
140 alert( _("Click on the quote's id to select or deselect the quote. Multiple quotes may be selected.") );
144 function fnClickAddQuote(e, node) {
146 /* some browsers only give charCode, so this will need to be */
147 /* fixed up to handle that */
148 console.log('charCode: '+e.charCode);
150 if (e.keyCode == 13) {
151 var quoteSource = $('#quoteSource').val();
152 var quoteText = $('#quoteText').val()
153 /* If passed a quote source, add the quote to the db */
154 if (quoteSource && quoteText) {
156 url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
159 "source" : quoteSource,
163 success: function(data){
164 var newQuote = data[0];
165 var aRow = oTable.fnUpdate(
172 oTable.fnPageChange( 'last' );
173 $('.add_quote_button').attr('onclick', 'fnClickAddRow()'); // re-enable add button
177 alert(_("Please supply both the text and source of the quote before saving."));
179 } else if (e.keyCode == 27) {
180 if (confirm(_("Are you sure you want to cancel adding this quote?"))) {
181 oTable.fnDeleteRow(node);
188 function fnClickAddRow() {
189 $('.add_quote_button').removeAttr('onclick'); // disable add button once it has been clicked
190 var aRow = oTable.fnAddData(
192 'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list...
193 '<input id="quoteSource" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
194 '<input id="quoteText" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
195 '0000-00-00 00:00:00',
199 oTable.fnPageChange( 'last' );
200 $('#quoteSource').focus();
203 function fnClickDeleteRow() {
204 var idsToDelete = oTable.$('.selected').map(function() {
208 alert(_("Please select a quote(s) by clicking the quote id(s) you desire to delete."));
209 } else if (confirm(_("Are you sure you wish to delete quote(s) %s?").format(idsToDelete))) {
210 oTable.$('.selected').each(function(){
211 var quoteID = $(this).attr('id');
213 url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
219 /* Delete the row from the datatable */
221 oTable.fnDeleteRow(this);
222 oTable.fnReloadAjax(null, null, true);
233 [% INCLUDE 'intranet-bottom.inc' %]