Skip to content

Commit

Permalink
fix clipboard text stale state on filename change
Browse files Browse the repository at this point in the history
  • Loading branch information
yurii-github committed Feb 19, 2021
1 parent c6a4b27 commit ee6eaba
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/views/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
resize: false,
sortable: false,
editable: false,
formatter: function (cellvalue, options, rowObject) {
return '<span title="click to copy filename to clipboard" class="book-filename ui-icon ui-icon-document" data-filename="{{ copy_book_dir() | raw }}' + cellvalue + '"></span>'
formatter: function (cellValue, options, rowObject) {
return '<span title="click to copy filename to clipboard" class="book-filename-clipboard ui-icon ui-icon-document" data-filename="{{ copy_book_dir() | raw }}' + cellValue + '"></span>'
}
},
{
Expand All @@ -182,7 +182,6 @@
editable: true,
hidden: false
},
caption: '',
rowNum: parseInt(getCookie('rowNum', 10)),
page: parseInt(getCookie('page', 1)),
rownumbers: true,
Expand All @@ -194,9 +193,7 @@
viewrecords: true,
sortorder: "desc",
sortable: true,
cellEdit: false,
cellSubmit: 'remote',
cellurl: 'api/book/manage', subGrid: true,
subGrid: true,
ajaxRowOptions: {
beforeSend: function (jqXHR, settings) {
jqXHR.setRequestHeader('Accept', "application/json")
Expand All @@ -206,9 +203,8 @@
serializeRowData: function (postData) {
return JSON.stringify(postData);
},
// TODO: better error message and unified
errorTextFormat: function (response) {
return response.responseText;
return response.responseText; // TODO: better error message and unified
},
subGridRowExpanded: function (subgrid_id, row_id) {
// If we want to pass additional parameters to the url we can use
Expand Down Expand Up @@ -301,11 +297,6 @@
filterCategories = 0 // avoid another append
}
$(".book-filename").on('click', function (e) {
let clipboardText = `evince "${$(this).attr('data-filename')}"`
window.prompt("Copy to clipboard: Ctrl+C, Enter", clipboardText)
})
$(".book-favorite").raty(ratyOptions) //rating init
$(".book-cover-link").fancybox({
Expand All @@ -324,20 +315,21 @@
var book_guid = $(this.element[0]).attr('data-guid') //1st element in visible group, we show 1 by 1
coverUpload.init(book_guid)
},
afterClose: function (e) {
}
afterClose: function (e) {}
})
},
ondblClickRow: function (rowid, ri, ci) {
var row_obj = $book_list.jqGrid('getInd', rowid, true) // row_obj is just piece of html - TR
lastFavorite = $(row_obj).find('div.book-favorite').attr('data-score')
lastRead = $(row_obj).find('div.book-read-yes').attr('class') !== undefined ? 'yes' : 'no'
//.jqGrid('editRow', rowid, keys, oneditfunc, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);
// http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing
// http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
$book_list.jqGrid('editRow', rowid, {
keys: true,
aftersavefunc: function (id, response, options) {
$('.book-favorite[data-guid=\"' + id + '\"]').raty(ratyOptions)//SOLUTION:http://stackoverflow.com/a/6246687/2032121
//SOLUTION:http://stackoverflow.com/a/6246687/2032121
$('.book-favorite[data-guid=\"' + id + '\"]').raty(ratyOptions)
$book_list.jqGrid('setCell', rowid, 'filename', response.responseJSON.filename)
},
afterrestorefunc: function (id, response, options) {
$('.book-favorite[data-guid="' + id + '"]').raty(ratyOptions)
Expand All @@ -355,7 +347,6 @@
}
})
.jqGrid('navGrid', '#book-pager', {
// navigation options
edit: false,
add: false,
del: false,
Expand All @@ -366,6 +357,15 @@
stringResult: true,
searchOnEnter: false
})
//
// Helpers
//
// - shows modal to copy book filepath into clipboard
$('body').delegate('.book-filename-clipboard', 'click', function (e) {
let clipboardText = `evince "${$(this).attr('data-filename')}"` // TODO: make configurable
window.prompt("Copy to clipboard: Ctrl+C, Enter", clipboardText)
})
</script>


Expand Down

0 comments on commit ee6eaba

Please sign in to comment.