Blame view
sources/apps/files/js/filelist.js
33.5 KB
|
03e52840d
|
1 2 |
var FileList={
useUndo:true,
|
|
31b7f2792
|
3 4 5 6 7 8 |
postProcessList: function() {
$('#fileList tr').each(function() {
//little hack to set unescape filenames in attribute
$(this).attr('data-file',decodeURIComponent($(this).attr('data-file')));
});
},
|
|
a293d369c
|
9 10 11 12 13 14 15 |
/**
* 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);
},
|
|
03e52840d
|
16 |
update:function(fileListHtml) {
|
|
31b7f2792
|
17 18 19 20 21 22 23 24 25 26 27 28 29 |
var $fileList = $('#fileList');
$fileList.empty().html(fileListHtml);
FileList.updateEmptyContent();
$fileList.find('tr').each(function () {
FileActions.display($(this).children('td.filename'));
});
$fileList.trigger(jQuery.Event("fileActionsReady"));
FileList.postProcessList();
// "Files" might not be loaded in extending apps
if (window.Files) {
Files.setupDragAndDrop();
}
FileList.updateFileSummary();
|
|
a293d369c
|
30 31 |
procesSelection(); |
|
31b7f2792
|
32 |
$fileList.trigger(jQuery.Event("updated"));
|
|
03e52840d
|
33 |
}, |
|
31b7f2792
|
34 |
createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions) {
|
|
03e52840d
|
35 36 37 38 39 40 41 42 43 44 45 |
var td, simpleSize, basename, extension;
//containing tr
var tr = $('<tr></tr>').attr({
"data-type": type,
"data-size": size,
"data-file": name,
"data-permissions": permissions
});
// filename td
td = $('<td></td>').attr({
"class": "filename",
|
|
31b7f2792
|
46 |
"style": 'background-image:url('+iconurl+'); background-size: 32px;'
|
|
03e52840d
|
47 |
}); |
|
31b7f2792
|
48 49 |
var rand = Math.random().toString(16).slice(2);
td.append('<input id="select-'+rand+'" type="checkbox" /><label for="select-'+rand+'"></label>');
|
|
03e52840d
|
50 51 52 53 54 |
var link_elem = $('<a></a>').attr({
"class": "name",
"href": linktarget
});
//split extension from filename for non dirs
|
|
31b7f2792
|
55 |
if (type !== 'dir' && name.indexOf('.') !== -1) {
|
|
03e52840d
|
56 57 58 59 60 61 62 63 |
basename=name.substr(0,name.lastIndexOf('.'));
extension=name.substr(name.lastIndexOf('.'));
} else {
basename=name;
extension=false;
}
var name_span=$('<span></span>').addClass('nametext').text(basename);
link_elem.append(name_span);
|
|
31b7f2792
|
64 |
if (extension) {
|
|
03e52840d
|
65 66 67 |
name_span.append($('<span></span>').addClass('extension').text(extension));
}
//dirs can show the number of uploaded files
|
|
31b7f2792
|
68 |
if (type === 'dir') {
|
|
03e52840d
|
69 70 71 72 73 74 75 76 77 |
link_elem.append($('<span></span>').attr({
'class': 'uploadtext',
'currentUploads': 0
}));
}
td.append(link_elem);
tr.append(td);
//size column
|
|
31b7f2792
|
78 79 80 |
if (size !== t('files', 'Pending')) {
simpleSize = humanFileSize(size);
} else {
|
|
03e52840d
|
81 82 |
simpleSize=t('files', 'Pending');
}
|
|
31b7f2792
|
83 |
var sizeColor = Math.round(160-Math.pow((size/(1024*1024)),2)); |
|
03e52840d
|
84 85 86 |
var lastModifiedTime = Math.round(lastModified.getTime() / 1000);
td = $('<td></td>').attr({
"class": "filesize",
|
|
03e52840d
|
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
"style": 'color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')'
}).text(simpleSize);
tr.append(td);
// date column
var modifiedColor = Math.round((Math.round((new Date()).getTime() / 1000)-lastModifiedTime)/60/60/24*5);
td = $('<td></td>').attr({ "class": "date" });
td.append($('<span></span>').attr({
"class": "modified",
"title": formatDate(lastModified),
"style": 'color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')'
}).text( relative_modified_date(lastModified.getTime() / 1000) ));
tr.append(td);
return tr;
},
|
|
31b7f2792
|
102 |
addFile:function(name, size, lastModified, loading, hidden, param) {
|
|
03e52840d
|
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
var imgurl;
if (!param) {
param = {};
}
var download_url = null;
if (!param.download_url) {
download_url = OC.Router.generate('download', { file: $('#dir').val()+'/'+name });
} else {
download_url = param.download_url;
}
if (loading) {
imgurl = OC.imagePath('core', 'loading.gif');
} else {
imgurl = OC.imagePath('core', 'filetypes/file.png');
}
var tr = this.createRow(
'file',
name,
imgurl,
download_url,
size,
lastModified,
$('#permissions').val()
);
FileList.insertElement(name, 'file', tr);
|
|
31b7f2792
|
132 133 134 |
if (loading) {
tr.data('loading', true);
} else {
|
|
03e52840d
|
135 136 137 138 139 140 141 |
tr.find('td.filename').draggable(dragOptions);
}
if (hidden) {
tr.hide();
}
return tr;
},
|
|
31b7f2792
|
142 |
addDir:function(name, size, lastModified, hidden) {
|
|
03e52840d
|
143 144 145 146 147 148 149 150 151 152 |
var tr = this.createRow(
'dir',
name,
OC.imagePath('core', 'filetypes/folder.png'),
OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent($('#dir').val()+'/'+name).replace(/%2F/g, '/'),
size,
lastModified,
$('#permissions').val()
);
|
|
31b7f2792
|
153 |
FileList.insertElement(name, 'dir', tr); |
|
03e52840d
|
154 155 156 157 158 159 160 161 162 |
var td = tr.find('td.filename');
td.draggable(dragOptions);
td.droppable(folderDropOptions);
if (hidden) {
tr.hide();
}
FileActions.display(tr.find('td.filename'), true);
return tr;
},
|
|
31b7f2792
|
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
getCurrentDirectory: function(){
return $('#dir').val() || '/';
},
/**
* @brief Changes the current directory and reload the file list.
* @param targetDir target directory (non URL encoded)
* @param changeUrl false if the URL must not be changed (defaults to true)
* @param {boolean} force set to true to force changing directory
*/
changeDirectory: function(targetDir, changeUrl, force) {
var $dir = $('#dir'),
url,
currentDir = $dir.val() || '/';
targetDir = targetDir || '/';
if (!force && currentDir === targetDir) {
return;
|
|
03e52840d
|
179 |
} |
|
31b7f2792
|
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
FileList.setCurrentDir(targetDir, changeUrl);
$('#fileList').trigger(
jQuery.Event('changeDirectory', {
dir: targetDir,
previousDir: currentDir
}
));
FileList.reload();
},
linkTo: function(dir) {
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
},
setCurrentDir: function(targetDir, changeUrl) {
$('#dir').val(targetDir);
if (changeUrl !== false) {
if (window.history.pushState && changeUrl !== false) {
url = FileList.linkTo(targetDir);
window.history.pushState({dir: targetDir}, '', url);
}
// use URL hash for IE8
else{
window.location.hash = '?dir='+ encodeURIComponent(targetDir).replace(/%2F/g, '/');
}
}
},
/**
* @brief Reloads the file list using ajax call
*/
reload: function() {
FileList.showMask();
if (FileList._reloadCall) {
FileList._reloadCall.abort();
}
FileList._reloadCall = $.ajax({
url: OC.filePath('files','ajax','list.php'),
data: {
dir : $('#dir').val(),
breadcrumb: true
},
error: function(result) {
FileList.reloadCallback(result);
},
success: function(result) {
FileList.reloadCallback(result);
}
});
},
reloadCallback: function(result) {
var $controls = $('#controls');
delete FileList._reloadCall;
FileList.hideMask();
if (!result || result.status === 'error') {
OC.Notification.show(result.data.message);
return;
}
if (result.status === 404) {
// go back home
FileList.changeDirectory('/');
return;
}
// TODO: should rather return upload file size through
// the files list ajax call
Files.updateStorageStatistics(true);
if (result.data.permissions) {
FileList.setDirectoryPermissions(result.data.permissions);
}
if (typeof(result.data.breadcrumb) !== 'undefined') {
$controls.find('.crumb').remove();
$controls.prepend(result.data.breadcrumb);
var width = $(window).width();
Files.initBreadCrumbs();
Files.resizeBreadcrumbs(width, true);
// in case svg is not supported by the browser we need to execute the fallback mechanism
if (!SVGSupport()) {
replaceSVG();
}
}
|
|
03e52840d
|
265 |
FileList.update(result.data.files); |
|
31b7f2792
|
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
},
setDirectoryPermissions: function(permissions) {
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
$('#permissions').val(permissions);
$('.creatable').toggleClass('hidden', !isCreatable);
$('.notCreatable').toggleClass('hidden', isCreatable);
},
/**
* Shows/hides action buttons
*
* @param show true for enabling, false for disabling
*/
showActions: function(show){
$('.actions,#file_action_panel').toggleClass('hidden', !show);
if (show){
// make sure to display according to permissions
var permissions = $('#permissions').val();
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
$('.creatable').toggleClass('hidden', !isCreatable);
$('.notCreatable').toggleClass('hidden', isCreatable);
}
else{
$('.creatable, .notCreatable').addClass('hidden');
}
},
/**
* Enables/disables viewer mode.
* In viewer mode, apps can embed themselves under the controls bar.
* In viewer mode, the actions of the file list will be hidden.
* @param show true for enabling, false for disabling
*/
setViewerMode: function(show){
this.showActions(!show);
$('#filestable').toggleClass('hidden', show);
|
|
03e52840d
|
300 301 |
},
remove:function(name){
|
|
a293d369c
|
302 303 304 305 306 307 |
var fileEl = FileList.findFileEl(name);
if (fileEl.data('permissions') & OC.PERMISSION_DELETE) {
// file is only draggable when delete permissions are set
fileEl.find('td.filename').draggable('destroy');
}
fileEl.remove();
|
|
31b7f2792
|
308 309 310 311 |
FileList.updateFileSummary();
if ( ! $('tr[data-file]').exists() ) {
$('#emptycontent').removeClass('hidden');
$('#filescontent th').addClass('hidden');
|
|
03e52840d
|
312 313 |
} }, |
|
31b7f2792
|
314 |
insertElement:function(name, type, element) {
|
|
03e52840d
|
315 316 |
//find the correct spot to insert the file or folder
var pos, fileElements=$('tr[data-file][data-type="'+type+'"]:visible');
|
|
31b7f2792
|
317 318 319 320 321 322 323 324 325 |
if (name.localeCompare($(fileElements[0]).attr('data-file')) < 0) {
pos = -1;
} else if (name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file')) > 0) {
pos = fileElements.length - 1;
} else {
for(pos = 0; pos<fileElements.length-1; pos++) {
if (name.localeCompare($(fileElements[pos]).attr('data-file')) > 0
&& name.localeCompare($(fileElements[pos+1]).attr('data-file')) < 0)
{
|
|
03e52840d
|
326 327 328 329 |
break; } } } |
|
31b7f2792
|
330 331 |
if (fileElements.exists()) {
if (pos === -1) {
|
|
03e52840d
|
332 |
$(fileElements[0]).before(element); |
|
31b7f2792
|
333 |
} else {
|
|
03e52840d
|
334 335 |
$(fileElements[pos]).after(element); } |
|
31b7f2792
|
336 |
} else if (type === 'dir' && $('tr[data-file]').exists()) {
|
|
03e52840d
|
337 |
$('tr[data-file]').first().before(element);
|
|
31b7f2792
|
338 339 340 |
} else if (type === 'file' && $('tr[data-file]').exists()) {
$('tr[data-file]').last().before(element);
} else {
|
|
03e52840d
|
341 342 |
$('#fileList').append(element);
}
|
|
31b7f2792
|
343 344 345 |
$('#emptycontent').addClass('hidden');
$('#filestable th').removeClass('hidden');
FileList.updateFileSummary();
|
|
03e52840d
|
346 |
}, |
|
31b7f2792
|
347 |
loadingDone:function(name, id) {
|
|
a293d369c
|
348 |
var mime, tr = FileList.findFileEl(name); |
|
31b7f2792
|
349 350 351 352 |
tr.data('loading', false);
mime = tr.data('mime');
tr.attr('data-mime', mime);
if (id) {
|
|
03e52840d
|
353 354 |
tr.attr('data-id', id);
}
|
|
31b7f2792
|
355 356 357 358 |
var path = getPathForPreview(name);
Files.lazyLoadPreview(path, mime, function(previewpath) {
tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
}, null, null, tr.attr('data-etag'));
|
|
03e52840d
|
359 360 |
tr.find('td.filename').draggable(dragOptions);
},
|
|
a293d369c
|
361 362 |
isLoading:function(file) {
return FileList.findFileEl(file).data('loading');
|
|
03e52840d
|
363 |
}, |
|
31b7f2792
|
364 |
rename:function(oldname) {
|
|
03e52840d
|
365 |
var tr, td, input, form; |
|
a293d369c
|
366 |
tr = FileList.findFileEl(oldname); |
|
03e52840d
|
367 |
tr.data('renaming',true);
|
|
31b7f2792
|
368 369 370 |
td = tr.children('td.filename');
input = $('<input type="text" class="filename"/>').val(oldname);
form = $('<form></form>');
|
|
03e52840d
|
371 372 373 374 |
form.append(input);
td.children('a.name').hide();
td.append(form);
input.focus();
|
|
03e52840d
|
375 376 377 378 379 |
//preselect input
var len = input.val().lastIndexOf('.');
if (len === -1) {
len = input.val().length;
}
|
|
31b7f2792
|
380 |
input.selectRange(0, len); |
|
03e52840d
|
381 |
|
|
31b7f2792
|
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
var checkInput = function () {
var filename = input.val();
if (filename !== oldname) {
if (!Files.isFileNameValid(filename)) {
// Files.isFileNameValid(filename) throws an exception itself
} else if($('#dir').val() === '/' && filename === 'Shared') {
throw t('files','In the home folder \'Shared\' is a reserved filename');
} else if (FileList.inList(filename)) {
throw t('files', '{new_name} already exists', {new_name: filename});
}
}
return true;
};
form.submit(function(event) {
|
|
03e52840d
|
397 398 |
event.stopPropagation(); event.preventDefault(); |
|
31b7f2792
|
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
try {
var newname = input.val();
if (newname !== oldname) {
checkInput();
// save background image, because it's replaced by a spinner while async request
var oldBackgroundImage = td.css('background-image');
// mark as loading
td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
$.ajax({
url: OC.filePath('files','ajax','rename.php'),
data: {
dir : $('#dir').val(),
newname: newname,
file: oldname
},
success: function(result) {
if (!result || result.status === 'error') {
OC.dialogs.alert(result.data.message, t('core', 'Could not rename file'));
// revert changes
newname = oldname;
tr.attr('data-file', newname);
var path = td.children('a.name').attr('href');
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
var basename=newname.substr(0,newname.lastIndexOf('.'));
} else {
var basename=newname;
}
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
if ( ! td.find('a.name span.extension').exists() ) {
td.find('a.name span.nametext').append('<span class="extension"></span>');
}
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
}
tr.find('.fileactions').effect('highlight', {}, 5000);
tr.effect('highlight', {}, 5000);
// remove loading mark and recover old image
td.css('background-image', oldBackgroundImage);
}
else {
var fileInfo = result.data;
tr.attr('data-mime', fileInfo.mime);
tr.attr('data-etag', fileInfo.etag);
if (fileInfo.isPreviewAvailable) {
Files.lazyLoadPreview(fileInfo.directory + '/' + fileInfo.name, result.data.mime, function(previewpath) {
tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
}, null, null, result.data.etag);
}
else {
tr.find('td.filename').removeClass('preview').attr('style','background-image:url('+fileInfo.icon+')');
}
}
// reinsert row
tr.detach();
FileList.insertElement( tr.attr('data-file'), tr.attr('data-type'),tr );
// update file actions in case the extension changed
FileActions.display( tr.find('td.filename'), true);
|
|
03e52840d
|
457 458 |
} }); |
|
03e52840d
|
459 |
} |
|
31b7f2792
|
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
input.tipsy('hide');
tr.data('renaming',false);
tr.attr('data-file', newname);
var path = td.children('a.name').attr('href');
// FIXME this will fail if the path contains the filename.
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
var basename = newname;
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
basename = newname.substr(0, newname.lastIndexOf('.'));
}
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
if ( ! td.find('a.name span.extension').exists() ) {
td.find('a.name span.nametext').append('<span class="extension"></span>');
}
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
|
|
03e52840d
|
476 |
} |
|
31b7f2792
|
477 478 479 480 481 482 483 |
form.remove();
td.children('a.name').show();
} catch (error) {
input.attr('title', error);
input.tipsy({gravity: 'w', trigger: 'manual'});
input.tipsy('show');
input.addClass('error');
|
|
03e52840d
|
484 |
} |
|
03e52840d
|
485 486 |
return false; }); |
|
31b7f2792
|
487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
input.keyup(function(event) {
// verify filename on typing
try {
checkInput();
input.tipsy('hide');
input.removeClass('error');
} catch (error) {
input.attr('title', error);
input.tipsy({gravity: 'w', trigger: 'manual'});
input.tipsy('show');
input.addClass('error');
}
if (event.keyCode === 27) {
input.tipsy('hide');
|
|
03e52840d
|
501 502 503 504 505 |
tr.data('renaming',false);
form.remove();
td.children('a.name').show();
}
});
|
|
31b7f2792
|
506 |
input.click(function(event) {
|
|
03e52840d
|
507 508 509 |
event.stopPropagation(); event.preventDefault(); }); |
|
31b7f2792
|
510 |
input.blur(function() {
|
|
03e52840d
|
511 512 513 |
form.trigger('submit');
});
},
|
|
a293d369c
|
514 515 |
inList:function(file) {
return FileList.findFileEl(file).length;
|
|
03e52840d
|
516 517 518 |
},
replace:function(oldName, newName, isNewFile) {
// Finish any existing actions
|
|
a293d369c
|
519 520 521 522 523 |
var oldFileEl = FileList.findFileEl(oldName); var newFileEl = FileList.findFileEl(newName); oldFileEl.hide(); newFileEl.hide(); var tr = oldFileEl.clone(); |
|
03e52840d
|
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
tr.attr('data-replace', 'true');
tr.attr('data-file', newName);
var td = tr.children('td.filename');
td.children('a.name .span').text(newName);
var path = td.children('a.name').attr('href');
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldName), encodeURIComponent(newName)));
if (newName.indexOf('.') > 0) {
var basename = newName.substr(0, newName.lastIndexOf('.'));
} else {
var basename = newName;
}
td.children('a.name').empty();
var span = $('<span class="nametext"></span>');
span.text(basename);
td.children('a.name').append(span);
if (newName.indexOf('.') > 0) {
span.append($('<span class="extension">'+newName.substr(newName.lastIndexOf('.'))+'</span>'));
}
FileList.insertElement(newName, tr.data('type'), tr);
tr.show();
FileList.replaceCanceled = false;
FileList.replaceOldName = oldName;
FileList.replaceNewName = newName;
FileList.replaceIsNewFile = isNewFile;
FileList.lastAction = function() {
FileList.finishReplace();
};
if (!isNewFile) {
|
|
31b7f2792
|
552 |
OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>');
|
|
03e52840d
|
553 554 555 556 557 |
}
},
finishReplace:function() {
if (!FileList.replaceCanceled && FileList.replaceOldName && FileList.replaceNewName) {
$.ajax({url: OC.filePath('files', 'ajax', 'rename.php'), async: false, data: { dir: $('#dir').val(), newname: FileList.replaceNewName, file: FileList.replaceOldName }, success: function(result) {
|
|
31b7f2792
|
558 559 |
if (result && result.status === 'success') {
$('tr[data-replace="true"').removeAttr('data-replace');
|
|
03e52840d
|
560 561 562 563 564 565 566 567 568 569 |
} else {
OC.dialogs.alert(result.data.message, 'Error moving file');
}
FileList.replaceCanceled = true;
FileList.replaceOldName = null;
FileList.replaceNewName = null;
FileList.lastAction = null;
}});
}
},
|
|
31b7f2792
|
570 571 |
do_delete:function(files) {
if (files.substr) {
|
|
03e52840d
|
572 573 574 |
files=[files];
}
for (var i=0; i<files.length; i++) {
|
|
a293d369c
|
575 |
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
|
|
31b7f2792
|
576 |
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
|
03e52840d
|
577 578 579 580 581 582 583 584 585 |
}
// Finish any existing actions
if (FileList.lastAction) {
FileList.lastAction();
}
var fileNames = JSON.stringify(files);
$.post(OC.filePath('files', 'ajax', 'delete.php'),
{dir:$('#dir').val(),files:fileNames},
|
|
31b7f2792
|
586 587 588 |
function(result) {
if (result.status === 'success') {
$.each(files,function(index,file) {
|
|
a293d369c
|
589 |
var files = FileList.findFileEl(file); |
|
03e52840d
|
590 591 592 593 594 |
files.remove();
files.find('input[type="checkbox"]').removeAttr('checked');
files.removeClass('selected');
});
procesSelection();
|
|
31b7f2792
|
595 596 597 598 |
checkTrashStatus(); FileList.updateFileSummary(); FileList.updateEmptyContent(); Files.updateStorageStatistics(); |
|
03e52840d
|
599 |
} else {
|
|
31b7f2792
|
600 601 602 603 604 605 606 607 608 609 |
if (result.status === 'error' && result.data.message) {
OC.Notification.show(result.data.message);
}
else {
OC.Notification.show(t('files', 'Error deleting file.'));
}
// hide notification after 10 sec
setTimeout(function() {
OC.Notification.hide();
}, 10000);
|
|
03e52840d
|
610 |
$.each(files,function(index,file) {
|
|
a293d369c
|
611 |
var deleteAction = FileList.findFileEl(file).find('.action.delete');
|
|
31b7f2792
|
612 |
deleteAction.removeClass('progress-icon').addClass('delete-icon');
|
|
03e52840d
|
613 614 615 |
}); } }); |
|
31b7f2792
|
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 |
},
createFileSummary: function() {
if( $('#fileList tr').exists() ) {
var summary = this._calculateFileSummary();
// Get translations
var directoryInfo = n('files', '%n folder', '%n folders', summary.totalDirs);
var fileInfo = n('files', '%n file', '%n files', summary.totalFiles);
var infoVars = {
dirs: '<span class="dirinfo">'+directoryInfo+'</span><span class="connector">',
files: '</span><span class="fileinfo">'+fileInfo+'</span>'
};
var info = t('files', '{dirs} and {files}', infoVars);
// don't show the filesize column, if filesize is NaN (e.g. in trashbin)
if (isNaN(summary.totalSize)) {
var fileSize = '';
} else {
var fileSize = '<td class="filesize">'+humanFileSize(summary.totalSize)+'</td>';
}
var $summary = $('<tr class="summary" data-file="undefined"><td><span class="info">'+info+'</span></td>'+fileSize+'<td></td></tr>');
$('#fileList').append($summary);
var $dirInfo = $summary.find('.dirinfo');
var $fileInfo = $summary.find('.fileinfo');
var $connector = $summary.find('.connector');
// Show only what's necessary, e.g.: no files: don't show "0 files"
if (summary.totalDirs === 0) {
$dirInfo.hide();
$connector.hide();
}
if (summary.totalFiles === 0) {
$fileInfo.hide();
$connector.hide();
}
}
},
_calculateFileSummary: function() {
var result = {
totalDirs: 0,
totalFiles: 0,
totalSize: 0
};
$.each($('tr[data-file]'), function(index, value) {
var $value = $(value);
if ($value.data('type') === 'dir') {
result.totalDirs++;
} else if ($value.data('type') === 'file') {
result.totalFiles++;
}
if ($value.data('size') !== undefined && $value.data('id') !== -1) {
//Skip shared as it does not count toward quota
result.totalSize += parseInt($value.data('size'));
}
});
return result;
},
updateFileSummary: function() {
var $summary = $('.summary');
// Check if we should remove the summary to show "Upload something"
if ($('#fileList tr').length === 1 && $summary.length === 1) {
$summary.remove();
}
// If there's no summary create one (createFileSummary checks if there's data)
else if ($summary.length === 0) {
FileList.createFileSummary();
}
// There's a summary and data -> Update the summary
else if ($('#fileList tr').length > 1 && $summary.length === 1) {
var fileSummary = this._calculateFileSummary();
var $dirInfo = $('.summary .dirinfo');
var $fileInfo = $('.summary .fileinfo');
var $connector = $('.summary .connector');
// Substitute old content with new translations
$dirInfo.html(n('files', '%n folder', '%n folders', fileSummary.totalDirs));
$fileInfo.html(n('files', '%n file', '%n files', fileSummary.totalFiles));
$('.summary .filesize').html(humanFileSize(fileSummary.totalSize));
// Show only what's necessary (may be hidden)
if (fileSummary.totalDirs === 0) {
$dirInfo.hide();
$connector.hide();
} else {
$dirInfo.show();
}
if (fileSummary.totalFiles === 0) {
$fileInfo.hide();
$connector.hide();
} else {
$fileInfo.show();
}
if (fileSummary.totalDirs > 0 && fileSummary.totalFiles > 0) {
$connector.show();
}
}
},
updateEmptyContent: function() {
var $fileList = $('#fileList');
var permissions = $('#permissions').val();
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
var exists = $fileList.find('tr:first').exists();
$('#emptycontent').toggleClass('hidden', !isCreatable || exists);
$('#filestable th').toggleClass('hidden', !exists);
},
showMask: function() {
// in case one was shown before
var $mask = $('#content .mask');
if ($mask.exists()) {
return;
}
$mask = $('<div class="mask transparent"></div>');
$mask.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
$mask.css('background-repeat', 'no-repeat');
$('#content').append($mask);
// block UI, but only make visible in case loading takes longer
FileList._maskTimeout = window.setTimeout(function() {
// reset opacity
$mask.removeClass('transparent');
}, 250);
},
hideMask: function() {
var $mask = $('#content .mask').remove();
if (FileList._maskTimeout) {
window.clearTimeout(FileList._maskTimeout);
}
},
scrollTo:function(file) {
//scroll to and highlight preselected file
|
|
a293d369c
|
753 |
var $scrolltorow = FileList.findFileEl(file); |
|
31b7f2792
|
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
if ($scrolltorow.exists()) {
$scrolltorow.addClass('searchresult');
$(window).scrollTop($scrolltorow.position().top);
//remove highlight when hovered over
$scrolltorow.one('hover', function() {
$scrolltorow.removeClass('searchresult');
});
}
},
filter:function(query) {
$('#fileList tr:not(.summary)').each(function(i,e) {
if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) !== -1) {
$(e).addClass("searchresult");
} else {
$(e).removeClass("searchresult");
}
});
//do not use scrollto to prevent removing searchresult css class
var first = $('#fileList tr.searchresult').first();
if (first.exists()) {
$(window).scrollTop(first.position().top);
}
},
unfilter:function() {
$('#fileList tr.searchresult').each(function(i,e) {
$(e).removeClass("searchresult");
});
|
|
03e52840d
|
781 782 |
} }; |
|
31b7f2792
|
783 784 |
$(document).ready(function() {
var isPublic = !!$('#isPublic').val();
|
|
03e52840d
|
785 786 787 |
// handle upload events
var file_upload_start = $('#file_upload_start');
|
|
31b7f2792
|
788 |
|
|
03e52840d
|
789 |
file_upload_start.on('fileuploaddrop', function(e, data) {
|
|
31b7f2792
|
790 791 792 793 794 795 796 797 798 799 800 801 802 803 |
OC.Upload.log('filelist handle fileuploaddrop', e, data);
var dropTarget = $(e.originalEvent.target).closest('tr, .crumb');
if (dropTarget && (dropTarget.data('type') === 'dir' || dropTarget.hasClass('crumb'))) { // drag&drop upload to folder
// remember as context
data.context = dropTarget;
var dir = dropTarget.data('file');
// if from file list, need to prepend parent dir
if (dir) {
var parentDir = $('#dir').val() || '/';
if (parentDir[parentDir.length - 1] !== '/') {
parentDir += '/';
|
|
03e52840d
|
804 |
} |
|
31b7f2792
|
805 |
dir = parentDir + dir; |
|
03e52840d
|
806 |
} |
|
31b7f2792
|
807 808 809 810 811 812 813 814 815 816 817 818 819 |
else{
// read full path from crumb
dir = dropTarget.data('dir') || '/';
}
// update folder in form
data.formData = function(form) {
return [
{name: 'dir', value: dir},
{name: 'requesttoken', value: oc_requesttoken}
];
};
}
|
|
03e52840d
|
820 821 |
});
file_upload_start.on('fileuploadadd', function(e, data) {
|
|
31b7f2792
|
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 |
OC.Upload.log('filelist handle fileuploadadd', e, data);
//finish delete if we are uploading a deleted file
if (FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1) {
FileList.finishDelete(null, true); //delete file before continuing
}
// add ui visualization to existing folder
if (data.context && data.context.data('type') === 'dir') {
// add to existing folder
// update upload counter ui
var uploadtext = data.context.find('.uploadtext');
var currentUploads = parseInt(uploadtext.attr('currentUploads'));
currentUploads += 1;
uploadtext.attr('currentUploads', currentUploads);
|
|
03e52840d
|
838 |
|
|
31b7f2792
|
839 840 841 842 843 844 845 846 |
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
if (currentUploads === 1) {
var img = OC.imagePath('core', 'loading.gif');
data.context.find('td.filename').attr('style','background-image:url('+img+')');
uploadtext.text(translatedText);
uploadtext.show();
} else {
uploadtext.text(translatedText);
|
|
03e52840d
|
847 |
} |
|
31b7f2792
|
848 |
} |
|
03e52840d
|
849 |
|
|
31b7f2792
|
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 |
});
/*
* when file upload done successfully add row to filelist
* update counter when uploading to sub folder
*/
file_upload_start.on('fileuploaddone', function(e, data) {
OC.Upload.log('filelist handle fileuploaddone', e, data);
var response;
if (typeof data.result === 'string') {
response = data.result;
} else {
// fetch response from iframe
response = data.result[0].body.innerText;
}
var result=$.parseJSON(response);
|
|
03e52840d
|
866 |
|
|
31b7f2792
|
867 868 869 870 |
if (typeof result[0] !== 'undefined' && result[0].status === 'success') {
var file = result[0];
if (data.context && data.context.data('type') === 'dir') {
|
|
03e52840d
|
871 872 873 874 |
// update upload counter ui
var uploadtext = data.context.find('.uploadtext');
var currentUploads = parseInt(uploadtext.attr('currentUploads'));
|
|
31b7f2792
|
875 |
currentUploads -= 1; |
|
03e52840d
|
876 |
uploadtext.attr('currentUploads', currentUploads);
|
|
31b7f2792
|
877 878 879 |
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
if (currentUploads === 0) {
var img = OC.imagePath('core', 'filetypes/folder.png');
|
|
03e52840d
|
880 |
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
|
31b7f2792
|
881 882 |
uploadtext.text(translatedText); uploadtext.hide(); |
|
03e52840d
|
883 |
} else {
|
|
31b7f2792
|
884 |
uploadtext.text(translatedText); |
|
03e52840d
|
885 |
} |
|
31b7f2792
|
886 887 888 889 890 891 |
// update folder size
var size = parseInt(data.context.data('size'));
size += parseInt(file.size);
data.context.attr('data-size', size);
data.context.find('td.filesize').text(humanFileSize(size));
|
|
03e52840d
|
892 |
} else {
|
|
a293d369c
|
893 894 |
// only append new file if uploaded into the current folder
if (file.directory !== FileList.getCurrentDirectory()) {
|
|
31b7f2792
|
895 896 |
return; } |
|
03e52840d
|
897 |
// add as stand-alone row to filelist |
|
31b7f2792
|
898 899 |
var size=t('files', 'Pending');
if (data.files[0].size>=0) {
|
|
03e52840d
|
900 901 902 903 |
size=data.files[0].size;
}
var date=new Date();
var param = {};
|
|
31b7f2792
|
904 905 |
if ($('#publicUploadRequestToken').exists()) {
param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name;
|
|
03e52840d
|
906 |
} |
|
31b7f2792
|
907 908 |
//should the file exist in the list remove it FileList.remove(file.name); |
|
03e52840d
|
909 |
// create new file context |
|
31b7f2792
|
910 911 912 913 914 915 916 917 918 919 920 |
data.context = FileList.addFile(file.name, file.size, date, false, false, param);
// update file data
data.context.attr('data-mime',file.mime).attr('data-id',file.id).attr('data-etag', file.etag);
var permissions = data.context.data('permissions');
if (permissions !== file.permissions) {
data.context.attr('data-permissions', file.permissions);
data.context.data('permissions', file.permissions);
}
FileActions.display(data.context.find('td.filename'), true);
|
|
03e52840d
|
921 |
|
|
31b7f2792
|
922 923 924 925 |
var path = getPathForPreview(file.name);
Files.lazyLoadPreview(path, file.mime, function(previewpath) {
data.context.find('td.filename').attr('style','background-image:url('+previewpath+')');
}, null, null, file.etag);
|
|
03e52840d
|
926 927 928 |
} } }); |
|
31b7f2792
|
929 930 |
file_upload_start.on('fileuploadstop', function(e, data) {
OC.Upload.log('filelist handle fileuploadstop', e, data);
|
|
03e52840d
|
931 |
|
|
31b7f2792
|
932 933 934 935 936 937 938 939 |
//if user pressed cancel hide upload chrome
if (data.errorThrown === 'abort') {
//cleanup uploading to a dir
var uploadtext = $('tr .uploadtext');
var img = OC.imagePath('core', 'filetypes/folder.png');
uploadtext.parents('td.filename').attr('style','background-image:url('+img+')');
uploadtext.fadeOut();
uploadtext.attr('currentUploads', 0);
|
|
03e52840d
|
940 941 942 |
}
});
file_upload_start.on('fileuploadfail', function(e, data) {
|
|
31b7f2792
|
943 944 945 946 |
OC.Upload.log('filelist handle fileuploadfail', e, data);
//if user pressed cancel hide upload chrome
if (data.errorThrown === 'abort') {
|
|
03e52840d
|
947 |
//cleanup uploading to a dir |
|
31b7f2792
|
948 |
var uploadtext = $('tr .uploadtext');
|
|
03e52840d
|
949 |
var img = OC.imagePath('core', 'filetypes/folder.png');
|
|
31b7f2792
|
950 951 952 |
uploadtext.parents('td.filename').attr('style','background-image:url('+img+')');
uploadtext.fadeOut();
uploadtext.attr('currentUploads', 0);
|
|
03e52840d
|
953 954 955 956 |
}
});
$('#notification').hide();
|
|
31b7f2792
|
957 |
$('#notification').on('click', '.undo', function() {
|
|
03e52840d
|
958 |
if (FileList.deleteFiles) {
|
|
31b7f2792
|
959 |
$.each(FileList.deleteFiles,function(index,file) {
|
|
a293d369c
|
960 |
FileList.findFileEl(file).show(); |
|
03e52840d
|
961 962 963 964 965 966 967 968 969 |
});
FileList.deleteCanceled=true;
FileList.deleteFiles=null;
} else if (FileList.replaceOldName && FileList.replaceNewName) {
if (FileList.replaceIsNewFile) {
// Delete the new uploaded file
FileList.deleteCanceled = false;
FileList.deleteFiles = [FileList.replaceOldName];
} else {
|
|
a293d369c
|
970 |
FileList.findFileEl(FileList.replaceOldName).show(); |
|
03e52840d
|
971 |
} |
|
31b7f2792
|
972 |
$('tr[data-replace="true"').remove();
|
|
a293d369c
|
973 |
FileList.findFileEl(FileList.replaceNewName).show(); |
|
03e52840d
|
974 975 976 977 978 979 |
FileList.replaceCanceled = true; FileList.replaceOldName = null; FileList.replaceNewName = null; FileList.replaceIsNewFile = null; } FileList.lastAction = null; |
|
31b7f2792
|
980 |
OC.Notification.hide(); |
|
03e52840d
|
981 982 |
});
$('#notification:first-child').on('click', '.replace', function() {
|
|
31b7f2792
|
983 984 985 |
OC.Notification.hide(function() {
FileList.replace($('#notification > span').attr('data-oldName'), $('#notification > span').attr('data-newName'), $('#notification > span').attr('data-isNewFile'));
});
|
|
03e52840d
|
986 987 |
});
$('#notification:first-child').on('click', '.suggest', function() {
|
|
a293d369c
|
988 989 |
var file = $('#notification > span').attr('data-oldName');
FileList.findFileEl(file).show();
|
|
31b7f2792
|
990 |
OC.Notification.hide(); |
|
03e52840d
|
991 992 993 994 995 996 997 998 |
});
$('#notification:first-child').on('click', '.cancel', function() {
if ($('#notification > span').attr('data-isNewFile')) {
FileList.deleteCanceled = false;
FileList.deleteFiles = [$('#notification > span').attr('data-oldName')];
}
});
FileList.useUndo=(window.onbeforeunload)?true:false;
|
|
31b7f2792
|
999 |
$(window).bind('beforeunload', function () {
|
|
03e52840d
|
1000 1001 1002 1003 |
if (FileList.lastAction) {
FileList.lastAction();
}
});
|
|
31b7f2792
|
1004 |
$(window).unload(function () {
|
|
03e52840d
|
1005 1006 |
$(window).trigger('beforeunload');
});
|
|
31b7f2792
|
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
function decodeQuery(query) {
return query.replace(/\+/g, ' ');
}
function parseHashQuery() {
var hash = window.location.hash,
pos = hash.indexOf('?'),
query;
if (pos >= 0) {
return hash.substr(pos + 1);
}
return '';
}
function parseCurrentDirFromUrl() {
var query = parseHashQuery(),
params,
dir = '/';
// try and parse from URL hash first
if (query) {
params = OC.parseQueryString(decodeQuery(query));
}
// else read from query attributes
if (!params) {
params = OC.parseQueryString(decodeQuery(location.search));
}
return (params && params.dir) || '/';
}
// disable ajax/history API for public app (TODO: until it gets ported)
if (!isPublic) {
// fallback to hashchange when no history support
if (!window.history.pushState) {
$(window).on('hashchange', function() {
FileList.changeDirectory(parseCurrentDirFromUrl(), false);
});
}
window.onpopstate = function(e) {
var targetDir;
if (e.state && e.state.dir) {
targetDir = e.state.dir;
}
else{
// read from URL
targetDir = parseCurrentDirFromUrl();
}
if (targetDir) {
FileList.changeDirectory(targetDir, false);
}
};
if (parseInt($('#ajaxLoad').val(), 10) === 1) {
// need to initially switch the dir to the one from the hash (IE8)
FileList.changeDirectory(parseCurrentDirFromUrl(), false, true);
}
}
FileList.createFileSummary();
|
|
03e52840d
|
1066 |
}); |