dropZone: $('#content'), // restrict dropZone to content div
//singleFileUploads is on by default, so the data.files array will always have length 1
add: function(e, data) {
+ if (!Files.isFileNameValid(data.files[0].name)) {
+ data.textStatus = 'invalidcharacters';
+ var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
+ fu._trigger('fail', e, data);
+ return true; //don't upload this file but go on with next in queue
+ }
if(data.files[0].type === '' && data.files[0].size == 4096)
{
if (result.status == 'success') {
var date=new Date();
FileList.addFile(name,0,date,false,hidden);
- var tr=$('tr').filterAttr('data-file',name);
+ var tr=FileList.findFileEl(name);
tr.attr('data-mime',result.data.mime);
tr.attr('data-id', result.data.id);
getMimeIcon(result.data.mime,function(path){
if (result.status == 'success') {
var date=new Date();
FileList.addDir(name,0,date,hidden);
- var tr=$('tr').filterAttr('data-file',name);
+ var tr=FileList.findFileEl(name);
tr.attr('data-id', result.data.id);
} else {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
$('#uploadprogressbar').fadeOut();
var date=new Date();
FileList.addFile(localName,size,date,false,hidden);
- var tr=$('tr').filterAttr('data-file',localName);
+ var tr = FileList.findFileEl(localName);
tr.data('mime',mime).data('id',id);
tr.attr('data-id', id);
getMimeIcon(mime,function(path){
FileActions.currentFile = parent;
var actions = FileActions.get(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var file = FileActions.getCurrentFile();
- if ($('tr[data-file="'+file+'"]').data('renaming')) {
+ if (FileList.findFileEl(file).data('renaming')) {
return;
}
filename = [filename];
}
$.each(filename, function (index, file) {
- var filename = $('tr').filterAttr('data-file', file);
+ var filename = FileList.findFileEl(file);
filename.hide();
filename.find('input[type="checkbox"]').removeAttr('checked');
filename.removeClass('selected');
var FileList={
useUndo:true,
+ /**
+ * Returns the tr element for a given file name
+ */
+ findFileEl: function(fileName){
+ // use filterAttr to avoid escaping issues
+ return $('#fileList tr').filterAttr('data-file', fileName);
+ },
update:function(fileListHtml) {
$('#fileList').empty().html(fileListHtml);
},
resetFileActionPanel();
},
remove:function(name){
- $('tr').filterAttr('data-file',name).find('td.filename').draggable('destroy');
- $('tr').filterAttr('data-file',name).remove();
+ var fileEl = FileList.findFileEl(name);
+ fileEl.find('td.filename').draggable('destroy');
+ fileEl.remove();
if($('tr[data-file]').length==0){
$('#emptyfolder').show();
}
$('#emptyfolder').hide();
},
loadingDone:function(name, id){
- var mime, tr=$('tr').filterAttr('data-file',name);
+ var mime, tr = FileList.findFileEl(name);
tr.data('loading',false);
mime=tr.data('mime');
tr.attr('data-mime',mime);
tr.find('td.filename').draggable(dragOptions);
},
isLoading:function(name){
- return $('tr').filterAttr('data-file',name).data('loading');
+ return FileList.findFileEl(name).data('loading');
},
rename:function(name){
var tr, td, input, form;
- tr=$('tr').filterAttr('data-file',name);
+ tr = FileList.findFileEl(name);
tr.data('renaming',true);
td=tr.children('td.filename');
input=$('<input class="filename"/>').val(name);
});
},
checkName:function(oldName, newName, isNewFile) {
- if (isNewFile || $('tr').filterAttr('data-file', newName).length > 0) {
+ if (isNewFile || FileList.findFileEl(newName).length > 0) {
var html;
if(isNewFile){
html = t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+'<span class="replace">'+t('files', 'replace')+'</span><span class="suggest">'+t('files', 'suggest name')+'</span> <span class="cancel">'+t('files', 'cancel')+'</span>';
},
replace:function(oldName, newName, isNewFile) {
// Finish any existing actions
- $('tr').filterAttr('data-file', oldName).hide();
- $('tr').filterAttr('data-file', newName).hide();
- var tr = $('tr').filterAttr('data-file', oldName).clone();
+ var oldFileEl = FileList.findFileEl(oldName);
+ var newFileEl = FileList.findFileEl(newName);
+ oldFileEl.hide();
+ newFileEl.hide();
+ var tr = oldFileEl.clone();
tr.attr('data-replace', 'true');
tr.attr('data-file', newName);
var td = tr.children('td.filename');
files=[files];
}
for (var i=0; i<files.length; i++) {
- var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date").children(".action.delete");
+ var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
var oldHTML = deleteAction[0].outerHTML;
var newHTML = '<img class="move2trash" data-action="Delete" title="'+t('files', 'perform delete operation')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
deleteAction[0].outerHTML = newHTML;
function(result){
if (result.status == 'success') {
$.each(files,function(index,file){
- var files = $('tr').filterAttr('data-file',file);
+ var files = FileList.findFileEl(file);
files.remove();
files.find('input[type="checkbox"]').removeAttr('checked');
files.removeClass('selected');
procesSelection();
} else {
$.each(files,function(index,file) {
- var deleteAction = $('tr').filterAttr('data-file',file).children("td.date").children(".move2trash");
+ var deleteAction = FileList.findFileEl(file).children("td.date").children('.move2trash');
deleteAction[0].outerHTML = oldHTML;
});
}
},
scrollTo:function(file) {
//scroll to and highlight preselected file
- var $scrolltorow = $('tr[data-file="'+file+'"]');
+ var $scrolltorow = FileList.findFileEl(file);
if ($scrolltorow.exists()) {
$scrolltorow.addClass('searchresult');
$(window).scrollTop($scrolltorow.position().top);
var dirName = dropTarget.data('file');
// set dir context
- data.context = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName);
+ data.context = FileList.findFileEl(dirName).filterAttr('data-type', 'dir');
// update upload counter ui
var uploadtext = data.context.find('.uploadtext');
// cleanup files, error notification has been shown by fileupload code
var tr = data.context;
if (typeof tr === 'undefined') {
- tr = $('tr').filterAttr('data-file', data.files[0].name);
+ tr = FileList.findFileEl(data.files[0].name);
}
if (tr.attr('data-type') === 'dir') {
//cleanup uploading to a dir
$('#notification').on('click', '.undo', function(){
if (FileList.deleteFiles) {
$.each(FileList.deleteFiles,function(index,file){
- $('tr').filterAttr('data-file',file).show();
+ FileList.findFileEl(file).show();
});
FileList.deleteCanceled=true;
FileList.deleteFiles=null;
FileList.deleteCanceled = false;
FileList.deleteFiles = [FileList.replaceOldName];
} else {
- $('tr').filterAttr('data-file', FileList.replaceOldName).show();
+ FileList.findFileEl(FileList.replaceOldName).show();
}
$('tr').filterAttr('data-replace', 'true').remove();
- $('tr').filterAttr('data-file', FileList.replaceNewName).show();
+ FileList.findFileEl(FileList.replaceNewName).show();
FileList.replaceCanceled = true;
FileList.replaceOldName = null;
FileList.replaceNewName = null;
});
});
$('#notification:first-child').on('click', '.suggest', function() {
- $('tr').filterAttr('data-file', $('#notification > span').attr('data-oldName')).show();
+ var file = $('#notification > span').attr('data-oldName');
+ FileList.findFileEl(file).show();
OC.Notification.hide();
});
$('#notification:first-child').on('click', '.cancel', function() {
$.each(uploadingFiles,function(index,file) {
if(typeof file['abort'] === 'function') {
file.abort();
- var filename = $('tr').filterAttr('data-file',index);
+ var filename = FileList.findFileEl(index);
filename.hide();
filename.find('input[type="checkbox"]').removeAttr('checked');
filename.removeClass('selected');
procesSelection();
} else {
var filename=$(this).parent().parent().attr('data-file');
- var tr=$('tr').filterAttr('data-file',filename);
+ var tr = FileList.findFileEl(filename);
var renaming=tr.data('renaming');
if(!renaming && !FileList.isLoading(filename)){
FileActions.currentFile = $(this).parent();
if (result.status == 'success') {
var date=new Date();
FileList.addFile(name,0,date,false,hidden);
- var tr=$('tr').filterAttr('data-file',name);
+ var tr=FileList.findFileEl(name);
tr.attr('data-mime','text/plain');
tr.attr('data-id', result.data.id);
getMimeIcon('text/plain',function(path){
if (result.status == 'success') {
var date=new Date();
FileList.addDir(name,0,date,hidden);
- var tr=$('tr').filterAttr('data-file',name);
+ var tr=FileList.findFileEl(name);
tr.attr('data-id', result.data.id);
} else {
OC.dialogs.alert(result.data.message, 'Error');
$('#uploadprogressbar').fadeOut();
var date=new Date();
FileList.addFile(localName,size,date,false,hidden);
- var tr=$('tr').filterAttr('data-file',localName);
+ var tr=FileList.findFileEl(localName);
tr.data('mime',mime).data('id',id);
tr.attr('data-id', id);
getMimeIcon(mime,function(path){
if (result) {
if (result.status === 'success') {
//recalculate folder size
- var oldSize = $('#fileList tr').filterAttr('data-file',target).data('size');
- var newSize = oldSize + $('#fileList tr').filterAttr('data-file',file).data('size');
- $('#fileList tr').filterAttr('data-file',target).data('size', newSize);
- $('#fileList tr').filterAttr('data-file',target).find('td.filesize').text(humanFileSize(newSize));
+ var oldFile = FileList.findFileEl(target);
+ var newFile = FileList.findFileEl(file);
+ var oldSize = oldFile.data('size');
+ var newSize = oldSize + newFile.data('size');
+ oldFile.data('size', newSize);
+ oldFile.find('td.filesize').text(humanFileSize(newSize));
FileList.remove(file);
procesSelection();
getMimeIcon.cache={};
function getUniqueName(name){
- if($('tr').filterAttr('data-file',name).length>0){
+ if (FileList.findFileEl(name).exists()) {
var parts=name.split('.');
var extension = "";
if (parts.length > 1) {
}
}
FileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function(filename) {
- var tr = $('tr').filterAttr('data-file', filename)
+ var tr = FileList.findFileEl(filename);
if (tr.length > 0) {
window.location = $(tr).find('a.name').attr('href');
}
});
FileActions.register('file', 'Download', OC.PERMISSION_READ, '', function(filename) {
- var tr = $('tr').filterAttr('data-file', filename)
+ var tr = FileList.findFileEl(filename);
if (tr.length > 0) {
window.location = $(tr).find('a.name').attr('href');
}
});
FileActions.register('dir', 'Download', OC.PERMISSION_READ, '', function(filename) {
- var tr = $('tr').filterAttr('data-file', filename)
+ var tr = FileList.findFileEl(filename);
if (tr.length > 0) {
window.location = $(tr).find('a.name').attr('href')+'&download';
}
} else {
var item = $('#dir').val() + '/' + filename;
}
- var tr = $('tr').filterAttr('data-file', filename);
+ var tr = FileList.findFileEl(filename);
if ($(tr).data('type') == 'dir') {
var itemType = 'folder';
} else {
if (typeof FileActions !== 'undefined') {
FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/undelete.png'), function(filename) {
- var tr=$('tr').filterAttr('data-file', filename);
+ var tr = FileList.findFileEl(filename);
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loader.gif') +'"></a>';
- var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date");
+ var undeleteAction = tr.children("td.date");
var files = tr.attr('data-file');
undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner;
$.post(OC.filePath('files_trashbin','ajax','undelete.php'),
}, function (filename) {
$('.tipsy').remove();
- var tr=$('tr').filterAttr('data-file', filename);
- var deleteAction = $('tr').filterAttr('data-file',filename).children("td.date").children(".action.delete");
+ var tr = FileList.findFileEl(filename);
+ var deleteAction = tr.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');
var dirlisting=getSelectedFiles('dirlisting')[0];
for (var i=0; i<files.length; i++) {
- var undeleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
+ var undeleteAction = $FileList.findFileEl(files[i]).children("td.date");
undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner;
}
var dirlisting=getSelectedFiles('dirlisting')[0];
for (var i=0; i<files.length; i++) {
- var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
+ var deleteAction = FileList.findFileEl(files[i]).children("td.date");
deleteAction[0].innerHTML = deleteAction[0].innerHTML+spinner;
}
event.preventDefault();
}
var filename = $(this).parent().parent().attr('data-file');
- var tr = $('tr').filterAttr('data-file',filename);
+ var tr = FileList.findFileEl(filename);
var renaming = tr.data('renaming');
if(!renaming && !FileList.isLoading(filename)){
if(mime.substr(0, 5) === 'text/'){ //no texteditor for now
data: { source: files },
async: false,
success: function( versions ) {
-
+ var htmlEl, fileEl;
// first decide which kind of dialog we need
if (versions) {
- var html = '<div id="dropdown" class="drop drop-versions" data-file="'+escapeHTML(files)+'">';
+ var html = '<div id="dropdown" class="drop drop-versions">';
html += '<div id="private">';
html += '<select data-placeholder="Saved versions" id="found_versions" class="chzen-select" style="width:16em;">';
html += '<option value=""></option>';
html += '<input id="link" style="display:none; width:90%;" />';
} else {
- var html = '<div id="dropdown" class="drop drop-versions" data-file="'+escapeHTML(files)+'">';
+ var html = '<div id="dropdown" class="drop drop-versions">';
html += '<div style="text-align:center;">No other versions available</div></div>';
}
if (filename) {
- $('tr').filterAttr('data-file',filename).addClass('mouseOver');
- $(html).appendTo($('tr').filterAttr('data-file',filename).find('td.filename'));
+ fileEl = FileList.findFileEl(filename);
+ fileEl.addClass('mouseOver');
+ htmlEl = $(html);
+ htmlEl.appendTo(fileEl.find('td.filename'));
} else {
- $(html).appendTo($('thead .share'));
+ htmlEl.appendTo($('thead .share'));
}
+ htmlEl.attr('data-file', files);
$("#makelink").click(function() {
goToVersionPage(historyUrl);
version.appendTo('#found_versions');
}
- $('tr').filterAttr('data-file',filename).addClass('mouseOver');
$('#dropdown').show('blind');
-
-
}
$(this).click(