Lines 1-10
Link Here
|
1 |
[% USE raw %] |
1 |
[% USE raw %] |
2 |
[% USE Asset %] |
2 |
[% USE Asset %] |
3 |
[% SET footerjs = 1 %] |
3 |
[% SET footerjs = 1 %] |
4 |
[% INCLUDE 'doc-head-open.inc' %] |
4 |
[% INCLUDE 'doc-head-open.inc' %] |
5 |
<title>Koha › Tools › Quote editor</title> |
5 |
<title>Koha › Tools › Quote editor</title> |
6 |
[% INCLUDE 'doc-head-close.inc' %] |
6 |
[% INCLUDE 'doc-head-close.inc' %] |
7 |
[% Asset.css("css/quotes.css") | $raw %] |
7 |
[% Asset.css("css/quotes.css") | $raw %] |
8 |
</head> |
8 |
</head> |
9 |
|
9 |
|
10 |
<body id="tools_quotes" class="tools"> |
10 |
<body id="tools_quotes" class="tools"> |
Lines 18-60
Link Here
|
18 |
<div class="col-sm-10 col-sm-push-2"> |
18 |
<div class="col-sm-10 col-sm-push-2"> |
19 |
<main> |
19 |
<main> |
20 |
|
20 |
|
21 |
[% INCLUDE 'quotes-toolbar.inc' %] |
21 |
[% FOREACH m IN messages %] |
22 |
<h2>Quote editor</h2> |
22 |
<div class="dialog [% m.type | html %]" id="quote_action_result_dialog"> |
23 |
<div id="instructions"> |
23 |
[% SWITCH m.code %] |
24 |
<fieldset id="quote_editor_help" class="rows"> |
24 |
[% CASE 'error_on_update' %] |
25 |
<legend>Instructions</legend> |
25 |
An error occurred when updating this quote. Perhaps it already exists. |
26 |
<div id="quote_editor_inst"> |
26 |
[% CASE 'error_on_insert' %] |
27 |
<ul> |
27 |
An error occurred when adding this quote. |
28 |
<li>Click on the 'Add quote' button to add a single quote; Press the <Enter> key to save the quote.<br /> |
28 |
[% CASE 'success_on_update' %] |
29 |
<strong>Note: </strong>Both the 'source' and 'text' fields must have content in order for the quote to be saved.</li> |
29 |
Quote updated successfully. |
30 |
<li>Click on any field to edit the contents; Press the <Enter> key to save edit.</li> |
30 |
[% CASE 'success_on_insert' %] |
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> |
31 |
Quote added successfully. |
32 |
<li>Click the 'Import quotes' button in the toolbar to import a CSV file of quotes.</li> |
32 |
[% CASE %] |
33 |
</ul> |
33 |
[% m.code | html %] |
34 |
</div> |
34 |
[% END %] |
35 |
</fieldset> |
35 |
</div> |
|
|
36 |
[% END %] |
37 |
|
38 |
<div class="dialog message" id="quote_delete_success" style="display: none;"></div> |
39 |
<div class="dialog alert" id="quote_delete_error" style="display: none;"></div> |
40 |
|
41 |
[% IF op == 'list' %] |
42 |
<div id="toolbar" class="btn-toolbar"> |
43 |
<a class="btn btn-default" id="newquote" href="/cgi-bin/koha/tools/quotes.pl?op=add_form"><i class="fa fa-plus"></i> New quote</a> |
44 |
<a class="btn btn-default" id="import_quotes" href="/cgi-bin/koha/tools/quotes-upload.pl"><i class="fa fa-folder-open"></i> Import quotes</a> |
45 |
</div> |
46 |
[% END %] |
47 |
|
48 |
[% IF op == 'add_form' %] |
49 |
<h3>[% IF quote %]Modify quote[% ELSE %]New quote[% END %]</h3> |
50 |
<form action="/cgi-bin/koha/tools/quotes.pl" id="Aform" name="Aform" class="validated" method="post"> |
51 |
<fieldset class="rows"> |
52 |
<input type="hidden" name="op" value="add_validate" /> |
53 |
<ol> |
54 |
<li> |
55 |
<label for="text" class="required">Source: </label> |
56 |
<input type="text" name="source" id="source" value="[% quote.source | html %]" class="required" required="required" /> |
57 |
<span class="required">Required</span> |
58 |
</li> |
59 |
<li> |
60 |
<label for="text" class="required">Text: </label> |
61 |
<textarea name="text" id="text" class="required" required="required" />[% quote.text | html %]</textarea> |
62 |
<span class="required">Required</span> |
63 |
</li> |
64 |
</ol> |
65 |
</fieldset> |
66 |
<fieldset class="action"> |
67 |
<input type="hidden" name="id" value="[% quote.id %]" /> |
68 |
<input type="submit" value="Submit" /> |
69 |
<a class="cancel" href="/cgi-bin/koha/tools/quotes.pl">Cancel</a> |
70 |
</fieldset> |
71 |
</form> |
72 |
[% END %] |
73 |
|
74 |
[% IF op == 'delete_confirm' %] |
75 |
<div class="dialog alert"> |
76 |
<form action="/cgi-bin/koha/tools/quotes.pl" method="post"> |
77 |
<h3>Are you sure you want to delete the following quote?</h3> |
78 |
[% quote.source | html %] - [% quote.text | html %] |
79 |
<input type="hidden" name="op" value="delete_confirmed" /> |
80 |
<input type="hidden" name="id" value="[% quote.id | html %]" /> |
81 |
<button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button> |
82 |
</form> |
83 |
<form action="/cgi-bin/koha/tools/quotes.pl" method="get"> |
84 |
<button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button> |
85 |
</form> |
86 |
</div> |
87 |
[% END %] |
88 |
|
89 |
[% IF op == 'list' %] |
90 |
<h3>Quotes</h3> |
91 |
[% IF quotes_count > 0 %] |
92 |
<table id="quotes"> |
93 |
<thead> |
94 |
<tr> |
95 |
<th>ID</th> |
96 |
<th>Source</th> |
97 |
<th>Text</th> |
98 |
<th>Last display</th> |
99 |
<th data-class-name="actions">Actions</th> |
100 |
</tr> |
101 |
</thead> |
102 |
</table> |
103 |
[% ELSE %] |
104 |
<div class="dialog message">There are no quotes defined. <a href="/cgi-bin/koha/tools/quotes.pl?op=add_form">Start defining quotes</a>.</div> |
105 |
[% END %] |
106 |
|
107 |
<div id="delete_confirm_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="delete_confirm_modal_label" aria-hidden="true"> |
108 |
<div class="modal-dialog"> |
109 |
<div class="modal-content"> |
110 |
<div class="modal-header"> |
111 |
<button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button> |
112 |
<h3 id="delete_confirm_modal_label">Delete quote</h3> |
36 |
</div> |
113 |
</div> |
37 |
<table id="quotes_editor"> |
114 |
<div class="modal-body"> |
38 |
<thead> |
115 |
<div id="delete_confirm_dialog"></div> |
39 |
<tr> |
116 |
</div> |
40 |
<th><span style="cursor: help" id="id_help">ID</span></th> |
117 |
<div class="modal-footer"> |
41 |
<th>Source</th> |
118 |
<a href="#" class="btn btn-default" id="delete_confirm_modal_button" role="button" data-toggle="modal">Delete</a> |
42 |
<th>Text</th> |
119 |
<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button> |
43 |
<th>Last displayed</th> |
120 |
</div> |
44 |
</tr> |
121 |
</div> <!-- /.modal-content --> |
45 |
</thead> |
122 |
</div> <!-- /.modal-dialog --> |
46 |
<tbody> |
123 |
</div> <!-- #delete_confirm_modal --> |
47 |
<!-- tbody content is generated by DataTables --> |
124 |
[% END %] |
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 |
|
125 |
|
59 |
</main> |
126 |
</main> |
60 |
</div> <!-- /.col-sm-10.col-sm-push-2 --> |
127 |
</div> <!-- /.col-sm-10.col-sm-push-2 --> |
Lines 68-231
Link Here
|
68 |
|
135 |
|
69 |
[% MACRO jsinclude BLOCK %] |
136 |
[% MACRO jsinclude BLOCK %] |
70 |
[% Asset.js("js/tools-menu.js") | $raw %] |
137 |
[% Asset.js("js/tools-menu.js") | $raw %] |
|
|
138 |
[% INCLUDE 'js-date-format.inc' %] |
71 |
[% INCLUDE 'datatables.inc' %] |
139 |
[% INCLUDE 'datatables.inc' %] |
72 |
[% Asset.js("lib/jquery/plugins/dataTables.fnReloadAjax.js") | $raw %] |
140 |
|
73 |
[% Asset.js("lib/jquery/plugins/jquery.jeditable.mini.js") | $raw %] |
|
|
74 |
<script> |
141 |
<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() { |
142 |
$(document).ready(function() { |
78 |
/* NOTE: This is an ajax-source datatable and *not* a server-side sourced datatable. */ |
143 |
|
79 |
/* See the datatable docs if you don't understand this difference. */ |
144 |
var quotes_url = '/api/v1/quotes'; |
80 |
oTable = $("#quotes_editor").dataTable({ |
145 |
var quotes = $("#quotes").api({ |
81 |
"bAutoWidth" : false, |
146 |
"ajax": { |
82 |
"bProcessing" : true, |
147 |
"url": quotes_url |
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": dataTablesDefaults.oLanguage, |
94 |
"fnPreDrawCallback": function(oSettings) { |
95 |
return true; |
96 |
}, |
148 |
}, |
97 |
"fnRowCallback": function( nRow, aData, iDisplayIndex ) { |
149 |
'emptyTable': '<div class="dialog message">'+_("There are no quotes defined.")+' <a href="/cgi-bin/koha/tools/quotes.pl?op=add_form">'+_("Start defining quotes")+'</a>.</div>', |
98 |
/* do foo on the current row and its child nodes */ |
150 |
"columnDefs": [ { |
99 |
var noEditFields = []; |
151 |
"targets": [0,1,2,3], |
100 |
var quoteID = $('td', nRow)[0].innerHTML; |
152 |
"render": function (data, type, row, meta) { |
101 |
$(nRow).attr("id", quoteID); /* set row ids to quote id */ |
153 |
if ( type == 'display' ) { |
102 |
$('td:eq(0)', nRow).click(function() {$(this.parentNode).toggleClass('selected',this.clicked);}); /* add row selectors */ |
154 |
if ( data != null ) { |
103 |
$('td:eq(0)', nRow).attr("title", _("Click ID to select/deselect quote")); |
155 |
return data.escapeHtml(); |
104 |
$('td', nRow).attr("id",quoteID); /* FIXME: this is a bit of a hack */ |
156 |
} |
105 |
if (isNaN(quoteID)) { |
157 |
else { |
106 |
noEditFields = [0,1,2,3]; /* all fields when adding a quote */ |
158 |
return ""; |
107 |
} else { |
159 |
} |
108 |
noEditFields = [0,3]; /* id, timestamp */ |
160 |
} |
109 |
} |
161 |
return data; |
110 |
/* apply no_edit id to noEditFields */ |
|
|
111 |
for (i=0; i<noEditFields.length; i++) { |
112 |
$('td', nRow)[noEditFields[i]].setAttribute("id","no_edit"); |
113 |
} |
162 |
} |
114 |
return nRow; |
163 |
} ], |
115 |
}, |
164 |
"columns": [ |
116 |
"fnDrawCallback": function(oSettings) { |
165 |
{ |
117 |
/* Apply the jEditable handlers to the table on all fields w/o the no_edit id */ |
166 |
"data": "quote_id", |
118 |
$('#quotes_editor tbody td[id!="no_edit"]').editable( "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", { |
167 |
"searchable": true, |
119 |
"submitdata" : function ( value, settings ) { |
168 |
"orderable": true |
120 |
return { |
169 |
}, |
121 |
"column" : oTable.fnGetPosition( this )[2], |
170 |
{ |
122 |
"action" : "edit", |
171 |
"data": "source", |
123 |
}; |
172 |
"searchable": true, |
124 |
}, |
173 |
"orderable": true |
125 |
"placeholder" : "Saving data...", |
174 |
}, |
126 |
}); |
175 |
{ |
127 |
}, |
176 |
"data": "text", |
128 |
}); |
177 |
"searchable": true, |
129 |
$("#add_quote").click(function(){ |
178 |
"orderable": true |
130 |
fnClickAddRow(); |
179 |
}, |
131 |
return false; |
180 |
{ |
132 |
}); |
181 |
"data": function( row, type, val, meta ) { |
133 |
$("#delete_quote").click(function(){ |
182 |
return $datetime(row.displayed_on); |
134 |
fnClickDeleteRow(); |
183 |
}, |
135 |
return false; |
184 |
"searchable": true, |
136 |
}); |
185 |
"orderable": true |
137 |
$("#id_help").on("click",function(e){ |
186 |
}, |
138 |
e.stopPropagation(); |
187 |
{ |
139 |
alert( _("Click on the quote's id to select or deselect the quote. Multiple quotes may be selected.") ); |
188 |
"data": function( row, type, val, meta ) { |
140 |
}); |
|
|
141 |
}); |
142 |
|
189 |
|
143 |
function fnClickAddQuote(e, node) { |
190 |
var result = '<a class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/quotes.pl?op=add_form&id='+encodeURIComponent(row.quote_id)+'" role="button"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'; |
144 |
if (e.charCode) { |
191 |
result += '<form action="/cgi-bin/koha/tools/quotes.pl" method="post">'; |
145 |
/* some browsers only give charCode, so this will need to be */ |
192 |
result += '<input type="hidden" name="id" value="'+row.quote_id.escapeHtml()+'" />'+"\n"; |
146 |
/* fixed up to handle that */ |
193 |
|
147 |
console.log('charCode: '+e.charCode); |
194 |
result += '<a class="btn btn-default btn-xs delete_quote" role="button" href="#" data-toggle="modal" data-target="#delete_confirm_modal" data-quote-id="'+ encodeURIComponent(row.quote_id) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</a>'; |
148 |
} |
195 |
|
149 |
if (e.keyCode == 13) { |
196 |
return result; |
150 |
var quoteSource = $('#quoteSource').val(); |
|
|
151 |
var quoteText = $('#quoteText').val() |
152 |
/* If passed a quote source, add the quote to the db */ |
153 |
if (quoteSource && quoteText) { |
154 |
$.ajax({ |
155 |
url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", |
156 |
type: "POST", |
157 |
data: { |
158 |
"source" : quoteSource, |
159 |
"text" : quoteText, |
160 |
"action" : "add", |
161 |
}, |
197 |
}, |
162 |
success: function(data){ |
198 |
"searchable": false, |
163 |
var newQuote = data[0]; |
199 |
"orderable": false |
164 |
var aRow = oTable.fnUpdate( |
200 |
}, |
165 |
newQuote, |
201 |
] |
166 |
node, |
202 |
}); |
167 |
undefined, |
203 |
|
168 |
false, |
204 |
$('#quotes').on( "click", '.delete_quote', function () { |
169 |
false |
205 |
var quote_id = decodeURIComponent($(this).data('quote-id')); |
170 |
); |
206 |
|
171 |
oTable.fnPageChange( 'last' ); |
207 |
$("#delete_confirm_dialog").html( |
172 |
$('.add_quote_button').attr('onclick', 'fnClickAddRow()'); // re-enable add button |
208 |
_("You are about to delete the quote #%s.").format(quote_id) |
173 |
} |
209 |
); |
174 |
}); |
210 |
|
175 |
} else { |
211 |
$("#delete_confirm_modal_button").unbind("click").on( "click", function () { |
176 |
alert(_("Please supply both the text and source of the quote before saving.")); |
|
|
177 |
} |
178 |
} else if (e.keyCode == 27) { |
179 |
if (confirm(_("Are you sure you want to cancel adding this quote?"))) { |
180 |
oTable.fnDeleteRow(node); |
181 |
} else { |
182 |
return; |
183 |
} |
184 |
} |
185 |
} |
186 |
|
187 |
function fnClickAddRow() { |
188 |
$('.add_quote_button').removeAttr('onclick'); // disable add button once it has been clicked |
189 |
var aRow = oTable.fnAddData( |
190 |
[ |
191 |
'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list... |
192 |
'<input id="quoteSource" type="text" style="width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>', |
193 |
'<input id="quoteText" type="text" style="width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>', |
194 |
'0000-00-00 00:00:00', |
195 |
], |
196 |
false |
197 |
); |
198 |
oTable.fnPageChange( 'last' ); |
199 |
$('#quoteSource').focus(); |
200 |
} |
201 |
|
202 |
function fnClickDeleteRow() { |
203 |
var idsToDelete = oTable.$('.selected').map(function() { |
204 |
return this.id; |
205 |
}).get().join(', '); |
206 |
if (!idsToDelete) { |
207 |
alert(_("Please select a quote(s) by clicking the quote id(s) you desire to delete.")); |
208 |
} else if (confirm(_("Are you sure you wish to delete quote(s) %s?").format(idsToDelete))) { |
209 |
oTable.$('.selected').each(function(){ |
210 |
var quoteID = $(this).attr('id'); |
211 |
$.ajax({ |
212 |
$.ajax({ |
212 |
url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", |
213 |
method: "DELETE", |
213 |
type: "POST", |
214 |
url: "/api/v1/quotes/"+quote_id |
214 |
data: { |
215 |
}).success(function() { |
215 |
"id" : quoteID, |
216 |
$("#delete_confirm_modal").modal('hide'); |
216 |
"action" : "delete", |
217 |
quotes.api().ajax.reload(function (data) { |
217 |
}, |
218 |
if (data.recordsTotal == 0) { |
218 |
/* Delete the row from the datatable */ |
219 |
$("#quotes").hide(); |
219 |
success: function(){ |
220 |
} |
220 |
oTable.fnDeleteRow(this); |
221 |
$("#quote_action_result_dialog").hide(); |
221 |
oTable.fnReloadAjax(null, null, true); |
222 |
$("#quote_delete_success").html(_("Quote #%s deleted successfully.").format(quote_id)).show(); |
222 |
} |
223 |
}); |
|
|
224 |
}).error(function () { |
225 |
$("#quote_delete_error").html(_("Error deleting quote #%s. Check the logs.").format(quote_id)).show(); |
223 |
}); |
226 |
}); |
224 |
}); |
227 |
}); |
225 |
} else { |
228 |
}); |
226 |
return; |
229 |
|
227 |
} |
230 |
}); |
228 |
} |
|
|
229 |
</script> |
231 |
</script> |
230 |
[% END %] |
232 |
[% END %] |
231 |
|
233 |
|