From 4edcf74c48b398debae4676163171d3c7aff9dbd Mon Sep 17 00:00:00 2001 From: Moe Date: Sun, 25 Sep 2022 19:46:20 -0700 Subject: [PATCH] add delete button to fileBin table --- libs/fileBin.js | 2 +- web/assets/js/bs5.fileBin.js | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/libs/fileBin.js b/libs/fileBin.js index acac006e..43603f22 100644 --- a/libs/fileBin.js +++ b/libs/fileBin.js @@ -339,7 +339,7 @@ module.exports = function(s,config,lang,app,io){ break; case'delete': response.ok = true; - await s.deleteFileBinEntry(file) + await deleteFileBinEntry(file) break; default: response.msg = user.lang.modifyVideoText1; diff --git a/web/assets/js/bs5.fileBin.js b/web/assets/js/bs5.fileBin.js index bfe37bdf..0d953650 100644 --- a/web/assets/js/bs5.fileBin.js +++ b/web/assets/js/bs5.fileBin.js @@ -98,6 +98,7 @@ $(document).ready(function(e){ ${isVideo ? `` : ``} ${permissionCheck('video_delete',file.mid) ? `` : ''} + ${permissionCheck('video_delete',file.mid) ? `` : ''} `, } @@ -126,6 +127,22 @@ $(document).ready(function(e){ await unarchiveFile(video) } } + function deleteFile(video,callback){ + return new Promise((resolve,reject) => { + var videoEndpoint = getApiPrefix(`fileBin`) + '/' + video.mid + '/' + video.name + $.getJSON(videoEndpoint + '/delete',function(data){ + notifyIfActionFailed(data) + if(callback)callback(data) + resolve(data) + }) + }) + } + async function deleteFiles(videos){ + for (let i = 0; i < videos.length; i++) { + var video = videos[i]; + await deleteFile(video) + } + } $('body') .on('click','.open-fileBin-video',function(e){ e.preventDefault() @@ -161,6 +178,30 @@ $(document).ready(function(e){ } return false; }) + .on('click','.delete-file',function(e){ + e.preventDefault() + var el = $(this).parents('[data-mid]') + var monitorId = el.attr('data-mid') + var filename = el.attr('data-name') + var file = loadedFilesInMemory[`${monitorId}${filename}`] + if(!file)return console.log(`No File`,monitorId,filename,unarchive,file); + $.confirm.create({ + title: lang["Delete"] + ' : ' + file.name, + body: `${lang.DeleteThisMsg}`, + clickOptions: { + title: ' ' + lang.Delete, + class: 'btn-danger btn-sm' + }, + clickCallback: function(){ + deleteFile(file).then(function(data){ + if(data.ok){ + drawFileBinViewElements() + } + }) + } + }); + return false; + }) addOnTabOpen('fileBinView', function () { drawMonitorListToSelector(monitorsList) drawFileBinViewElements()