forked from j62/ctbrec
1
0
Fork 0

Fix: show notification and clear input field after adding a model

This commit is contained in:
0xb00bface 2023-11-12 17:58:08 +01:00
parent 41ffd75d48
commit 98aa9bc148
1 changed files with 16 additions and 13 deletions

View File

@ -137,8 +137,8 @@
<span data-bind="text: throughput.text()" style="float:right"></span> <span data-bind="text: throughput.text()" style="float:right"></span>
<span class="progress"> <span class="progress">
<span class="progress-bar progress-bar-striped" role="progressbar" aria-valuemin="0" data-bind="attr: {'aria-valuemax': space.total, 'aria-valuenow': space.free}, <span class="progress-bar progress-bar-striped" role="progressbar" aria-valuemin="0" data-bind="attr: {'aria-valuemax': space.total, 'aria-valuenow': space.free},
style: { width: space.percent() + '%' }, style: { width: space.percent() + '%' },
text: space.percent() + '%'"> text: space.percent() + '%'">
</span> </span>
</span> </span>
</div> </div>
@ -153,7 +153,7 @@
<th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'model.name'}">Model</a></th> <th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'model.name'}">Model</a></th>
<th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'startDate'}">Date</a></th> <th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'startDate'}">Date</a></th>
<th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'ko_status'}">Status</a></th> <th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'ko_status'}">Status</a></th>
<!-- <th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'progress'}">Progress</a></th> --> <!-- <th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'progress'}">Progress</a></th> -->
<th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'sizeInByte'}">Size</a></th> <th><a href="#" data-bind="orderable: {collection: 'recordings', field: 'sizeInByte'}">Size</a></th>
<th></th> <th></th>
<th></th> <th></th>
@ -166,7 +166,7 @@
<td><a data-bind="attr: { href: model.url, title: model.name }, text: model.name"></a></td> <td><a data-bind="attr: { href: model.url, title: model.name }, text: model.name"></a></td>
<td data-bind="text: ko_date"></td> <td data-bind="text: ko_date"></td>
<td data-bind="text: ko_status"></td> <td data-bind="text: ko_status"></td>
<!-- <td data-bind="text: ko_progressString"></td> --> <!-- <td data-bind="text: ko_progressString"></td> -->
<td data-bind="text: ko_size"></td> <td data-bind="text: ko_size"></td>
<td> <td>
<button class="btn btn-secondary fa fa-play" title="Play recording" data-bind="click: play"></button> <button class="btn btn-secondary fa fa-play" title="Play recording" data-bind="click: play"></button>
@ -289,13 +289,13 @@
function addModelKeyPressed(e) { function addModelKeyPressed(e) {
let charCode = (typeof e.which === "number") ? e.which : e.keyCode; let charCode = (typeof e.which === "number") ? e.which : e.keyCode;
let val = $('#addModelByUrl').val(); let val = $('#addModelByUrl').val();
let duration = $('#recordingDuration').val(); // Get the recording duration input let duration = $('#recordingDuration').val(); // Get the recording duration input
if (charCode === 13) { if (charCode === 13) {
// Check if a valid duration is provided // Check if a valid duration is provided
let durationMinutes = duration ? parseInt(duration) : undefined; let durationMinutes = duration ? parseInt(duration) : undefined;
ctbrec.add(val, durationMinutes, function() { ctbrec.add(val, durationMinutes, function() {
$('#addModelByUrl').val(''); $('#addModelByUrl').val('');
$('#recordingDuration').val(''); // Clear the recording duration input $('#recordingDuration').val(''); // Clear the recording duration input
}); });
} else { } else {
$('#addModelByUrl').autocomplete({ $('#addModelByUrl').autocomplete({
@ -305,7 +305,7 @@
} }
let ctbrec = { let ctbrec = {
add: function(input, onsuccess) { add: function(input, duration, onsuccess) {
try { try {
let model = { let model = {
type: null, type: null,
@ -326,8 +326,11 @@
data: msg data: msg
}) })
.done(function(data) { .done(function(data) {
console.log(data);
if (data.status === 'success') { if (data.status === 'success') {
onsuccess.call(data); if (onsuccess) {
onsuccess.call(data);
}
$.notify('Model added', 'info'); $.notify('Model added', 'info');
} else { } else {
$.notify('Adding model failed', 'error'); $.notify('Adding model failed', 'error');