2013-01-18 16:50:44 +00:00
|
|
|
|
2013-01-18 12:11:29 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
if (typeof FileActions !== 'undefined') {
|
2013-06-17 11:30:57 +00:00
|
|
|
FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) {
|
2013-01-18 12:11:29 +00:00
|
|
|
var tr=$('tr').filterAttr('data-file', filename);
|
2013-06-17 10:35:25 +00:00
|
|
|
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
|
2013-01-30 14:35:24 +00:00
|
|
|
var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date");
|
2013-02-20 15:33:45 +00:00
|
|
|
var files = tr.attr('data-file');
|
2013-01-30 14:35:24 +00:00
|
|
|
undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner;
|
2013-07-26 12:54:27 +00:00
|
|
|
disableActions();
|
2013-01-18 12:11:29 +00:00
|
|
|
$.post(OC.filePath('files_trashbin','ajax','undelete.php'),
|
2013-02-20 15:33:45 +00:00
|
|
|
{files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') },
|
2013-01-18 12:11:29 +00:00
|
|
|
function(result){
|
2013-01-18 16:50:44 +00:00
|
|
|
for (var i = 0; i < result.data.success.length; i++) {
|
2013-01-22 11:13:50 +00:00
|
|
|
var row = document.getElementById(result.data.success[i].filename);
|
2013-01-18 13:09:22 +00:00
|
|
|
row.parentNode.removeChild(row);
|
2013-01-18 16:50:44 +00:00
|
|
|
}
|
2013-04-18 16:28:03 +00:00
|
|
|
if (result.status !== 'success') {
|
2013-04-06 14:52:55 +00:00
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
2013-01-18 12:11:29 +00:00
|
|
|
}
|
2013-07-26 12:54:27 +00:00
|
|
|
enableActions();
|
2013-07-03 17:50:03 +00:00
|
|
|
FileList.updateFileSummary();
|
2013-01-18 12:11:29 +00:00
|
|
|
});
|
2013-01-31 17:14:22 +00:00
|
|
|
|
2013-01-18 12:11:29 +00:00
|
|
|
});
|
|
|
|
};
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-02-06 15:23:22 +00:00
|
|
|
FileActions.register('all', 'Delete', OC.PERMISSION_READ, function () {
|
|
|
|
return OC.imagePath('core', 'actions/delete');
|
|
|
|
}, function (filename) {
|
|
|
|
$('.tipsy').remove();
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-02-06 15:23:22 +00:00
|
|
|
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>';
|
2013-02-20 15:33:45 +00:00
|
|
|
var files = tr.attr('data-file');
|
2013-02-06 15:23:22 +00:00
|
|
|
deleteAction[0].outerHTML = newHTML;
|
2013-07-26 12:54:27 +00:00
|
|
|
disableActions();
|
2013-02-06 15:23:22 +00:00
|
|
|
$.post(OC.filePath('files_trashbin','ajax','delete.php'),
|
2013-02-20 15:33:45 +00:00
|
|
|
{files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') },
|
2013-02-06 15:23:22 +00:00
|
|
|
function(result){
|
2013-02-19 11:38:00 +00:00
|
|
|
for (var i = 0; i < result.data.success.length; i++) {
|
|
|
|
var row = document.getElementById(result.data.success[i].filename);
|
2013-02-06 15:23:22 +00:00
|
|
|
row.parentNode.removeChild(row);
|
2013-02-19 11:38:00 +00:00
|
|
|
}
|
2013-04-18 16:28:03 +00:00
|
|
|
if (result.status !== 'success') {
|
2013-04-06 14:52:55 +00:00
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
2013-02-06 15:23:22 +00:00
|
|
|
}
|
2013-07-26 12:54:27 +00:00
|
|
|
enableActions();
|
2013-07-03 17:50:03 +00:00
|
|
|
FileList.updateFileSummary();
|
2013-02-06 15:23:22 +00:00
|
|
|
});
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-02-06 15:23:22 +00:00
|
|
|
});
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-01-18 16:50:44 +00:00
|
|
|
// 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');
|
|
|
|
}
|
2013-01-30 12:01:53 +00:00
|
|
|
processSelection();
|
2013-01-18 16:50:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('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) {
|
2013-04-18 16:28:03 +00:00
|
|
|
if (index === i) {
|
2013-01-18 16:50:44 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-01-30 12:01:53 +00:00
|
|
|
processSelection();
|
2013-01-31 17:14:22 +00:00
|
|
|
});
|
|
|
|
|
2013-01-18 16:50:44 +00:00
|
|
|
$('.undelete').click('click',function(event) {
|
2013-05-27 14:37:43 +00:00
|
|
|
event.preventDefault();
|
2013-06-17 10:35:25 +00:00
|
|
|
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
|
2013-01-30 14:35:24 +00:00
|
|
|
var files=getSelectedFiles('file');
|
2013-02-20 15:33:45 +00:00
|
|
|
var fileslist = JSON.stringify(files);
|
2013-01-22 11:00:04 +00:00
|
|
|
var dirlisting=getSelectedFiles('dirlisting')[0];
|
2013-07-26 12:54:27 +00:00
|
|
|
disableActions();
|
2013-02-20 20:57:50 +00:00
|
|
|
for (var i=0; i<files.length; i++) {
|
2013-01-30 14:35:24 +00:00
|
|
|
var undeleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
|
|
|
|
undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner;
|
|
|
|
}
|
2013-01-31 17:14:22 +00:00
|
|
|
|
2013-01-18 16:50:44 +00:00
|
|
|
$.post(OC.filePath('files_trashbin','ajax','undelete.php'),
|
2013-01-22 11:00:04 +00:00
|
|
|
{files:fileslist, dirlisting:dirlisting},
|
2013-01-18 16:50:44 +00:00
|
|
|
function(result){
|
|
|
|
for (var i = 0; i < result.data.success.length; i++) {
|
2013-01-22 11:13:50 +00:00
|
|
|
var row = document.getElementById(result.data.success[i].filename);
|
2013-01-18 16:50:44 +00:00
|
|
|
row.parentNode.removeChild(row);
|
|
|
|
}
|
2013-04-18 16:28:03 +00:00
|
|
|
if (result.status !== 'success') {
|
2013-04-06 14:52:55 +00:00
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
2013-01-18 16:50:44 +00:00
|
|
|
}
|
2013-07-26 12:54:27 +00:00
|
|
|
enableActions();
|
2013-01-31 17:14:22 +00:00
|
|
|
});
|
2013-01-18 16:50:44 +00:00
|
|
|
});
|
|
|
|
|
2013-02-19 09:24:21 +00:00
|
|
|
$('.delete').click('click',function(event) {
|
2013-05-27 13:24:37 +00:00
|
|
|
event.preventDefault();
|
2013-02-19 09:24:21 +00:00
|
|
|
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');
|
2013-02-20 15:33:45 +00:00
|
|
|
var fileslist = JSON.stringify(files);
|
2013-02-19 09:24:21 +00:00
|
|
|
var dirlisting=getSelectedFiles('dirlisting')[0];
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-07-26 12:54:27 +00:00
|
|
|
disableActions();
|
2013-02-20 21:32:44 +00:00
|
|
|
for (var i=0; i<files.length; i++) {
|
2013-02-19 09:24:21 +00:00
|
|
|
var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
|
|
|
|
deleteAction[0].innerHTML = deleteAction[0].innerHTML+spinner;
|
|
|
|
}
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-02-19 09:24:21 +00:00
|
|
|
$.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);
|
|
|
|
}
|
2013-04-18 16:28:03 +00:00
|
|
|
if (result.status !== 'success') {
|
2013-04-06 14:52:55 +00:00
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
2013-02-19 09:24:21 +00:00
|
|
|
}
|
2013-07-26 12:54:27 +00:00
|
|
|
enableActions();
|
2013-02-19 09:24:21 +00:00
|
|
|
});
|
|
|
|
});
|
2013-01-18 16:50:44 +00:00
|
|
|
|
2013-01-31 17:14:22 +00:00
|
|
|
$('#fileList').on('click', 'td.filename a', function(event) {
|
2013-02-28 12:32:08 +00:00
|
|
|
var mime = $(this).parent().parent().data('mime');
|
|
|
|
if (mime !== 'httpd/unix-directory') {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2013-01-31 17:14:22 +00:00
|
|
|
var filename = $(this).parent().parent().attr('data-file');
|
|
|
|
var tr = $('tr').filterAttr('data-file',filename);
|
|
|
|
var renaming = tr.data('renaming');
|
|
|
|
if(!renaming && !FileList.isLoading(filename)){
|
2013-02-27 19:37:50 +00:00
|
|
|
if(mime.substr(0, 5) === 'text/'){ //no texteditor for now
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 17:14:22 +00:00
|
|
|
var type = $(this).parent().parent().data('type');
|
|
|
|
var permissions = $(this).parent().parent().data('permissions');
|
|
|
|
var action = FileActions.getDefault(mime, type, permissions);
|
|
|
|
if(action){
|
|
|
|
event.preventDefault();
|
|
|
|
action(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-01-31 18:19:58 +00:00
|
|
|
|
|
|
|
FileActions.actions.dir = {};
|
2013-01-18 16:50:44 +00:00
|
|
|
});
|
2013-01-18 12:11:29 +00:00
|
|
|
|
2013-01-30 12:01:53 +00:00
|
|
|
function processSelection(){
|
2013-01-18 16:50:44 +00:00
|
|
|
var selected=getSelectedFiles();
|
2013-04-18 16:28:03 +00:00
|
|
|
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) {
|
2013-01-18 16:50:44 +00:00
|
|
|
$('#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){
|
2013-08-09 18:37:18 +00:00
|
|
|
selection += n('files', '%n folder', '%n folders', selectedFolders.length);
|
2013-01-18 16:50:44 +00:00
|
|
|
if(selectedFiles.length>0){
|
|
|
|
selection+=' & ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(selectedFiles.length>0){
|
2013-08-09 18:37:18 +00:00
|
|
|
selection += n('files', '%n file', '%n files', selectedFiles.length);
|
2013-01-18 16:50:44 +00:00
|
|
|
}
|
|
|
|
$('#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
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* possible values for property: name, mime, size and type
|
|
|
|
* if property is set, an array with that property for each file is returnd
|
|
|
|
* if it's ommited an array of objects with all properties is returned
|
|
|
|
*/
|
|
|
|
function getSelectedFiles(property){
|
|
|
|
var elements=$('td.filename input:checkbox:checked').parent().parent();
|
|
|
|
var files=[];
|
|
|
|
elements.each(function(i,element){
|
|
|
|
var file={
|
|
|
|
name:$(element).attr('data-filename'),
|
|
|
|
file:$(element).attr('data-file'),
|
|
|
|
timestamp:$(element).attr('data-timestamp'),
|
2013-01-22 11:00:04 +00:00
|
|
|
type:$(element).attr('data-type'),
|
|
|
|
dirlisting:$(element).attr('data-dirlisting')
|
2013-01-18 16:50:44 +00:00
|
|
|
};
|
|
|
|
if(property){
|
|
|
|
files.push(file[property]);
|
|
|
|
}else{
|
|
|
|
files.push(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return files;
|
2013-01-31 17:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fileDownloadPath(dir, file) {
|
|
|
|
return OC.filePath('files_trashbin', '', 'download.php') + '?file='+encodeURIComponent(file);
|
|
|
|
}
|
2013-07-26 12:54:27 +00:00
|
|
|
|
|
|
|
function enableActions() {
|
|
|
|
$(".action").css("display", "inline");
|
|
|
|
$(":input:checkbox").css("display", "inline");
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableActions() {
|
|
|
|
$(".action").css("display", "none");
|
|
|
|
$(":input:checkbox").css("display", "none");
|
|
|
|
}
|