'
));
row.on('click', '.bookmark-cancel', function() {
row.remove();
});
row.on('click', '.bookmark-save', function() {
var data = Object.fromEntries(
$.map(inputs, function(input, name){
input.disable(true);
// double wrapped because jQuery.map() flattens the result
return [[name, input.getValue()]];
})
);
$.ajax(document.location.href, {
data: JSON.stringify([data]),
contentType: 'application/json',
method: 'POST'
}).fail(function(data) {
// adding failed, reenable inputs
$.map(inputs, function(input, name) { input.disable(false); });
}).done(function(data) {
if (data.length && data.length === 1 && 'bookmark_id' in data[0]) {
row.attr('data-id', data[0]['bookmark_id']);
var tds = row.find('td');
Object.values(inputs).forEach(function(input, index) {
var td = $(tds[index]);
td.data('value', input.getValue());
td.html(input.getHtml());
});
}
// remove inputs
var $cell = row.find('td').last();
var $group = $cell.find('.btn-group');
if ($group.length) {
$group.remove;
$cell.html('
delete
');
}
});
});
$table.append(row);
row[0].scrollIntoView();
});
var $importModal = $('#importModal').modal({show: false});
$(this).find('.bookmark-import').on('click', function() {
var storage = new BookmarkLocalStorage();
var bookmarks = storage.getBookmarks();
if (bookmarks.length) {
var modes = $table.data('modes');
var $list = $('
');
$list.append(bookmarks.map(function(b) {
var row = $(
'
' +
'
' +
'
' + b.name + '
' +
'
' + renderFrequency(b.frequency) + '
' +
'
' + renderModulation(b.modulation, modes) + '
' +
// '
' + renderModulation(b.underlying, modes) + '
' +
'
'
);
row.data('bookmark', b);
return row;
}));
$importModal.find('.bookmark-list').html($list);
} else {
$importModal.find('.bookmark-list').html('No personal bookmarks found in this browser');
}
$importModal.modal('show');
});
$importModal.on('click', '.confirm', function() {
var $list = $importModal.find('.bookmark-list table');
if ($list.length) {
var selected = $list.find('tr').filter(function(){
return $(this).find('.select').is(':checked');
}).map(function(){
return $(this).data('bookmark');
}).toArray();
if (selected.length) {
$.ajax(document.location.href, {
data: JSON.stringify(selected),
contentType: 'application/json',
method: 'POST'
}).fail(function(data) {
// import failed
$table.find('.emptytext').remove();
}).done(function(data) {
$table.find('.emptytext').remove();
var modes = $table.data('modes');
if (data.length && data.length == selected.length) {
$table.append(data.map(function(obj, index) {
var b = selected[index];
// provide reasonable defaults for missing fields
if (!('underlying' in b)) b.underlying = '';
if (!('description' in b)) b.description = '';
if (!('scannable' in b)) {
var modesToScan = ['lsb', 'usb', 'cw', 'am', 'sam', 'nfm'];
b.scannable = modesToScan.indexOf(b.modulation) >= 0;
}
return $(
'