2014-02-17 21:26:29 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global OC, t, FileList, FileActions */
|
2013-01-18 20:50:44 +04:00
|
|
|
|
2013-01-18 16:11:29 +04:00
|
|
|
$(document).ready(function() {
|
2014-02-17 21:26:29 +04:00
|
|
|
function removeCallback(result) {
|
|
|
|
if (result.status !== 'success') {
|
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
|
|
|
}
|
|
|
|
|
|
|
|
var files = result.data.success;
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
FileList.findFileEl(OC.basename(files[i].filename)).remove();
|
|
|
|
}
|
|
|
|
FileList.updateFileSummary();
|
|
|
|
FileList.updateEmptyContent();
|
|
|
|
enableActions();
|
|
|
|
}
|
2013-01-18 16:11:29 +04:00
|
|
|
|
|
|
|
if (typeof FileActions !== 'undefined') {
|
2013-06-17 15:30:57 +04:00
|
|
|
FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) {
|
2014-01-10 18:02:26 +04:00
|
|
|
var tr = FileList.findFileEl(filename);
|
|
|
|
var deleteAction = tr.children("td.date").children(".action.delete");
|
2013-10-09 14:01:25 +04:00
|
|
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
2013-07-26 16:54:27 +04:00
|
|
|
disableActions();
|
2014-02-17 21:26:29 +04:00
|
|
|
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
|
|
|
|
files: JSON.stringify([filename]),
|
|
|
|
dir: FileList.getCurrentDirectory()
|
|
|
|
},
|
|
|
|
removeCallback
|
2013-10-09 14:43:56 +04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
FileActions.register('all', 'Delete', OC.PERMISSION_READ, function() {
|
|
|
|
return OC.imagePath('core', 'actions/delete');
|
|
|
|
}, function(filename) {
|
|
|
|
$('.tipsy').remove();
|
2014-01-10 18:02:26 +04:00
|
|
|
var tr = FileList.findFileEl(filename);
|
|
|
|
var deleteAction = tr.children("td.date").children(".action.delete");
|
2013-10-09 14:43:56 +04:00
|
|
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
|
|
|
disableActions();
|
2014-02-17 21:26:29 +04:00
|
|
|
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
|
|
|
|
files: JSON.stringify([filename]),
|
|
|
|
dir: FileList.getCurrentDirectory()
|
|
|
|
},
|
|
|
|
removeCallback
|
2013-10-09 14:43:56 +04:00
|
|
|
);
|
|
|
|
});
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2013-10-09 14:43:56 +04: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-10-09 15:15:53 +04:00
|
|
|
procesSelection();
|
2013-10-09 14:43:56 +04:00
|
|
|
});
|
2013-01-18 20:50:44 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
$('.undelete').click('click', function(event) {
|
|
|
|
event.preventDefault();
|
2014-02-17 21:26:29 +04:00
|
|
|
var allFiles = $('#select_all').is(':checked');
|
|
|
|
var files = [];
|
|
|
|
var params = {};
|
2013-10-09 14:43:56 +04:00
|
|
|
disableActions();
|
2014-02-17 21:26:29 +04:00
|
|
|
if (allFiles) {
|
|
|
|
FileList.showMask();
|
|
|
|
params = {
|
|
|
|
allfiles: true,
|
|
|
|
dir: FileList.getCurrentDirectory()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
files = getSelectedFiles('name');
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
|
|
|
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
|
|
|
}
|
|
|
|
params = {
|
|
|
|
files: JSON.stringify(files),
|
|
|
|
dir: FileList.getCurrentDirectory()
|
|
|
|
};
|
2013-10-09 14:43:56 +04:00
|
|
|
}
|
2013-01-31 21:14:22 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
|
2014-02-17 21:26:29 +04:00
|
|
|
params,
|
|
|
|
function(result) {
|
|
|
|
if (allFiles) {
|
2013-10-09 14:01:25 +04:00
|
|
|
if (result.status !== 'success') {
|
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
|
|
|
}
|
2014-02-17 21:26:29 +04:00
|
|
|
FileList.hideMask();
|
|
|
|
// simply remove all files
|
|
|
|
FileList.update('');
|
2013-10-09 14:01:25 +04:00
|
|
|
enableActions();
|
|
|
|
}
|
2014-02-17 21:26:29 +04:00
|
|
|
else {
|
|
|
|
removeCallback(result);
|
|
|
|
}
|
|
|
|
}
|
2013-10-09 14:43:56 +04:00
|
|
|
);
|
|
|
|
});
|
2013-01-18 20:50:44 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
$('.delete').click('click', function(event) {
|
|
|
|
event.preventDefault();
|
2013-10-31 01:34:37 +04:00
|
|
|
var allFiles = $('#select_all').is(':checked');
|
|
|
|
var files = [];
|
|
|
|
var params = {};
|
|
|
|
if (allFiles) {
|
|
|
|
params = {
|
2014-02-17 21:26:29 +04:00
|
|
|
allfiles: true,
|
|
|
|
dir: FileList.getCurrentDirectory()
|
2013-10-31 01:34:37 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
2014-02-17 21:26:29 +04:00
|
|
|
files = getSelectedFiles('name');
|
2013-10-31 01:34:37 +04:00
|
|
|
params = {
|
|
|
|
files: JSON.stringify(files),
|
2014-02-17 21:26:29 +04:00
|
|
|
dir: FileList.getCurrentDirectory()
|
2013-10-31 01:34:37 +04:00
|
|
|
};
|
2014-02-17 21:26:29 +04:00
|
|
|
}
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
disableActions();
|
2013-10-31 01:34:37 +04:00
|
|
|
if (allFiles) {
|
|
|
|
FileList.showMask();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
2014-01-10 18:02:26 +04:00
|
|
|
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
|
2013-10-31 01:34:37 +04:00
|
|
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
|
|
|
}
|
2013-10-09 14:43:56 +04:00
|
|
|
}
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
|
2013-10-31 01:34:37 +04:00
|
|
|
params,
|
2013-10-09 14:43:56 +04:00
|
|
|
function(result) {
|
2013-10-31 01:34:37 +04:00
|
|
|
if (allFiles) {
|
2014-02-17 21:26:29 +04:00
|
|
|
if (result.status !== 'success') {
|
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
|
|
|
}
|
2013-10-31 01:34:37 +04:00
|
|
|
FileList.hideMask();
|
|
|
|
// simply remove all files
|
2014-02-17 21:26:29 +04:00
|
|
|
FileList.update('');
|
|
|
|
enableActions();
|
2013-10-31 01:34:37 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-02-17 21:26:29 +04:00
|
|
|
removeCallback(result);
|
2013-10-09 14:35:15 +04:00
|
|
|
}
|
|
|
|
}
|
2013-10-09 14:43:56 +04:00
|
|
|
);
|
2013-10-09 14:35:15 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
});
|
2013-01-18 20:50:44 +04:00
|
|
|
|
2013-12-02 18:27:40 +04:00
|
|
|
$('#fileList').on('click', 'td.filename input', function() {
|
|
|
|
var checkbox = $(this).parent().children('input:checkbox');
|
|
|
|
$(checkbox).parent().parent().toggleClass('selected');
|
2013-12-12 19:45:45 +04:00
|
|
|
if ($(checkbox).is(':checked')) {
|
|
|
|
var selectedCount = $('td.filename input:checkbox:checked').length;
|
|
|
|
if (selectedCount === $('td.filename input:checkbox').length) {
|
|
|
|
$('#select_all').prop('checked', true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('#select_all').prop('checked',false);
|
|
|
|
}
|
2013-12-02 18:27:40 +04:00
|
|
|
procesSelection();
|
|
|
|
});
|
|
|
|
|
2013-01-31 21:14:22 +04:00
|
|
|
$('#fileList').on('click', 'td.filename a', function(event) {
|
2013-02-28 16:32:08 +04:00
|
|
|
var mime = $(this).parent().parent().data('mime');
|
|
|
|
if (mime !== 'httpd/unix-directory') {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2013-01-31 21:14:22 +04:00
|
|
|
var filename = $(this).parent().parent().attr('data-file');
|
2014-01-10 18:02:26 +04:00
|
|
|
var tr = FileList.findFileEl(filename);
|
2013-01-31 21:14:22 +04:00
|
|
|
var renaming = tr.data('renaming');
|
|
|
|
if(!renaming && !FileList.isLoading(filename)){
|
2013-02-27 23:37:50 +04:00
|
|
|
if(mime.substr(0, 5) === 'text/'){ //no texteditor for now
|
|
|
|
return;
|
|
|
|
}
|
2013-01-31 21:14:22 +04: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-08-17 15:07:18 +04:00
|
|
|
|
|
|
|
// event handlers for breadcrumb items
|
|
|
|
$('#controls').delegate('.crumb:not(.home) a', 'click', onClickBreadcrumb);
|
2013-01-31 21:14:22 +04:00
|
|
|
});
|
2013-01-31 22:19:58 +04:00
|
|
|
|
2013-08-17 15:07:18 +04:00
|
|
|
FileActions.actions.dir = {
|
|
|
|
// only keep 'Open' action for navigation
|
|
|
|
'Open': FileActions.actions.dir.Open
|
|
|
|
};
|
2013-01-18 20:50:44 +04:00
|
|
|
});
|
2013-01-18 16:11:29 +04:00
|
|
|
|
2013-01-18 20:50:44 +04:00
|
|
|
/**
|
|
|
|
* @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={
|
2014-02-17 21:26:29 +04:00
|
|
|
name:$(element).attr('data-file'),
|
2013-01-18 20:50:44 +04:00
|
|
|
timestamp:$(element).attr('data-timestamp'),
|
2014-02-17 21:26:29 +04:00
|
|
|
type:$(element).attr('data-type')
|
2013-01-18 20:50:44 +04:00
|
|
|
};
|
|
|
|
if(property){
|
|
|
|
files.push(file[property]);
|
|
|
|
}else{
|
|
|
|
files.push(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return files;
|
2013-01-31 21:14:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function fileDownloadPath(dir, file) {
|
|
|
|
return OC.filePath('files_trashbin', '', 'download.php') + '?file='+encodeURIComponent(file);
|
|
|
|
}
|
2013-07-26 16:54:27 +04:00
|
|
|
|
|
|
|
function enableActions() {
|
|
|
|
$(".action").css("display", "inline");
|
|
|
|
$(":input:checkbox").css("display", "inline");
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableActions() {
|
|
|
|
$(".action").css("display", "none");
|
|
|
|
$(":input:checkbox").css("display", "none");
|
|
|
|
}
|
2013-08-17 15:07:18 +04:00
|
|
|
|