diff options
Diffstat (limited to 'apps/files_trashbin/js/trash.js')
-rw-r--r-- | apps/files_trashbin/js/trash.js | 272 |
1 files changed, 124 insertions, 148 deletions
diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index d73eadb6011..4e83afcdb06 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -3,15 +3,39 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) { - var tr=$('tr').filterAttr('data-file', filename); - var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>'; - var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date"); - var files = tr.attr('data-file'); - undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner; + var tr = $('tr').filterAttr('data-file', filename); + var deleteAction = $('tr').filterAttr('data-file', filename).children("td.date").children(".action.delete"); + deleteAction.removeClass('delete-icon').addClass('progress-icon'); disableActions(); - $.post(OC.filePath('files_trashbin','ajax','undelete.php'), - {files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') }, - function(result){ + $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), + {files: JSON.stringify([filename]), dirlisting: tr.attr('data-dirlisting')}, + function(result) { + for (var i = 0; i < result.data.success.length; i++) { + var row = document.getElementById(result.data.success[i].filename); + row.parentNode.removeChild(row); + } + if (result.status !== 'success') { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } + enableActions(); + FileList.updateFileSummary(); + } + ); + + }); + }; + + FileActions.register('all', 'Delete', OC.PERMISSION_READ, function() { + return OC.imagePath('core', 'actions/delete'); + }, function(filename) { + $('.tipsy').remove(); + var tr = $('tr').filterAttr('data-file', filename); + var deleteAction = $('tr').filterAttr('data-file', filename).children("td.date").children(".action.delete"); + deleteAction.removeClass('delete-icon').addClass('progress-icon'); + disableActions(); + $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), + {files: JSON.stringify([filename]), dirlisting: tr.attr('data-dirlisting')}, + function(result) { for (var i = 0; i < result.data.success.length; i++) { var row = document.getElementById(result.data.success[i].filename); row.parentNode.removeChild(row); @@ -21,26 +45,74 @@ $(document).ready(function() { } enableActions(); FileList.updateFileSummary(); - }); + } + ); - }); - }; + }); - FileActions.register('all', 'Delete', OC.PERMISSION_READ, function () { - return OC.imagePath('core', 'actions/delete'); - }, function (filename) { - $('.tipsy').remove(); + // Sets the select_all checkbox behaviour : + $('#select_all').click(function() { + if ($(this).attr('checked')) { + // Check all + $('td.filename input:checkbox').attr('checked', true); + $('td.filename input:checkbox').parent().parent().addClass('selected'); + } else { + // Uncheck all + $('td.filename input:checkbox').attr('checked', false); + $('td.filename input:checkbox').parent().parent().removeClass('selected'); + } + procesSelection(); + }); - var tr=$('tr').filterAttr('data-file', filename); - var deleteAction = $('tr').filterAttr('data-file',filename).children("td.date").children(".action.delete"); - var oldHTML = deleteAction[0].outerHTML; - var newHTML = '<img class="move2trash" data-action="Delete" title="'+t('files', 'delete file permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>'; - var files = tr.attr('data-file'); - deleteAction[0].outerHTML = newHTML; - disableActions(); - $.post(OC.filePath('files_trashbin','ajax','delete.php'), - {files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') }, - function(result){ + $('#fileList').on('click', 'td.filename a', function(event) { + if (event.shiftKey) { + event.preventDefault(); + var last = $(lastChecked).parent().parent().prevAll().length; + var first = $(this).parent().parent().prevAll().length; + var start = Math.min(first, last); + var end = Math.max(first, last); + var rows = $(this).parent().parent().parent().children('tr'); + for (var i = start; i < end; i++) { + $(rows).each(function(index) { + if (index == i) { + var checkbox = $(this).children().children('input:checkbox'); + $(checkbox).attr('checked', 'checked'); + $(checkbox).parent().parent().addClass('selected'); + } + }); + } + } + var checkbox = $(this).parent().children('input:checkbox'); + lastChecked = checkbox; + if ($(checkbox).attr('checked')) { + $(checkbox).removeAttr('checked'); + $(checkbox).parent().parent().removeClass('selected'); + $('#select_all').removeAttr('checked'); + } else { + $(checkbox).attr('checked', 'checked'); + $(checkbox).parent().parent().toggleClass('selected'); + var selectedCount = $('td.filename input:checkbox:checked').length; + if (selectedCount == $('td.filename input:checkbox').length) { + $('#select_all').attr('checked', 'checked'); + } + } + procesSelection(); + }); + + $('.undelete').click('click', function(event) { + event.preventDefault(); + var files = getSelectedFiles('file'); + var fileslist = JSON.stringify(files); + var dirlisting = getSelectedFiles('dirlisting')[0]; + disableActions(); + for (var i = 0; i < files.length; i++) { + var deleteAction = $('tr').filterAttr('data-file', files[i]).children("td.date").children(".action.delete"); + deleteAction.removeClass('delete-icon').addClass('progress-icon'); + } + + $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), + {files: fileslist, dirlisting: dirlisting}, + function(result) { for (var i = 0; i < result.data.success.length; i++) { var row = document.getElementById(result.data.success[i].filename); row.parentNode.removeChild(row); @@ -50,106 +122,38 @@ $(document).ready(function() { } enableActions(); FileList.updateFileSummary(); - }); - - }); - - // Sets the select_all checkbox behaviour : - $('#select_all').click(function() { - if($(this).attr('checked')){ - // Check all - $('td.filename input:checkbox').attr('checked', true); - $('td.filename input:checkbox').parent().parent().addClass('selected'); - }else{ - // Uncheck all - $('td.filename input:checkbox').attr('checked', false); - $('td.filename input:checkbox').parent().parent().removeClass('selected'); - } - processSelection(); - }); - - $('td.filename input:checkbox').live('change',function(event) { - if (event.shiftKey) { - var last = $(lastChecked).parent().parent().prevAll().length; - var first = $(this).parent().parent().prevAll().length; - var start = Math.min(first, last); - var end = Math.max(first, last); - var rows = $(this).parent().parent().parent().children('tr'); - for (var i = start; i < end; i++) { - $(rows).each(function(index) { - if (index === i) { - var checkbox = $(this).children().children('input:checkbox'); - $(checkbox).attr('checked', 'checked'); - $(checkbox).parent().parent().addClass('selected'); - } - }); } - } - var selectedCount=$('td.filename input:checkbox:checked').length; - $(this).parent().parent().toggleClass('selected'); - if(!$(this).attr('checked')){ - $('#select_all').attr('checked',false); - }else{ - if(selectedCount==$('td.filename input:checkbox').length){ - $('#select_all').attr('checked',true); - } - } - processSelection(); - }); + ); + }); - $('.undelete').click('click',function(event) { - event.preventDefault(); - var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>'; - var files=getSelectedFiles('file'); - var fileslist = JSON.stringify(files); - var dirlisting=getSelectedFiles('dirlisting')[0]; - disableActions(); - for (var i=0; i<files.length; i++) { - var undeleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date"); - undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner; - } + $('.delete').click('click', function(event) { + event.preventDefault(); + var files = getSelectedFiles('file'); + var fileslist = JSON.stringify(files); + var dirlisting = getSelectedFiles('dirlisting')[0]; - $.post(OC.filePath('files_trashbin','ajax','undelete.php'), - {files:fileslist, dirlisting:dirlisting}, - function(result){ - for (var i = 0; i < result.data.success.length; i++) { - var row = document.getElementById(result.data.success[i].filename); - row.parentNode.removeChild(row); - } - if (result.status !== 'success') { - OC.dialogs.alert(result.data.message, t('core', 'Error')); - } - enableActions(); - }); - }); - - $('.delete').click('click',function(event) { - event.preventDefault(); - console.log("delete selected"); - var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'Delete permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>'; - var files=getSelectedFiles('file'); - var fileslist = JSON.stringify(files); - var dirlisting=getSelectedFiles('dirlisting')[0]; + disableActions(); + for (var i = 0; i < files.length; i++) { + var deleteAction = $('tr').filterAttr('data-file', files[i]).children("td.date").children(".action.delete"); + deleteAction.removeClass('delete-icon').addClass('progress-icon'); + } - disableActions(); - for (var i=0; i<files.length; i++) { - var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date"); - deleteAction[0].innerHTML = deleteAction[0].innerHTML+spinner; - } + $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), + {files: fileslist, dirlisting: dirlisting}, + function(result) { + for (var i = 0; i < result.data.success.length; i++) { + var row = document.getElementById(result.data.success[i].filename); + row.parentNode.removeChild(row); + } + if (result.status !== 'success') { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } + enableActions(); + FileList.updateFileSummary(); + } + ); - $.post(OC.filePath('files_trashbin','ajax','delete.php'), - {files:fileslist, dirlisting:dirlisting}, - function(result){ - for (var i = 0; i < result.data.success.length; i++) { - var row = document.getElementById(result.data.success[i].filename); - row.parentNode.removeChild(row); - } - if (result.status !== 'success') { - OC.dialogs.alert(result.data.message, t('core', 'Error')); - } - enableActions(); - }); - }); + }); $('#fileList').on('click', 'td.filename a', function(event) { var mime = $(this).parent().parent().data('mime'); @@ -182,34 +186,6 @@ $(document).ready(function() { }; }); -function processSelection(){ - var selected=getSelectedFiles(); - var selectedFiles=selected.filter(function(el){return el.type === 'file'}); - var selectedFolders=selected.filter(function(el){return el.type === 'dir'}); - if(selectedFiles.length === 0 && selectedFolders.length === 0) { - $('#headerName>span.name').text(t('files','Name')); - $('#modified').text(t('files','Deleted')); - $('table').removeClass('multiselect'); - $('.selectedActions').hide(); - } - else { - $('.selectedActions').show(); - var selection=''; - if(selectedFolders.length>0){ - selection += n('files', '%n folder', '%n folders', selectedFolders.length); - if(selectedFiles.length>0){ - selection+=' & '; - } - } - if(selectedFiles.length>0){ - selection += n('files', '%n file', '%n files', selectedFiles.length); - } - $('#headerName>span.name').text(selection); - $('#modified').text(''); - $('table').addClass('multiselect'); - } -} - /** * @brief get a list of selected files * @param string property (option) the property of the file requested |