prevent user from creating or renaming sth. to an existing filename
- show tooltip when violating naming constraints while typing - when target filename exists on server fallback to dialog to interrupt the users flow because something unexpected went wrong - fixes #5062 - also fixes some whitespace and codestyle issues in files js - uses css selector over filterAttr in touched js files
This commit is contained in:
parent
cadd71ec8a
commit
45e6d96702
|
@ -56,6 +56,21 @@ function progress($notification_code, $severity, $message, $message_code, $bytes
|
||||||
|
|
||||||
$target = $dir.'/'.$filename;
|
$target = $dir.'/'.$filename;
|
||||||
|
|
||||||
|
$l10n = \OC_L10n::get('files');
|
||||||
|
|
||||||
|
if (\OC\Files\Filesystem::file_exists($target)) {
|
||||||
|
$result = array(
|
||||||
|
'success' => false,
|
||||||
|
'data' => array(
|
||||||
|
'message' => $l10n->t(
|
||||||
|
"The name %s is already used in the folder %s. Please choose a different name.",
|
||||||
|
array($newname, $dir))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
OCP\JSON::error($result);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
if($source) {
|
if($source) {
|
||||||
if(substr($source, 0, 8)!='https://' and substr($source, 0, 7)!='http://') {
|
if(substr($source, 0, 8)!='https://' and substr($source, 0, 7)!='http://') {
|
||||||
OCP\JSON::error(array("data" => array( "message" => "Not a valid source" )));
|
OCP\JSON::error(array("data" => array( "message" => "Not a valid source" )));
|
||||||
|
|
|
@ -49,7 +49,13 @@
|
||||||
background-repeat:no-repeat; cursor:pointer; }
|
background-repeat:no-repeat; cursor:pointer; }
|
||||||
#new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;}
|
#new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;}
|
||||||
|
|
||||||
|
#new .error, #fileList .error {
|
||||||
|
color: #e9322d;
|
||||||
|
border-color: #e9322d;
|
||||||
|
-webkit-box-shadow: 0 0 6px #f8b9b7;
|
||||||
|
-moz-box-shadow: 0 0 6px #f8b9b7;
|
||||||
|
box-shadow: 0 0 6px #f8b9b7;
|
||||||
|
}
|
||||||
|
|
||||||
/* FILE TABLE */
|
/* FILE TABLE */
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@ OC.Upload = {
|
||||||
*/
|
*/
|
||||||
cancelUploads:function() {
|
cancelUploads:function() {
|
||||||
this.log('canceling uploads');
|
this.log('canceling uploads');
|
||||||
jQuery.each(this._uploads,function(i, jqXHR){
|
jQuery.each(this._uploads,function(i, jqXHR) {
|
||||||
jqXHR.abort();
|
jqXHR.abort();
|
||||||
});
|
});
|
||||||
this._uploads = [];
|
this._uploads = [];
|
||||||
},
|
},
|
||||||
rememberUpload:function(jqXHR){
|
rememberUpload:function(jqXHR) {
|
||||||
if (jqXHR) {
|
if (jqXHR) {
|
||||||
this._uploads.push(jqXHR);
|
this._uploads.push(jqXHR);
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,10 @@ OC.Upload = {
|
||||||
* returns true if any hxr has the state 'pending'
|
* returns true if any hxr has the state 'pending'
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isProcessing:function(){
|
isProcessing:function() {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|
||||||
jQuery.each(this._uploads,function(i, data){
|
jQuery.each(this._uploads,function(i, data) {
|
||||||
if (data.state() === 'pending') {
|
if (data.state() === 'pending') {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ OC.Upload = {
|
||||||
* handle skipping an upload
|
* handle skipping an upload
|
||||||
* @param {object} data
|
* @param {object} data
|
||||||
*/
|
*/
|
||||||
onSkip:function(data){
|
onSkip:function(data) {
|
||||||
this.log('skip', null, data);
|
this.log('skip', null, data);
|
||||||
this.deleteUpload(data);
|
this.deleteUpload(data);
|
||||||
},
|
},
|
||||||
|
@ -122,12 +122,12 @@ OC.Upload = {
|
||||||
* handle replacing a file on the server with an uploaded file
|
* handle replacing a file on the server with an uploaded file
|
||||||
* @param {object} data
|
* @param {object} data
|
||||||
*/
|
*/
|
||||||
onReplace:function(data){
|
onReplace:function(data) {
|
||||||
this.log('replace', null, data);
|
this.log('replace', null, data);
|
||||||
if (data.data){
|
if (data.data) {
|
||||||
data.data.append('resolution', 'replace');
|
data.data.append('resolution', 'replace');
|
||||||
} else {
|
} else {
|
||||||
data.formData.push({name:'resolution',value:'replace'}); //hack for ie8
|
data.formData.push({name:'resolution', value:'replace'}); //hack for ie8
|
||||||
}
|
}
|
||||||
data.submit();
|
data.submit();
|
||||||
},
|
},
|
||||||
|
@ -135,12 +135,12 @@ OC.Upload = {
|
||||||
* handle uploading a file and letting the server decide a new name
|
* handle uploading a file and letting the server decide a new name
|
||||||
* @param {object} data
|
* @param {object} data
|
||||||
*/
|
*/
|
||||||
onAutorename:function(data){
|
onAutorename:function(data) {
|
||||||
this.log('autorename', null, data);
|
this.log('autorename', null, data);
|
||||||
if (data.data) {
|
if (data.data) {
|
||||||
data.data.append('resolution', 'autorename');
|
data.data.append('resolution', 'autorename');
|
||||||
} else {
|
} else {
|
||||||
data.formData.push({name:'resolution',value:'autorename'}); //hack for ie8
|
data.formData.push({name:'resolution', value:'autorename'}); //hack for ie8
|
||||||
}
|
}
|
||||||
data.submit();
|
data.submit();
|
||||||
},
|
},
|
||||||
|
@ -162,7 +162,7 @@ OC.Upload = {
|
||||||
* @param {function} callbacks.onChooseConflicts
|
* @param {function} callbacks.onChooseConflicts
|
||||||
* @param {function} callbacks.onCancel
|
* @param {function} callbacks.onCancel
|
||||||
*/
|
*/
|
||||||
checkExistingFiles: function (selection, callbacks){
|
checkExistingFiles: function (selection, callbacks) {
|
||||||
// TODO check filelist before uploading and show dialog on conflicts, use callbacks
|
// TODO check filelist before uploading and show dialog on conflicts, use callbacks
|
||||||
callbacks.onNoConflicts(selection);
|
callbacks.onNoConflicts(selection);
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ $(document).ready(function() {
|
||||||
var selection = data.originalFiles.selection;
|
var selection = data.originalFiles.selection;
|
||||||
|
|
||||||
// add uploads
|
// add uploads
|
||||||
if ( selection.uploads.length < selection.filesToUpload ){
|
if ( selection.uploads.length < selection.filesToUpload ) {
|
||||||
// remember upload
|
// remember upload
|
||||||
selection.uploads.push(data);
|
selection.uploads.push(data);
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
delete data.jqXHR;
|
delete data.jqXHR;
|
||||||
|
|
||||||
if(typeof result[0] === 'undefined') {
|
if (typeof result[0] === 'undefined') {
|
||||||
data.textStatus = 'servererror';
|
data.textStatus = 'servererror';
|
||||||
data.errorThrown = t('files', 'Could not get result from server.');
|
data.errorThrown = t('files', 'Could not get result from server.');
|
||||||
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
|
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
|
||||||
|
@ -368,13 +368,13 @@ $(document).ready(function() {
|
||||||
var fileupload = $('#file_upload_start').fileupload(file_upload_param);
|
var fileupload = $('#file_upload_start').fileupload(file_upload_param);
|
||||||
window.file_upload_param = fileupload;
|
window.file_upload_param = fileupload;
|
||||||
|
|
||||||
if(supportAjaxUploadWithProgress()) {
|
if (supportAjaxUploadWithProgress()) {
|
||||||
|
|
||||||
// add progress handlers
|
// add progress handlers
|
||||||
fileupload.on('fileuploadadd', function(e, data) {
|
fileupload.on('fileuploadadd', function(e, data) {
|
||||||
OC.Upload.log('progress handle fileuploadadd', e, data);
|
OC.Upload.log('progress handle fileuploadadd', e, data);
|
||||||
//show cancel button
|
//show cancel button
|
||||||
//if(data.dataType !== 'iframe') { //FIXME when is iframe used? only for ie?
|
//if (data.dataType !== 'iframe') { //FIXME when is iframe used? only for ie?
|
||||||
// $('#uploadprogresswrapper input.stop').show();
|
// $('#uploadprogresswrapper input.stop').show();
|
||||||
//}
|
//}
|
||||||
});
|
});
|
||||||
|
@ -419,7 +419,9 @@ $(document).ready(function() {
|
||||||
// http://stackoverflow.com/a/6700/11236
|
// http://stackoverflow.com/a/6700/11236
|
||||||
var size = 0, key;
|
var size = 0, key;
|
||||||
for (key in obj) {
|
for (key in obj) {
|
||||||
if (obj.hasOwnProperty(key)) size++;
|
if (obj.hasOwnProperty(key)) {
|
||||||
|
size++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
};
|
};
|
||||||
|
@ -432,56 +434,61 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
//add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
|
//add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
|
||||||
if(navigator.userAgent.search(/konqueror/i)==-1){
|
if (navigator.userAgent.search(/konqueror/i) === -1) {
|
||||||
$('#file_upload_start').attr('multiple','multiple');
|
$('#file_upload_start').attr('multiple', 'multiple');
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder
|
//if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder
|
||||||
var crumb=$('div.crumb').first();
|
var crumb=$('div.crumb').first();
|
||||||
while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){
|
while($('div.controls').height() > 40 && crumb.next('div.crumb').length > 0) {
|
||||||
crumb.children('a').text('...');
|
crumb.children('a').text('...');
|
||||||
crumb=crumb.next('div.crumb');
|
crumb = crumb.next('div.crumb');
|
||||||
}
|
}
|
||||||
//if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent
|
//if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent
|
||||||
var crumb=$('div.crumb').first();
|
var crumb = $('div.crumb').first();
|
||||||
var next=crumb.next('div.crumb');
|
var next = crumb.next('div.crumb');
|
||||||
while($('div.controls').height()>40 && next.next('div.crumb').length>0){
|
while($('div.controls').height()>40 && next.next('div.crumb').length > 0) {
|
||||||
crumb.remove();
|
crumb.remove();
|
||||||
crumb=next;
|
crumb = next;
|
||||||
next=crumb.next('div.crumb');
|
next = crumb.next('div.crumb');
|
||||||
}
|
}
|
||||||
//still not enough, start shorting down the current folder name
|
//still not enough, start shorting down the current folder name
|
||||||
var crumb=$('div.crumb>a').last();
|
var crumb=$('div.crumb>a').last();
|
||||||
while($('div.controls').height()>40 && crumb.text().length>6){
|
while($('div.controls').height() > 40 && crumb.text().length > 6) {
|
||||||
var text=crumb.text()
|
var text=crumb.text();
|
||||||
text=text.substr(0,text.length-6)+'...';
|
text = text.substr(0,text.length-6)+'...';
|
||||||
crumb.text(text);
|
crumb.text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).click(function(){
|
$(document).click(function() {
|
||||||
$('#new>ul').hide();
|
$('#new>ul').hide();
|
||||||
$('#new').removeClass('active');
|
$('#new').removeClass('active');
|
||||||
$('#new li').each(function(i,element){
|
if ($('#new .error').length > 0) {
|
||||||
if($(element).children('p').length==0){
|
$('#new .error').tipsy('hide');
|
||||||
|
}
|
||||||
|
$('#new li').each(function(i,element) {
|
||||||
|
if ($(element).children('p').length === 0) {
|
||||||
$(element).children('form').remove();
|
$(element).children('form').remove();
|
||||||
$(element).append('<p>'+$(element).data('text')+'</p>');
|
$(element).append('<p>'+$(element).data('text')+'</p>');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$('#new').click(function(event){
|
$('#new').click(function(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
});
|
});
|
||||||
$('#new>a').click(function(){
|
$('#new>a').click(function() {
|
||||||
$('#new>ul').toggle();
|
$('#new>ul').toggle();
|
||||||
$('#new').toggleClass('active');
|
$('#new').toggleClass('active');
|
||||||
});
|
});
|
||||||
$('#new li').click(function(){
|
$('#new li').click(function() {
|
||||||
if($(this).children('p').length==0){
|
if ($(this).children('p').length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#new .error').tipsy('hide');
|
||||||
|
|
||||||
$('#new li').each(function(i,element){
|
$('#new li').each(function(i,element) {
|
||||||
if($(element).children('p').length==0){
|
if ($(element).children('p').length === 0) {
|
||||||
$(element).children('form').remove();
|
$(element).children('form').remove();
|
||||||
$(element).append('<p>'+$(element).data('text')+'</p>');
|
$(element).append('<p>'+$(element).data('text')+'</p>');
|
||||||
}
|
}
|
||||||
|
@ -491,132 +498,164 @@ $(document).ready(function() {
|
||||||
var text=$(this).children('p').text();
|
var text=$(this).children('p').text();
|
||||||
$(this).data('text',text);
|
$(this).data('text',text);
|
||||||
$(this).children('p').remove();
|
$(this).children('p').remove();
|
||||||
|
|
||||||
|
// add input field
|
||||||
var form=$('<form></form>');
|
var form=$('<form></form>');
|
||||||
var input=$('<input type="text">');
|
var input=$('<input type="text">');
|
||||||
form.append(input);
|
form.append(input);
|
||||||
$(this).append(form);
|
$(this).append(form);
|
||||||
|
|
||||||
|
var checkInput = function () {
|
||||||
|
var filename = input.val();
|
||||||
|
if (type === 'web' && filename.length === 0) {
|
||||||
|
throw t('files', 'URL cannot be empty.');
|
||||||
|
} else if (type !== 'web' && !Files.isFileNameValid(filename)) {
|
||||||
|
// Files.isFileNameValid(filename) throws an exception itself
|
||||||
|
} else if ($('#dir').val() === '/' && filename === 'Shared') {
|
||||||
|
throw t('files','Invalid name. Usage of \'Shared\' is reserved by ownCloud');
|
||||||
|
} else if (FileList.inList(filename)) {
|
||||||
|
throw t('files', '{new_name} already exists', {new_name: filename});
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// verify filename on typing
|
||||||
|
input.keyup(function(event) {
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
input.focus();
|
input.focus();
|
||||||
form.submit(function(event){
|
form.submit(function(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var newname=input.val();
|
try {
|
||||||
if(type == 'web' && newname.length == 0) {
|
checkInput();
|
||||||
OC.Notification.show(t('files', 'URL cannot be empty.'));
|
var newname = input.val();
|
||||||
return false;
|
if (FileList.lastAction) {
|
||||||
} else if (type != 'web' && !Files.isFileNameValid(newname)) {
|
FileList.lastAction();
|
||||||
return false;
|
}
|
||||||
} else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') {
|
var name = getUniqueName(newname);
|
||||||
OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by ownCloud'));
|
if (newname !== name) {
|
||||||
return false;
|
FileList.checkName(name, newname, true);
|
||||||
}
|
var hidden = true;
|
||||||
if (FileList.lastAction) {
|
} else {
|
||||||
FileList.lastAction();
|
var hidden = false;
|
||||||
}
|
}
|
||||||
var name = getUniqueName(newname);
|
switch(type) {
|
||||||
if (newname != name) {
|
case 'file':
|
||||||
FileList.checkName(name, newname, true);
|
$.post(
|
||||||
var hidden = true;
|
OC.filePath('files', 'ajax', 'newfile.php'),
|
||||||
} else {
|
{dir:$('#dir').val(), filename:name},
|
||||||
var hidden = false;
|
function(result) {
|
||||||
}
|
if (result.status === 'success') {
|
||||||
switch(type){
|
var date = new Date();
|
||||||
case 'file':
|
// TODO: ideally addFile should be able to receive
|
||||||
$.post(
|
// all attributes and set them automatically,
|
||||||
OC.filePath('files','ajax','newfile.php'),
|
// and also auto-load the preview
|
||||||
{dir:$('#dir').val(),filename:name},
|
var tr = FileList.addFile(name, 0, date, false, hidden);
|
||||||
function(result){
|
tr.attr('data-size', result.data.size);
|
||||||
if (result.status == 'success') {
|
tr.attr('data-mime', result.data.mime);
|
||||||
var date=new Date();
|
tr.attr('data-id', result.data.id);
|
||||||
// TODO: ideally addFile should be able to receive
|
tr.find('.filesize').text(humanFileSize(result.data.size));
|
||||||
// all attributes and set them automatically,
|
var path = getPathForPreview(name);
|
||||||
// and also auto-load the preview
|
lazyLoadPreview(path, result.data.mime, function(previewpath) {
|
||||||
var tr = FileList.addFile(name,0,date,false,hidden);
|
tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
||||||
tr.attr('data-size',result.data.size);
|
});
|
||||||
tr.attr('data-mime',result.data.mime);
|
FileActions.display(tr.find('td.filename'), true);
|
||||||
tr.attr('data-id', result.data.id);
|
} else {
|
||||||
tr.find('.filesize').text(humanFileSize(result.data.size));
|
OC.dialogs.alert(result.data.message, t('core', 'Could not create file'));
|
||||||
var path = getPathForPreview(name);
|
}
|
||||||
lazyLoadPreview(path, result.data.mime, function(previewpath){
|
|
||||||
tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
|
||||||
});
|
|
||||||
FileActions.display(tr.find('td.filename'), true);
|
|
||||||
} else {
|
|
||||||
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
break;
|
||||||
break;
|
case 'folder':
|
||||||
case 'folder':
|
$.post(
|
||||||
$.post(
|
OC.filePath('files','ajax','newfolder.php'),
|
||||||
OC.filePath('files','ajax','newfolder.php'),
|
{dir:$('#dir').val(), foldername:name},
|
||||||
{dir:$('#dir').val(),foldername:name},
|
function(result) {
|
||||||
function(result){
|
if (result.status === 'success') {
|
||||||
if (result.status == 'success') {
|
var date=new Date();
|
||||||
var date=new Date();
|
FileList.addDir(name, 0, date, hidden);
|
||||||
FileList.addDir(name,0,date,hidden);
|
var tr=$('tr[data-file="'+name+'"]');
|
||||||
var tr=$('tr').filterAttr('data-file',name);
|
tr.attr('data-id', result.data.id);
|
||||||
tr.attr('data-id', result.data.id);
|
} else {
|
||||||
} else {
|
OC.dialogs.alert(result.data.message, t('core', 'Could not create folder'));
|
||||||
OC.dialogs.alert(result.data.message, t('core', 'Error'));
|
}
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'web':
|
||||||
|
if (name.substr(0,8) !== 'https://' && name.substr(0,7) !== 'http://') {
|
||||||
|
name = 'http://' + name;
|
||||||
}
|
}
|
||||||
);
|
var localName=name;
|
||||||
break;
|
if (localName.substr(localName.length-1,1)==='/') {//strip /
|
||||||
case 'web':
|
localName=localName.substr(0,localName.length-1);
|
||||||
if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){
|
}
|
||||||
name='http://'+name;
|
if (localName.indexOf('/')) {//use last part of url
|
||||||
}
|
localName=localName.split('/').pop();
|
||||||
var localName=name;
|
} else { //or the domain
|
||||||
if(localName.substr(localName.length-1,1)=='/'){//strip /
|
localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.','');
|
||||||
localName=localName.substr(0,localName.length-1)
|
}
|
||||||
}
|
localName = getUniqueName(localName);
|
||||||
if(localName.indexOf('/')){//use last part of url
|
|
||||||
localName=localName.split('/').pop();
|
|
||||||
} else { //or the domain
|
|
||||||
localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.','');
|
|
||||||
}
|
|
||||||
localName = getUniqueName(localName);
|
|
||||||
//IE < 10 does not fire the necessary events for the progress bar.
|
|
||||||
if($('html.lte9').length === 0) {
|
|
||||||
$('#uploadprogressbar').progressbar({value:0});
|
|
||||||
$('#uploadprogressbar').fadeIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName});
|
|
||||||
eventSource.listen('progress',function(progress){
|
|
||||||
//IE < 10 does not fire the necessary events for the progress bar.
|
//IE < 10 does not fire the necessary events for the progress bar.
|
||||||
if($('html.lte9').length === 0) {
|
if ($('html.lte9').length === 0) {
|
||||||
$('#uploadprogressbar').progressbar('value',progress);
|
$('#uploadprogressbar').progressbar({value:0});
|
||||||
|
$('#uploadprogressbar').fadeIn();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
eventSource.listen('success',function(data){
|
var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName});
|
||||||
var mime=data.mime;
|
eventSource.listen('progress',function(progress) {
|
||||||
var size=data.size;
|
//IE < 10 does not fire the necessary events for the progress bar.
|
||||||
var id=data.id;
|
if ($('html.lte9').length === 0) {
|
||||||
$('#uploadprogressbar').fadeOut();
|
$('#uploadprogressbar').progressbar('value',progress);
|
||||||
var date=new Date();
|
}
|
||||||
FileList.addFile(localName,size,date,false,hidden);
|
|
||||||
var tr=$('tr').filterAttr('data-file',localName);
|
|
||||||
tr.data('mime',mime).data('id',id);
|
|
||||||
tr.attr('data-id', id);
|
|
||||||
var path = $('#dir').val()+'/'+localName;
|
|
||||||
lazyLoadPreview(path, mime, function(previewpath){
|
|
||||||
tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
|
||||||
});
|
});
|
||||||
});
|
eventSource.listen('success',function(data) {
|
||||||
eventSource.listen('error',function(error){
|
var mime = data.mime;
|
||||||
$('#uploadprogressbar').fadeOut();
|
var size = data.size;
|
||||||
alert(error);
|
var id = data.id;
|
||||||
});
|
$('#uploadprogressbar').fadeOut();
|
||||||
break;
|
var date = new Date();
|
||||||
|
FileList.addFile(localName, size, date, false, hidden);
|
||||||
|
var tr = $('tr[data-file="'+localName+'"]');
|
||||||
|
tr.data('mime', mime).data('id', id);
|
||||||
|
tr.attr('data-id', id);
|
||||||
|
var path = $('#dir').val()+'/'+localName;
|
||||||
|
lazyLoadPreview(path, mime, function(previewpath) {
|
||||||
|
tr.find('td.filename').attr('style', 'background-image:url('+previewpath+')');
|
||||||
|
});
|
||||||
|
FileActions.display(tr.find('td.filename'), true);
|
||||||
|
});
|
||||||
|
eventSource.listen('error',function(error) {
|
||||||
|
$('#uploadprogressbar').fadeOut();
|
||||||
|
alert(error);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var li=form.parent();
|
||||||
|
form.remove();
|
||||||
|
/* workaround for IE 9&10 click event trap, 2 lines: */
|
||||||
|
$('input').first().focus();
|
||||||
|
$('#content').focus();
|
||||||
|
li.append('<p>'+li.data('text')+'</p>');
|
||||||
|
$('#new>a').click();
|
||||||
|
} catch (error) {
|
||||||
|
input.attr('title', error);
|
||||||
|
input.tipsy({gravity: 'w', trigger: 'manual'});
|
||||||
|
input.tipsy('show');
|
||||||
|
input.addClass('error');
|
||||||
}
|
}
|
||||||
var li=form.parent();
|
|
||||||
form.remove();
|
|
||||||
/* workaround for IE 9&10 click event trap, 2 lines: */
|
|
||||||
$('input').first().focus();
|
|
||||||
$('#content').focus();
|
|
||||||
li.append('<p>'+li.data('text')+'</p>');
|
|
||||||
$('#new>a').click();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
window.file_upload_param = file_upload_param;
|
window.file_upload_param = file_upload_param;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
var FileList={
|
var FileList={
|
||||||
useUndo:true,
|
useUndo:true,
|
||||||
postProcessList: function(){
|
postProcessList: function() {
|
||||||
$('#fileList tr').each(function(){
|
$('#fileList tr').each(function() {
|
||||||
//little hack to set unescape filenames in attribute
|
//little hack to set unescape filenames in attribute
|
||||||
$(this).attr('data-file',decodeURIComponent($(this).attr('data-file')));
|
$(this).attr('data-file',decodeURIComponent($(this).attr('data-file')));
|
||||||
});
|
});
|
||||||
|
@ -11,20 +11,20 @@ var FileList={
|
||||||
permissions = $('#permissions').val(),
|
permissions = $('#permissions').val(),
|
||||||
isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
||||||
$fileList.empty().html(fileListHtml);
|
$fileList.empty().html(fileListHtml);
|
||||||
$('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').length > 0);
|
$('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').exists());
|
||||||
$fileList.find('tr').each(function () {
|
$fileList.find('tr').each(function () {
|
||||||
FileActions.display($(this).children('td.filename'));
|
FileActions.display($(this).children('td.filename'));
|
||||||
});
|
});
|
||||||
$fileList.trigger(jQuery.Event("fileActionsReady"));
|
$fileList.trigger(jQuery.Event("fileActionsReady"));
|
||||||
FileList.postProcessList();
|
FileList.postProcessList();
|
||||||
// "Files" might not be loaded in extending apps
|
// "Files" might not be loaded in extending apps
|
||||||
if (window.Files){
|
if (window.Files) {
|
||||||
Files.setupDragAndDrop();
|
Files.setupDragAndDrop();
|
||||||
}
|
}
|
||||||
FileList.updateFileSummary();
|
FileList.updateFileSummary();
|
||||||
$fileList.trigger(jQuery.Event("updated"));
|
$fileList.trigger(jQuery.Event("updated"));
|
||||||
},
|
},
|
||||||
createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions){
|
createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions) {
|
||||||
var td, simpleSize, basename, extension;
|
var td, simpleSize, basename, extension;
|
||||||
//containing tr
|
//containing tr
|
||||||
var tr = $('<tr></tr>').attr({
|
var tr = $('<tr></tr>').attr({
|
||||||
|
@ -45,7 +45,7 @@ var FileList={
|
||||||
"href": linktarget
|
"href": linktarget
|
||||||
});
|
});
|
||||||
//split extension from filename for non dirs
|
//split extension from filename for non dirs
|
||||||
if (type != 'dir' && name.indexOf('.')!=-1) {
|
if (type !== 'dir' && name.indexOf('.') !== -1) {
|
||||||
basename=name.substr(0,name.lastIndexOf('.'));
|
basename=name.substr(0,name.lastIndexOf('.'));
|
||||||
extension=name.substr(name.lastIndexOf('.'));
|
extension=name.substr(name.lastIndexOf('.'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,11 +54,11 @@ var FileList={
|
||||||
}
|
}
|
||||||
var name_span=$('<span></span>').addClass('nametext').text(basename);
|
var name_span=$('<span></span>').addClass('nametext').text(basename);
|
||||||
link_elem.append(name_span);
|
link_elem.append(name_span);
|
||||||
if(extension){
|
if (extension) {
|
||||||
name_span.append($('<span></span>').addClass('extension').text(extension));
|
name_span.append($('<span></span>').addClass('extension').text(extension));
|
||||||
}
|
}
|
||||||
//dirs can show the number of uploaded files
|
//dirs can show the number of uploaded files
|
||||||
if (type == 'dir') {
|
if (type === 'dir') {
|
||||||
link_elem.append($('<span></span>').attr({
|
link_elem.append($('<span></span>').attr({
|
||||||
'class': 'uploadtext',
|
'class': 'uploadtext',
|
||||||
'currentUploads': 0
|
'currentUploads': 0
|
||||||
|
@ -68,9 +68,9 @@ var FileList={
|
||||||
tr.append(td);
|
tr.append(td);
|
||||||
|
|
||||||
//size column
|
//size column
|
||||||
if(size!=t('files', 'Pending')){
|
if (size !== t('files', 'Pending')) {
|
||||||
simpleSize = humanFileSize(size);
|
simpleSize = humanFileSize(size);
|
||||||
}else{
|
} else {
|
||||||
simpleSize=t('files', 'Pending');
|
simpleSize=t('files', 'Pending');
|
||||||
}
|
}
|
||||||
var sizeColor = Math.round(160-Math.pow((size/(1024*1024)),2));
|
var sizeColor = Math.round(160-Math.pow((size/(1024*1024)),2));
|
||||||
|
@ -92,7 +92,7 @@ var FileList={
|
||||||
tr.append(td);
|
tr.append(td);
|
||||||
return tr;
|
return tr;
|
||||||
},
|
},
|
||||||
addFile:function(name,size,lastModified,loading,hidden,param){
|
addFile:function(name, size, lastModified, loading, hidden, param) {
|
||||||
var imgurl;
|
var imgurl;
|
||||||
|
|
||||||
if (!param) {
|
if (!param) {
|
||||||
|
@ -122,9 +122,9 @@ var FileList={
|
||||||
);
|
);
|
||||||
|
|
||||||
FileList.insertElement(name, 'file', tr);
|
FileList.insertElement(name, 'file', tr);
|
||||||
if(loading){
|
if (loading) {
|
||||||
tr.data('loading',true);
|
tr.data('loading', true);
|
||||||
}else{
|
} else {
|
||||||
tr.find('td.filename').draggable(dragOptions);
|
tr.find('td.filename').draggable(dragOptions);
|
||||||
}
|
}
|
||||||
if (hidden) {
|
if (hidden) {
|
||||||
|
@ -132,7 +132,7 @@ var FileList={
|
||||||
}
|
}
|
||||||
return tr;
|
return tr;
|
||||||
},
|
},
|
||||||
addDir:function(name,size,lastModified,hidden){
|
addDir:function(name, size, lastModified, hidden) {
|
||||||
|
|
||||||
var tr = this.createRow(
|
var tr = this.createRow(
|
||||||
'dir',
|
'dir',
|
||||||
|
@ -144,7 +144,7 @@ var FileList={
|
||||||
$('#permissions').val()
|
$('#permissions').val()
|
||||||
);
|
);
|
||||||
|
|
||||||
FileList.insertElement(name,'dir',tr);
|
FileList.insertElement(name, 'dir', tr);
|
||||||
var td = tr.find('td.filename');
|
var td = tr.find('td.filename');
|
||||||
td.draggable(dragOptions);
|
td.draggable(dragOptions);
|
||||||
td.droppable(folderDropOptions);
|
td.droppable(folderDropOptions);
|
||||||
|
@ -158,25 +158,26 @@ var FileList={
|
||||||
* @brief Changes the current directory and reload the file list.
|
* @brief Changes the current directory and reload the file list.
|
||||||
* @param targetDir target directory (non URL encoded)
|
* @param targetDir target directory (non URL encoded)
|
||||||
* @param changeUrl false if the URL must not be changed (defaults to true)
|
* @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){
|
changeDirectory: function(targetDir, changeUrl, force) {
|
||||||
var $dir = $('#dir'),
|
var $dir = $('#dir'),
|
||||||
url,
|
url,
|
||||||
currentDir = $dir.val() || '/';
|
currentDir = $dir.val() || '/';
|
||||||
targetDir = targetDir || '/';
|
targetDir = targetDir || '/';
|
||||||
if (!force && currentDir === targetDir){
|
if (!force && currentDir === targetDir) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileList.setCurrentDir(targetDir, changeUrl);
|
FileList.setCurrentDir(targetDir, changeUrl);
|
||||||
FileList.reload();
|
FileList.reload();
|
||||||
},
|
},
|
||||||
linkTo: function(dir){
|
linkTo: function(dir) {
|
||||||
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
|
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
|
||||||
},
|
},
|
||||||
setCurrentDir: function(targetDir, changeUrl){
|
setCurrentDir: function(targetDir, changeUrl) {
|
||||||
$('#dir').val(targetDir);
|
$('#dir').val(targetDir);
|
||||||
if (changeUrl !== false){
|
if (changeUrl !== false) {
|
||||||
if (window.history.pushState && changeUrl !== false){
|
if (window.history.pushState && changeUrl !== false) {
|
||||||
url = FileList.linkTo(targetDir);
|
url = FileList.linkTo(targetDir);
|
||||||
window.history.pushState({dir: targetDir}, '', url);
|
window.history.pushState({dir: targetDir}, '', url);
|
||||||
}
|
}
|
||||||
|
@ -189,9 +190,9 @@ var FileList={
|
||||||
/**
|
/**
|
||||||
* @brief Reloads the file list using ajax call
|
* @brief Reloads the file list using ajax call
|
||||||
*/
|
*/
|
||||||
reload: function(){
|
reload: function() {
|
||||||
FileList.showMask();
|
FileList.showMask();
|
||||||
if (FileList._reloadCall){
|
if (FileList._reloadCall) {
|
||||||
FileList._reloadCall.abort();
|
FileList._reloadCall.abort();
|
||||||
}
|
}
|
||||||
FileList._reloadCall = $.ajax({
|
FileList._reloadCall = $.ajax({
|
||||||
|
@ -200,7 +201,7 @@ var FileList={
|
||||||
dir : $('#dir').val(),
|
dir : $('#dir').val(),
|
||||||
breadcrumb: true
|
breadcrumb: true
|
||||||
},
|
},
|
||||||
error: function(result){
|
error: function(result) {
|
||||||
FileList.reloadCallback(result);
|
FileList.reloadCallback(result);
|
||||||
},
|
},
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
|
@ -208,7 +209,7 @@ var FileList={
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
reloadCallback: function(result){
|
reloadCallback: function(result) {
|
||||||
var $controls = $('#controls');
|
var $controls = $('#controls');
|
||||||
|
|
||||||
delete FileList._reloadCall;
|
delete FileList._reloadCall;
|
||||||
|
@ -219,17 +220,17 @@ var FileList={
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.status === 404){
|
if (result.status === 404) {
|
||||||
// go back home
|
// go back home
|
||||||
FileList.changeDirectory('/');
|
FileList.changeDirectory('/');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.data.permissions){
|
if (result.data.permissions) {
|
||||||
FileList.setDirectoryPermissions(result.data.permissions);
|
FileList.setDirectoryPermissions(result.data.permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof(result.data.breadcrumb) != 'undefined'){
|
if (typeof(result.data.breadcrumb) !== 'undefined') {
|
||||||
$controls.find('.crumb').remove();
|
$controls.find('.crumb').remove();
|
||||||
$controls.prepend(result.data.breadcrumb);
|
$controls.prepend(result.data.breadcrumb);
|
||||||
|
|
||||||
|
@ -238,81 +239,83 @@ var FileList={
|
||||||
Files.resizeBreadcrumbs(width, true);
|
Files.resizeBreadcrumbs(width, true);
|
||||||
|
|
||||||
// in case svg is not supported by the browser we need to execute the fallback mechanism
|
// in case svg is not supported by the browser we need to execute the fallback mechanism
|
||||||
if(!SVGSupport()) {
|
if (!SVGSupport()) {
|
||||||
replaceSVG();
|
replaceSVG();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileList.update(result.data.files);
|
FileList.update(result.data.files);
|
||||||
},
|
},
|
||||||
setDirectoryPermissions: function(permissions){
|
setDirectoryPermissions: function(permissions) {
|
||||||
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
||||||
$('#permissions').val(permissions);
|
$('#permissions').val(permissions);
|
||||||
$('.creatable').toggleClass('hidden', !isCreatable);
|
$('.creatable').toggleClass('hidden', !isCreatable);
|
||||||
$('.notCreatable').toggleClass('hidden', isCreatable);
|
$('.notCreatable').toggleClass('hidden', isCreatable);
|
||||||
},
|
},
|
||||||
remove:function(name){
|
remove:function(name) {
|
||||||
$('tr').filterAttr('data-file',name).find('td.filename').draggable('destroy');
|
$('tr[data-file="'+name+'"]').find('td.filename').draggable('destroy');
|
||||||
$('tr').filterAttr('data-file',name).remove();
|
$('tr[data-file="'+name+'"]').remove();
|
||||||
FileList.updateFileSummary();
|
FileList.updateFileSummary();
|
||||||
if($('tr[data-file]').length==0){
|
if ( ! $('tr[data-file]').exists() ) {
|
||||||
$('#emptycontent').removeClass('hidden');
|
$('#emptycontent').removeClass('hidden');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
insertElement:function(name,type,element){
|
insertElement:function(name, type, element) {
|
||||||
//find the correct spot to insert the file or folder
|
//find the correct spot to insert the file or folder
|
||||||
var pos, fileElements=$('tr[data-file][data-type="'+type+'"]:visible');
|
var pos, fileElements=$('tr[data-file][data-type="'+type+'"]:visible');
|
||||||
if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){
|
if (name.localeCompare($(fileElements[0]).attr('data-file')) < 0) {
|
||||||
pos=-1;
|
pos = -1;
|
||||||
}else if(name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file'))>0){
|
} else if (name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file')) > 0) {
|
||||||
pos=fileElements.length-1;
|
pos = fileElements.length - 1;
|
||||||
}else{
|
} else {
|
||||||
for(pos=0;pos<fileElements.length-1;pos++){
|
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){
|
if (name.localeCompare($(fileElements[pos]).attr('data-file')) > 0
|
||||||
|
&& name.localeCompare($(fileElements[pos+1]).attr('data-file')) < 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(fileElements.length){
|
if (fileElements.exists()) {
|
||||||
if(pos==-1){
|
if (pos === -1) {
|
||||||
$(fileElements[0]).before(element);
|
$(fileElements[0]).before(element);
|
||||||
}else{
|
} else {
|
||||||
$(fileElements[pos]).after(element);
|
$(fileElements[pos]).after(element);
|
||||||
}
|
}
|
||||||
}else if(type=='dir' && $('tr[data-file]').length>0){
|
} else if (type === 'dir' && $('tr[data-file]').exists()) {
|
||||||
$('tr[data-file]').first().before(element);
|
$('tr[data-file]').first().before(element);
|
||||||
} else if(type=='file' && $('tr[data-file]').length>0) {
|
} else if (type === 'file' && $('tr[data-file]').exists()) {
|
||||||
$('tr[data-file]').last().before(element);
|
$('tr[data-file]').last().before(element);
|
||||||
}else{
|
} else {
|
||||||
$('#fileList').append(element);
|
$('#fileList').append(element);
|
||||||
}
|
}
|
||||||
$('#emptycontent').addClass('hidden');
|
$('#emptycontent').addClass('hidden');
|
||||||
FileList.updateFileSummary();
|
FileList.updateFileSummary();
|
||||||
},
|
},
|
||||||
loadingDone:function(name, id){
|
loadingDone:function(name, id) {
|
||||||
var mime, tr=$('tr').filterAttr('data-file',name);
|
var mime, tr = $('tr[data-file="'+name+'"]');
|
||||||
tr.data('loading',false);
|
tr.data('loading', false);
|
||||||
mime=tr.data('mime');
|
mime = tr.data('mime');
|
||||||
tr.attr('data-mime',mime);
|
tr.attr('data-mime', mime);
|
||||||
if (id != null) {
|
if (id) {
|
||||||
tr.attr('data-id', id);
|
tr.attr('data-id', id);
|
||||||
}
|
}
|
||||||
var path = getPathForPreview(name);
|
var path = getPathForPreview(name);
|
||||||
lazyLoadPreview(path, mime, function(previewpath){
|
lazyLoadPreview(path, mime, function(previewpath) {
|
||||||
tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
||||||
});
|
});
|
||||||
tr.find('td.filename').draggable(dragOptions);
|
tr.find('td.filename').draggable(dragOptions);
|
||||||
},
|
},
|
||||||
isLoading:function(name){
|
isLoading:function(name) {
|
||||||
return $('tr').filterAttr('data-file',name).data('loading');
|
return $('tr[data-file="'+name+'"]').data('loading');
|
||||||
},
|
},
|
||||||
rename:function(name){
|
rename:function(oldname) {
|
||||||
var tr, td, input, form;
|
var tr, td, input, form;
|
||||||
tr=$('tr').filterAttr('data-file',name);
|
tr = $('tr[data-file="'+oldname+'"]');
|
||||||
tr.data('renaming',true);
|
tr.data('renaming',true);
|
||||||
td=tr.children('td.filename');
|
td = tr.children('td.filename');
|
||||||
input=$('<input type="text" class="filename"/>').val(name);
|
input = $('<input type="text" class="filename"/>').val(oldname);
|
||||||
form=$('<form></form>');
|
form = $('<form></form>');
|
||||||
form.append(input);
|
form.append(input);
|
||||||
td.children('a.name').hide();
|
td.children('a.name').hide();
|
||||||
td.append(form);
|
td.append(form);
|
||||||
|
@ -322,18 +325,29 @@ var FileList={
|
||||||
if (len === -1) {
|
if (len === -1) {
|
||||||
len = input.val().length;
|
len = input.val().length;
|
||||||
}
|
}
|
||||||
input.selectRange(0,len);
|
input.selectRange(0, len);
|
||||||
|
|
||||||
form.submit(function(event){
|
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','Invalid name. Usage of \'Shared\' is reserved by ownCloud');
|
||||||
|
} else if (FileList.inList(filename)) {
|
||||||
|
throw t('files', '{new_name} already exists', {new_name: filename});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
form.submit(function(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var newname=input.val();
|
try {
|
||||||
if (!Files.isFileNameValid(newname)) {
|
var newname = input.val();
|
||||||
return false;
|
if (newname !== oldname) {
|
||||||
} else if (newname != name) {
|
checkInput();
|
||||||
if (FileList.checkName(name, newname, false)) {
|
|
||||||
newname = name;
|
|
||||||
} else {
|
|
||||||
// save background image, because it's replaced by a spinner while async request
|
// save background image, because it's replaced by a spinner while async request
|
||||||
var oldBackgroundImage = td.css('background-image');
|
var oldBackgroundImage = td.css('background-image');
|
||||||
// mark as loading
|
// mark as loading
|
||||||
|
@ -343,16 +357,16 @@ var FileList={
|
||||||
data: {
|
data: {
|
||||||
dir : $('#dir').val(),
|
dir : $('#dir').val(),
|
||||||
newname: newname,
|
newname: newname,
|
||||||
file: name
|
file: oldname
|
||||||
},
|
},
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
if (!result || result.status === 'error') {
|
if (!result || result.status === 'error') {
|
||||||
OC.Notification.show(result.data.message);
|
OC.dialogs.alert(result.data.message, t('core', 'Could not rename file'));
|
||||||
newname = name;
|
|
||||||
// revert changes
|
// revert changes
|
||||||
|
newname = oldname;
|
||||||
tr.attr('data-file', newname);
|
tr.attr('data-file', newname);
|
||||||
var path = td.children('a.name').attr('href');
|
var path = td.children('a.name').attr('href');
|
||||||
td.children('a.name').attr('href', path.replace(encodeURIComponent(name), encodeURIComponent(newname)));
|
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
|
||||||
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
||||||
var basename=newname.substr(0,newname.lastIndexOf('.'));
|
var basename=newname.substr(0,newname.lastIndexOf('.'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -360,7 +374,7 @@ var FileList={
|
||||||
}
|
}
|
||||||
td.find('a.name span.nametext').text(basename);
|
td.find('a.name span.nametext').text(basename);
|
||||||
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
||||||
if (td.find('a.name span.extension').length === 0 ) {
|
if ( ! td.find('a.name span.extension').exists() ) {
|
||||||
td.find('a.name span.nametext').append('<span class="extension"></span>');
|
td.find('a.name span.nametext').append('<span class="extension"></span>');
|
||||||
}
|
}
|
||||||
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
|
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
|
||||||
|
@ -368,70 +382,76 @@ var FileList={
|
||||||
tr.find('.fileactions').effect('highlight', {}, 5000);
|
tr.find('.fileactions').effect('highlight', {}, 5000);
|
||||||
tr.effect('highlight', {}, 5000);
|
tr.effect('highlight', {}, 5000);
|
||||||
}
|
}
|
||||||
|
// reinsert row
|
||||||
|
tr.detach();
|
||||||
|
FileList.insertElement( tr.attr('data-file'), tr.attr('data-type'),tr );
|
||||||
// remove loading mark and recover old image
|
// remove loading mark and recover old image
|
||||||
td.css('background-image', oldBackgroundImage);
|
td.css('background-image', oldBackgroundImage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
input.tipsy('hide');
|
||||||
tr.data('renaming',false);
|
tr.data('renaming',false);
|
||||||
tr.attr('data-file', newname);
|
tr.attr('data-file', newname);
|
||||||
var path = td.children('a.name').attr('href');
|
var path = td.children('a.name').attr('href');
|
||||||
td.children('a.name').attr('href', path.replace(encodeURIComponent(name), encodeURIComponent(newname)));
|
// FIXME this will fail if the path contains the filename.
|
||||||
if (newname.indexOf('.') > 0 && tr.data('type') != 'dir') {
|
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
|
||||||
var basename=newname.substr(0,newname.lastIndexOf('.'));
|
var basename = newname;
|
||||||
} else {
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
||||||
var basename=newname;
|
basename = newname.substr(0, newname.lastIndexOf('.'));
|
||||||
}
|
}
|
||||||
td.find('a.name span.nametext').text(basename);
|
td.find('a.name span.nametext').text(basename);
|
||||||
if (newname.indexOf('.') > 0 && tr.data('type') != 'dir') {
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
||||||
if (td.find('a.name span.extension').length == 0 ) {
|
if ( ! td.find('a.name span.extension').exists() ) {
|
||||||
td.find('a.name span.nametext').append('<span class="extension"></span>');
|
td.find('a.name span.nametext').append('<span class="extension"></span>');
|
||||||
|
}
|
||||||
|
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
|
||||||
}
|
}
|
||||||
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
|
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');
|
||||||
}
|
}
|
||||||
form.remove();
|
|
||||||
td.children('a.name').show();
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
input.keyup(function(event){
|
input.keyup(function(event) {
|
||||||
if (event.keyCode == 27) {
|
// 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');
|
||||||
tr.data('renaming',false);
|
tr.data('renaming',false);
|
||||||
form.remove();
|
form.remove();
|
||||||
td.children('a.name').show();
|
td.children('a.name').show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
input.click(function(event){
|
input.click(function(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
input.blur(function(){
|
input.blur(function() {
|
||||||
form.trigger('submit');
|
form.trigger('submit');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
checkName:function(oldName, newName, isNewFile) {
|
inList:function(filename) {
|
||||||
if (isNewFile || $('tr').filterAttr('data-file', newName).length > 0) {
|
return $('#fileList tr[data-file="'+filename+'"]').length;
|
||||||
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>';
|
|
||||||
}else{
|
|
||||||
html = t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+'<span class="replace">'+t('files', 'replace')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>';
|
|
||||||
}
|
|
||||||
html = $('<span>' + html + '</span>');
|
|
||||||
html.attr('data-oldName', oldName);
|
|
||||||
html.attr('data-newName', newName);
|
|
||||||
html.attr('data-isNewFile', isNewFile);
|
|
||||||
OC.Notification.showHtml(html);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
replace:function(oldName, newName, isNewFile) {
|
replace:function(oldName, newName, isNewFile) {
|
||||||
// Finish any existing actions
|
// Finish any existing actions
|
||||||
$('tr').filterAttr('data-file', oldName).hide();
|
$('tr[data-file="'+oldName+'"]').hide();
|
||||||
$('tr').filterAttr('data-file', newName).hide();
|
$('tr[data-file="'+newName+'"]').hide();
|
||||||
var tr = $('tr').filterAttr('data-file', oldName).clone();
|
var tr = $('tr[data-file="'+oldName+'"]').clone();
|
||||||
tr.attr('data-replace', 'true');
|
tr.attr('data-replace', 'true');
|
||||||
tr.attr('data-file', newName);
|
tr.attr('data-file', newName);
|
||||||
var td = tr.children('td.filename');
|
var td = tr.children('td.filename');
|
||||||
|
@ -460,14 +480,14 @@ var FileList={
|
||||||
FileList.finishReplace();
|
FileList.finishReplace();
|
||||||
};
|
};
|
||||||
if (!isNewFile) {
|
if (!isNewFile) {
|
||||||
OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>');
|
OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+'<span class="undo">'+t('files', 'undo')+'</span>');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
finishReplace:function() {
|
finishReplace:function() {
|
||||||
if (!FileList.replaceCanceled && FileList.replaceOldName && FileList.replaceNewName) {
|
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) {
|
$.ajax({url: OC.filePath('files', 'ajax', 'rename.php'), async: false, data: { dir: $('#dir').val(), newname: FileList.replaceNewName, file: FileList.replaceOldName }, success: function(result) {
|
||||||
if (result && result.status == 'success') {
|
if (result && result.status === 'success') {
|
||||||
$('tr').filterAttr('data-replace', 'true').removeAttr('data-replace');
|
$('tr[data-replace="true"').removeAttr('data-replace');
|
||||||
} else {
|
} else {
|
||||||
OC.dialogs.alert(result.data.message, 'Error moving file');
|
OC.dialogs.alert(result.data.message, 'Error moving file');
|
||||||
}
|
}
|
||||||
|
@ -478,12 +498,12 @@ var FileList={
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
do_delete:function(files){
|
do_delete:function(files) {
|
||||||
if(files.substr){
|
if (files.substr) {
|
||||||
files=[files];
|
files=[files];
|
||||||
}
|
}
|
||||||
for (var i=0; i<files.length; i++) {
|
for (var i=0; i<files.length; i++) {
|
||||||
var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date").children(".action.delete");
|
var deleteAction = $('tr[data-file="'+files[i]+'"]').children("td.date").children(".action.delete");
|
||||||
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
||||||
}
|
}
|
||||||
// Finish any existing actions
|
// Finish any existing actions
|
||||||
|
@ -494,10 +514,10 @@ var FileList={
|
||||||
var fileNames = JSON.stringify(files);
|
var fileNames = JSON.stringify(files);
|
||||||
$.post(OC.filePath('files', 'ajax', 'delete.php'),
|
$.post(OC.filePath('files', 'ajax', 'delete.php'),
|
||||||
{dir:$('#dir').val(),files:fileNames},
|
{dir:$('#dir').val(),files:fileNames},
|
||||||
function(result){
|
function(result) {
|
||||||
if (result.status == 'success') {
|
if (result.status === 'success') {
|
||||||
$.each(files,function(index,file){
|
$.each(files,function(index,file) {
|
||||||
var files = $('tr').filterAttr('data-file',file);
|
var files = $('tr[data-file="'+file+'"]');
|
||||||
files.remove();
|
files.remove();
|
||||||
files.find('input[type="checkbox"]').removeAttr('checked');
|
files.find('input[type="checkbox"]').removeAttr('checked');
|
||||||
files.removeClass('selected');
|
files.removeClass('selected');
|
||||||
|
@ -507,14 +527,14 @@ var FileList={
|
||||||
FileList.updateFileSummary();
|
FileList.updateFileSummary();
|
||||||
} else {
|
} else {
|
||||||
$.each(files,function(index,file) {
|
$.each(files,function(index,file) {
|
||||||
var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date").children(".action.delete");
|
var deleteAction = $('tr[data-file="'+files[i]+'"]').children("td.date").children(".action.delete");
|
||||||
deleteAction.removeClass('progress-icon').addClass('delete-icon');
|
deleteAction.removeClass('progress-icon').addClass('delete-icon');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createFileSummary: function() {
|
createFileSummary: function() {
|
||||||
if( $('#fileList tr').length > 0 ) {
|
if ( $('#fileList tr').exists() ) {
|
||||||
var totalDirs = 0;
|
var totalDirs = 0;
|
||||||
var totalFiles = 0;
|
var totalFiles = 0;
|
||||||
var totalSize = 0;
|
var totalSize = 0;
|
||||||
|
@ -536,7 +556,7 @@ var FileList={
|
||||||
var infoVars = {
|
var infoVars = {
|
||||||
dirs: '<span class="dirinfo">'+directoryInfo+'</span><span class="connector">',
|
dirs: '<span class="dirinfo">'+directoryInfo+'</span><span class="connector">',
|
||||||
files: '</span><span class="fileinfo">'+fileInfo+'</span>'
|
files: '</span><span class="fileinfo">'+fileInfo+'</span>'
|
||||||
}
|
};
|
||||||
|
|
||||||
var info = t('files', '{dirs} and {files}', infoVars);
|
var info = t('files', '{dirs} and {files}', infoVars);
|
||||||
|
|
||||||
|
@ -618,10 +638,10 @@ var FileList={
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showMask: function(){
|
showMask: function() {
|
||||||
// in case one was shown before
|
// in case one was shown before
|
||||||
var $mask = $('#content .mask');
|
var $mask = $('#content .mask');
|
||||||
if ($mask.length){
|
if ($mask.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,31 +652,31 @@ var FileList={
|
||||||
$('#content').append($mask);
|
$('#content').append($mask);
|
||||||
|
|
||||||
// block UI, but only make visible in case loading takes longer
|
// block UI, but only make visible in case loading takes longer
|
||||||
FileList._maskTimeout = window.setTimeout(function(){
|
FileList._maskTimeout = window.setTimeout(function() {
|
||||||
// reset opacity
|
// reset opacity
|
||||||
$mask.removeClass('transparent');
|
$mask.removeClass('transparent');
|
||||||
}, 250);
|
}, 250);
|
||||||
},
|
},
|
||||||
hideMask: function(){
|
hideMask: function() {
|
||||||
var $mask = $('#content .mask').remove();
|
var $mask = $('#content .mask').remove();
|
||||||
if (FileList._maskTimeout){
|
if (FileList._maskTimeout) {
|
||||||
window.clearTimeout(FileList._maskTimeout);
|
window.clearTimeout(FileList._maskTimeout);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
scrollTo:function(file) {
|
scrollTo:function(file) {
|
||||||
//scroll to and highlight preselected file
|
//scroll to and highlight preselected file
|
||||||
var scrolltorow = $('tr[data-file="'+file+'"]');
|
var $scrolltorow = $('tr[data-file="'+file+'"]');
|
||||||
if (scrolltorow.length > 0) {
|
if ($scrolltorow.exists()) {
|
||||||
scrolltorow.addClass('searchresult');
|
$scrolltorow.addClass('searchresult');
|
||||||
$(window).scrollTop(scrolltorow.position().top);
|
$(window).scrollTop($scrolltorow.position().top);
|
||||||
//remove highlight when hovered over
|
//remove highlight when hovered over
|
||||||
scrolltorow.one('hover', function(){
|
$scrolltorow.one('hover', function() {
|
||||||
scrolltorow.removeClass('searchresult');
|
$scrolltorow.removeClass('searchresult');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filter:function(query){
|
filter:function(query) {
|
||||||
$('#fileList tr:not(.summary)').each(function(i,e){
|
$('#fileList tr:not(.summary)').each(function(i,e) {
|
||||||
if ($(e).data('file').toLowerCase().indexOf(query.toLowerCase()) !== -1) {
|
if ($(e).data('file').toLowerCase().indexOf(query.toLowerCase()) !== -1) {
|
||||||
$(e).addClass("searchresult");
|
$(e).addClass("searchresult");
|
||||||
} else {
|
} else {
|
||||||
|
@ -665,18 +685,18 @@ var FileList={
|
||||||
});
|
});
|
||||||
//do not use scrollto to prevent removing searchresult css class
|
//do not use scrollto to prevent removing searchresult css class
|
||||||
var first = $('#fileList tr.searchresult').first();
|
var first = $('#fileList tr.searchresult').first();
|
||||||
if (first.length !== 0) {
|
if (first.exists()) {
|
||||||
$(window).scrollTop(first.position().top);
|
$(window).scrollTop(first.position().top);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unfilter:function(){
|
unfilter:function() {
|
||||||
$('#fileList tr.searchresult').each(function(i,e){
|
$('#fileList tr.searchresult').each(function(i,e) {
|
||||||
$(e).removeClass("searchresult");
|
$(e).removeClass("searchresult");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function() {
|
||||||
var isPublic = !!$('#isPublic').val();
|
var isPublic = !!$('#isPublic').val();
|
||||||
|
|
||||||
// handle upload events
|
// handle upload events
|
||||||
|
@ -686,16 +706,16 @@ $(document).ready(function(){
|
||||||
OC.Upload.log('filelist handle fileuploaddrop', e, data);
|
OC.Upload.log('filelist handle fileuploaddrop', e, data);
|
||||||
|
|
||||||
var dropTarget = $(e.originalEvent.target).closest('tr, .crumb');
|
var dropTarget = $(e.originalEvent.target).closest('tr, .crumb');
|
||||||
if(dropTarget && (dropTarget.data('type') === 'dir' || dropTarget.hasClass('crumb'))) { // drag&drop upload to folder
|
if (dropTarget && (dropTarget.data('type') === 'dir' || dropTarget.hasClass('crumb'))) { // drag&drop upload to folder
|
||||||
|
|
||||||
// remember as context
|
// remember as context
|
||||||
data.context = dropTarget;
|
data.context = dropTarget;
|
||||||
|
|
||||||
var dir = dropTarget.data('file');
|
var dir = dropTarget.data('file');
|
||||||
// if from file list, need to prepend parent dir
|
// if from file list, need to prepend parent dir
|
||||||
if (dir){
|
if (dir) {
|
||||||
var parentDir = $('#dir').val() || '/';
|
var parentDir = $('#dir').val() || '/';
|
||||||
if (parentDir[parentDir.length - 1] != '/'){
|
if (parentDir[parentDir.length - 1] !== '/') {
|
||||||
parentDir += '/';
|
parentDir += '/';
|
||||||
}
|
}
|
||||||
dir = parentDir + dir;
|
dir = parentDir + dir;
|
||||||
|
@ -719,12 +739,12 @@ $(document).ready(function(){
|
||||||
OC.Upload.log('filelist handle fileuploadadd', e, data);
|
OC.Upload.log('filelist handle fileuploadadd', e, data);
|
||||||
|
|
||||||
//finish delete if we are uploading a deleted file
|
//finish delete if we are uploading a deleted file
|
||||||
if(FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1){
|
if (FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1) {
|
||||||
FileList.finishDelete(null, true); //delete file before continuing
|
FileList.finishDelete(null, true); //delete file before continuing
|
||||||
}
|
}
|
||||||
|
|
||||||
// add ui visualization to existing folder
|
// add ui visualization to existing folder
|
||||||
if(data.context && data.context.data('type') === 'dir') {
|
if (data.context && data.context.data('type') === 'dir') {
|
||||||
// add to existing folder
|
// add to existing folder
|
||||||
|
|
||||||
// update upload counter ui
|
// update upload counter ui
|
||||||
|
@ -734,7 +754,7 @@ $(document).ready(function(){
|
||||||
uploadtext.attr('currentUploads', currentUploads);
|
uploadtext.attr('currentUploads', currentUploads);
|
||||||
|
|
||||||
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
||||||
if(currentUploads === 1) {
|
if (currentUploads === 1) {
|
||||||
var img = OC.imagePath('core', 'loading.gif');
|
var img = OC.imagePath('core', 'loading.gif');
|
||||||
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
||||||
uploadtext.text(translatedText);
|
uploadtext.text(translatedText);
|
||||||
|
@ -761,7 +781,7 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
var result=$.parseJSON(response);
|
var result=$.parseJSON(response);
|
||||||
|
|
||||||
if(typeof result[0] !== 'undefined' && result[0].status === 'success') {
|
if (typeof result[0] !== 'undefined' && result[0].status === 'success') {
|
||||||
var file = result[0];
|
var file = result[0];
|
||||||
|
|
||||||
if (data.context && data.context.data('type') === 'dir') {
|
if (data.context && data.context.data('type') === 'dir') {
|
||||||
|
@ -772,7 +792,7 @@ $(document).ready(function(){
|
||||||
currentUploads -= 1;
|
currentUploads -= 1;
|
||||||
uploadtext.attr('currentUploads', currentUploads);
|
uploadtext.attr('currentUploads', currentUploads);
|
||||||
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
||||||
if(currentUploads === 0) {
|
if (currentUploads === 0) {
|
||||||
var img = OC.imagePath('core', 'filetypes/folder.png');
|
var img = OC.imagePath('core', 'filetypes/folder.png');
|
||||||
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
||||||
uploadtext.text(translatedText);
|
uploadtext.text(translatedText);
|
||||||
|
@ -789,18 +809,18 @@ $(document).ready(function(){
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// only append new file if dragged onto current dir's crumb (last)
|
// only append new file if dragged onto current dir's crumb (last)
|
||||||
if (data.context && data.context.hasClass('crumb') && !data.context.hasClass('last')){
|
if (data.context && data.context.hasClass('crumb') && !data.context.hasClass('last')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add as stand-alone row to filelist
|
// add as stand-alone row to filelist
|
||||||
var size=t('files', 'Pending');
|
var size=t('files', 'Pending');
|
||||||
if (data.files[0].size>=0){
|
if (data.files[0].size>=0) {
|
||||||
size=data.files[0].size;
|
size=data.files[0].size;
|
||||||
}
|
}
|
||||||
var date=new Date();
|
var date=new Date();
|
||||||
var param = {};
|
var param = {};
|
||||||
if ($('#publicUploadRequestToken').length) {
|
if ($('#publicUploadRequestToken').exists()) {
|
||||||
param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name;
|
param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name;
|
||||||
}
|
}
|
||||||
//should the file exist in the list remove it
|
//should the file exist in the list remove it
|
||||||
|
@ -813,14 +833,14 @@ $(document).ready(function(){
|
||||||
data.context.attr('data-mime',file.mime).attr('data-id',file.id);
|
data.context.attr('data-mime',file.mime).attr('data-id',file.id);
|
||||||
|
|
||||||
var permissions = data.context.data('permissions');
|
var permissions = data.context.data('permissions');
|
||||||
if(permissions !== file.permissions) {
|
if (permissions !== file.permissions) {
|
||||||
data.context.attr('data-permissions', file.permissions);
|
data.context.attr('data-permissions', file.permissions);
|
||||||
data.context.data('permissions', file.permissions);
|
data.context.data('permissions', file.permissions);
|
||||||
}
|
}
|
||||||
FileActions.display(data.context.find('td.filename'), true);
|
FileActions.display(data.context.find('td.filename'), true);
|
||||||
|
|
||||||
var path = getPathForPreview(file.name);
|
var path = getPathForPreview(file.name);
|
||||||
lazyLoadPreview(path, file.mime, function(previewpath){
|
lazyLoadPreview(path, file.mime, function(previewpath) {
|
||||||
data.context.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
data.context.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -854,10 +874,10 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#notification').hide();
|
$('#notification').hide();
|
||||||
$('#notification').on('click', '.undo', function(){
|
$('#notification').on('click', '.undo', function() {
|
||||||
if (FileList.deleteFiles) {
|
if (FileList.deleteFiles) {
|
||||||
$.each(FileList.deleteFiles,function(index,file){
|
$.each(FileList.deleteFiles,function(index,file) {
|
||||||
$('tr').filterAttr('data-file',file).show();
|
$('tr[data-file="'+file+'"]').show();
|
||||||
});
|
});
|
||||||
FileList.deleteCanceled=true;
|
FileList.deleteCanceled=true;
|
||||||
FileList.deleteFiles=null;
|
FileList.deleteFiles=null;
|
||||||
|
@ -867,10 +887,10 @@ $(document).ready(function(){
|
||||||
FileList.deleteCanceled = false;
|
FileList.deleteCanceled = false;
|
||||||
FileList.deleteFiles = [FileList.replaceOldName];
|
FileList.deleteFiles = [FileList.replaceOldName];
|
||||||
} else {
|
} else {
|
||||||
$('tr').filterAttr('data-file', FileList.replaceOldName).show();
|
$('tr[data-file="'+FileList.replaceOldName+'"]').show();
|
||||||
}
|
}
|
||||||
$('tr').filterAttr('data-replace', 'true').remove();
|
$('tr[data-replace="true"').remove();
|
||||||
$('tr').filterAttr('data-file', FileList.replaceNewName).show();
|
$('tr[data-file="'+FileList.replaceNewName+'"]').show();
|
||||||
FileList.replaceCanceled = true;
|
FileList.replaceCanceled = true;
|
||||||
FileList.replaceOldName = null;
|
FileList.replaceOldName = null;
|
||||||
FileList.replaceNewName = null;
|
FileList.replaceNewName = null;
|
||||||
|
@ -885,7 +905,7 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$('#notification:first-child').on('click', '.suggest', function() {
|
$('#notification:first-child').on('click', '.suggest', function() {
|
||||||
$('tr').filterAttr('data-file', $('#notification > span').attr('data-oldName')).show();
|
$('tr[data-file="'+$('#notification > span').attr('data-oldName')+'"]').show();
|
||||||
OC.Notification.hide();
|
OC.Notification.hide();
|
||||||
});
|
});
|
||||||
$('#notification:first-child').on('click', '.cancel', function() {
|
$('#notification:first-child').on('click', '.cancel', function() {
|
||||||
|
@ -895,67 +915,67 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
FileList.useUndo=(window.onbeforeunload)?true:false;
|
FileList.useUndo=(window.onbeforeunload)?true:false;
|
||||||
$(window).bind('beforeunload', function (){
|
$(window).bind('beforeunload', function () {
|
||||||
if (FileList.lastAction) {
|
if (FileList.lastAction) {
|
||||||
FileList.lastAction();
|
FileList.lastAction();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$(window).unload(function (){
|
$(window).unload(function () {
|
||||||
$(window).trigger('beforeunload');
|
$(window).trigger('beforeunload');
|
||||||
});
|
});
|
||||||
|
|
||||||
function decodeQuery(query){
|
function decodeQuery(query) {
|
||||||
return query.replace(/\+/g, ' ');
|
return query.replace(/\+/g, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseHashQuery(){
|
function parseHashQuery() {
|
||||||
var hash = window.location.hash,
|
var hash = window.location.hash,
|
||||||
pos = hash.indexOf('?'),
|
pos = hash.indexOf('?'),
|
||||||
query;
|
query;
|
||||||
if (pos >= 0){
|
if (pos >= 0) {
|
||||||
return hash.substr(pos + 1);
|
return hash.substr(pos + 1);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCurrentDirFromUrl(){
|
function parseCurrentDirFromUrl() {
|
||||||
var query = parseHashQuery(),
|
var query = parseHashQuery(),
|
||||||
params,
|
params,
|
||||||
dir = '/';
|
dir = '/';
|
||||||
// try and parse from URL hash first
|
// try and parse from URL hash first
|
||||||
if (query){
|
if (query) {
|
||||||
params = OC.parseQueryString(decodeQuery(query));
|
params = OC.parseQueryString(decodeQuery(query));
|
||||||
}
|
}
|
||||||
// else read from query attributes
|
// else read from query attributes
|
||||||
if (!params){
|
if (!params) {
|
||||||
params = OC.parseQueryString(decodeQuery(location.search));
|
params = OC.parseQueryString(decodeQuery(location.search));
|
||||||
}
|
}
|
||||||
return (params && params.dir) || '/';
|
return (params && params.dir) || '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable ajax/history API for public app (TODO: until it gets ported)
|
// disable ajax/history API for public app (TODO: until it gets ported)
|
||||||
if (!isPublic){
|
if (!isPublic) {
|
||||||
// fallback to hashchange when no history support
|
// fallback to hashchange when no history support
|
||||||
if (!window.history.pushState){
|
if (!window.history.pushState) {
|
||||||
$(window).on('hashchange', function(){
|
$(window).on('hashchange', function() {
|
||||||
FileList.changeDirectory(parseCurrentDirFromUrl(), false);
|
FileList.changeDirectory(parseCurrentDirFromUrl(), false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
window.onpopstate = function(e){
|
window.onpopstate = function(e) {
|
||||||
var targetDir;
|
var targetDir;
|
||||||
if (e.state && e.state.dir){
|
if (e.state && e.state.dir) {
|
||||||
targetDir = e.state.dir;
|
targetDir = e.state.dir;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// read from URL
|
// read from URL
|
||||||
targetDir = parseCurrentDirFromUrl();
|
targetDir = parseCurrentDirFromUrl();
|
||||||
}
|
}
|
||||||
if (targetDir){
|
if (targetDir) {
|
||||||
FileList.changeDirectory(targetDir, false);
|
FileList.changeDirectory(targetDir, false);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
if (parseInt($('#ajaxLoad').val(), 10) === 1){
|
if (parseInt($('#ajaxLoad').val(), 10) === 1) {
|
||||||
// need to initially switch the dir to the one from the hash (IE8)
|
// need to initially switch the dir to the one from the hash (IE8)
|
||||||
FileList.changeDirectory(parseCurrentDirFromUrl(), false, true);
|
FileList.changeDirectory(parseCurrentDirFromUrl(), false, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
Files={
|
Files={
|
||||||
updateMaxUploadFilesize:function(response) {
|
updateMaxUploadFilesize:function(response) {
|
||||||
if(response == undefined) {
|
if (response === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
|
if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
|
||||||
$('#max_upload').val(response.data.uploadMaxFilesize);
|
$('#max_upload').val(response.data.uploadMaxFilesize);
|
||||||
$('#upload.button').attr('original-title', response.data.maxHumanFilesize);
|
$('#upload.button').attr('original-title', response.data.maxHumanFilesize);
|
||||||
$('#usedSpacePercent').val(response.data.usedSpacePercent);
|
$('#usedSpacePercent').val(response.data.usedSpacePercent);
|
||||||
Files.displayStorageWarnings();
|
Files.displayStorageWarnings();
|
||||||
}
|
}
|
||||||
if(response[0] == undefined) {
|
if (response[0] === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(response[0].uploadMaxFilesize !== undefined) {
|
if (response[0].uploadMaxFilesize !== undefined) {
|
||||||
$('#max_upload').val(response[0].uploadMaxFilesize);
|
$('#max_upload').val(response[0].uploadMaxFilesize);
|
||||||
$('#upload.button').attr('original-title', response[0].maxHumanFilesize);
|
$('#upload.button').attr('original-title', response[0].maxHumanFilesize);
|
||||||
$('#usedSpacePercent').val(response[0].usedSpacePercent);
|
$('#usedSpacePercent').val(response[0].usedSpacePercent);
|
||||||
|
@ -22,23 +22,18 @@ Files={
|
||||||
},
|
},
|
||||||
isFileNameValid:function (name) {
|
isFileNameValid:function (name) {
|
||||||
if (name === '.') {
|
if (name === '.') {
|
||||||
OC.Notification.show(t('files', '\'.\' is an invalid file name.'));
|
throw t('files', '\'.\' is an invalid file name.');
|
||||||
return false;
|
} else if (name.length === 0) {
|
||||||
}
|
throw t('files', 'File name cannot be empty.');
|
||||||
if (name.length == 0) {
|
|
||||||
OC.Notification.show(t('files', 'File name cannot be empty.'));
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for invalid characters
|
// check for invalid characters
|
||||||
var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
|
var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
|
||||||
for (var i = 0; i < invalid_characters.length; i++) {
|
for (var i = 0; i < invalid_characters.length; i++) {
|
||||||
if (name.indexOf(invalid_characters[i]) != -1) {
|
if (name.indexOf(invalid_characters[i]) !== -1) {
|
||||||
OC.Notification.show(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
|
throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OC.Notification.hide();
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
displayStorageWarnings: function() {
|
displayStorageWarnings: function() {
|
||||||
|
@ -78,18 +73,18 @@ Files={
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setupDragAndDrop: function(){
|
setupDragAndDrop: function() {
|
||||||
var $fileList = $('#fileList');
|
var $fileList = $('#fileList');
|
||||||
|
|
||||||
//drag/drop of files
|
//drag/drop of files
|
||||||
$fileList.find('tr td.filename').each(function(i,e){
|
$fileList.find('tr td.filename').each(function(i,e) {
|
||||||
if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) {
|
if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) {
|
||||||
$(e).draggable(dragOptions);
|
$(e).draggable(dragOptions);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$fileList.find('tr[data-type="dir"] td.filename').each(function(i,e){
|
$fileList.find('tr[data-type="dir"] td.filename').each(function(i,e) {
|
||||||
if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){
|
if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE) {
|
||||||
$(e).droppable(folderDropOptions);
|
$(e).droppable(folderDropOptions);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -127,9 +122,9 @@ Files={
|
||||||
},
|
},
|
||||||
|
|
||||||
resizeBreadcrumbs: function (width, firstRun) {
|
resizeBreadcrumbs: function (width, firstRun) {
|
||||||
if (width != Files.lastWidth) {
|
if (width !== Files.lastWidth) {
|
||||||
if ((width < Files.lastWidth || firstRun) && width < Files.breadcrumbsWidth) {
|
if ((width < Files.lastWidth || firstRun) && width < Files.breadcrumbsWidth) {
|
||||||
if (Files.hiddenBreadcrumbs == 0) {
|
if (Files.hiddenBreadcrumbs === 0) {
|
||||||
Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth;
|
Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth;
|
||||||
$(Files.breadcrumbs[1]).find('a').hide();
|
$(Files.breadcrumbs[1]).find('a').hide();
|
||||||
$(Files.breadcrumbs[1]).append('<span>...</span>');
|
$(Files.breadcrumbs[1]).append('<span>...</span>');
|
||||||
|
@ -141,12 +136,12 @@ Files={
|
||||||
Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth;
|
Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth;
|
||||||
$(Files.breadcrumbs[i]).hide();
|
$(Files.breadcrumbs[i]).hide();
|
||||||
Files.hiddenBreadcrumbs = i;
|
Files.hiddenBreadcrumbs = i;
|
||||||
i++
|
i++;
|
||||||
}
|
}
|
||||||
} else if (width > Files.lastWidth && Files.hiddenBreadcrumbs > 0) {
|
} else if (width > Files.lastWidth && Files.hiddenBreadcrumbs > 0) {
|
||||||
var i = Files.hiddenBreadcrumbs;
|
var i = Files.hiddenBreadcrumbs;
|
||||||
while (width > Files.breadcrumbsWidth && i > 0) {
|
while (width > Files.breadcrumbsWidth && i > 0) {
|
||||||
if (Files.hiddenBreadcrumbs == 1) {
|
if (Files.hiddenBreadcrumbs === 1) {
|
||||||
Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth;
|
Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth;
|
||||||
$(Files.breadcrumbs[1]).find('span').remove();
|
$(Files.breadcrumbs[1]).find('span').remove();
|
||||||
$(Files.breadcrumbs[1]).find('a').show();
|
$(Files.breadcrumbs[1]).find('a').show();
|
||||||
|
@ -170,7 +165,7 @@ Files={
|
||||||
};
|
};
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// FIXME: workaround for trashbin app
|
// FIXME: workaround for trashbin app
|
||||||
if (window.trashBinApp){
|
if (window.trashBinApp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Files.displayEncryptionWarning();
|
Files.displayEncryptionWarning();
|
||||||
|
@ -215,7 +210,7 @@ $(document).ready(function() {
|
||||||
var rows = $(this).parent().parent().parent().children('tr');
|
var rows = $(this).parent().parent().parent().children('tr');
|
||||||
for (var i = start; i < end; i++) {
|
for (var i = start; i < end; i++) {
|
||||||
$(rows).each(function(index) {
|
$(rows).each(function(index) {
|
||||||
if (index == i) {
|
if (index === i) {
|
||||||
var checkbox = $(this).children().children('input:checkbox');
|
var checkbox = $(this).children().children('input:checkbox');
|
||||||
$(checkbox).attr('checked', 'checked');
|
$(checkbox).attr('checked', 'checked');
|
||||||
$(checkbox).parent().parent().addClass('selected');
|
$(checkbox).parent().parent().addClass('selected');
|
||||||
|
@ -232,23 +227,23 @@ $(document).ready(function() {
|
||||||
} else {
|
} else {
|
||||||
$(checkbox).attr('checked', 'checked');
|
$(checkbox).attr('checked', 'checked');
|
||||||
$(checkbox).parent().parent().toggleClass('selected');
|
$(checkbox).parent().parent().toggleClass('selected');
|
||||||
var selectedCount=$('td.filename input:checkbox:checked').length;
|
var selectedCount = $('td.filename input:checkbox:checked').length;
|
||||||
if (selectedCount == $('td.filename input:checkbox').length) {
|
if (selectedCount === $('td.filename input:checkbox').length) {
|
||||||
$('#select_all').attr('checked', 'checked');
|
$('#select_all').attr('checked', 'checked');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
procesSelection();
|
procesSelection();
|
||||||
} else {
|
} else {
|
||||||
var filename=$(this).parent().parent().attr('data-file');
|
var filename=$(this).parent().parent().attr('data-file');
|
||||||
var tr=$('tr').filterAttr('data-file',filename);
|
var tr=$('tr[data-file="'+filename+'"]');
|
||||||
var renaming=tr.data('renaming');
|
var renaming=tr.data('renaming');
|
||||||
if(!renaming && !FileList.isLoading(filename)){
|
if (!renaming && !FileList.isLoading(filename)) {
|
||||||
FileActions.currentFile = $(this).parent();
|
FileActions.currentFile = $(this).parent();
|
||||||
var mime=FileActions.getCurrentMimeType();
|
var mime=FileActions.getCurrentMimeType();
|
||||||
var type=FileActions.getCurrentType();
|
var type=FileActions.getCurrentType();
|
||||||
var permissions = FileActions.getCurrentPermissions();
|
var permissions = FileActions.getCurrentPermissions();
|
||||||
var action=FileActions.getDefault(mime,type, permissions);
|
var action=FileActions.getDefault(mime,type, permissions);
|
||||||
if(action){
|
if (action) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
action(filename);
|
action(filename);
|
||||||
}
|
}
|
||||||
|
@ -259,11 +254,11 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// Sets the select_all checkbox behaviour :
|
// Sets the select_all checkbox behaviour :
|
||||||
$('#select_all').click(function() {
|
$('#select_all').click(function() {
|
||||||
if($(this).attr('checked')){
|
if ($(this).attr('checked')) {
|
||||||
// Check all
|
// Check all
|
||||||
$('td.filename input:checkbox').attr('checked', true);
|
$('td.filename input:checkbox').attr('checked', true);
|
||||||
$('td.filename input:checkbox').parent().parent().addClass('selected');
|
$('td.filename input:checkbox').parent().parent().addClass('selected');
|
||||||
}else{
|
} else {
|
||||||
// Uncheck all
|
// Uncheck all
|
||||||
$('td.filename input:checkbox').attr('checked', false);
|
$('td.filename input:checkbox').attr('checked', false);
|
||||||
$('td.filename input:checkbox').parent().parent().removeClass('selected');
|
$('td.filename input:checkbox').parent().parent().removeClass('selected');
|
||||||
|
@ -280,7 +275,7 @@ $(document).ready(function() {
|
||||||
var rows = $(this).parent().parent().parent().children('tr');
|
var rows = $(this).parent().parent().parent().children('tr');
|
||||||
for (var i = start; i < end; i++) {
|
for (var i = start; i < end; i++) {
|
||||||
$(rows).each(function(index) {
|
$(rows).each(function(index) {
|
||||||
if (index == i) {
|
if (index === i) {
|
||||||
var checkbox = $(this).children().children('input:checkbox');
|
var checkbox = $(this).children().children('input:checkbox');
|
||||||
$(checkbox).attr('checked', 'checked');
|
$(checkbox).attr('checked', 'checked');
|
||||||
$(checkbox).parent().parent().addClass('selected');
|
$(checkbox).parent().parent().addClass('selected');
|
||||||
|
@ -290,10 +285,10 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
var selectedCount=$('td.filename input:checkbox:checked').length;
|
var selectedCount=$('td.filename input:checkbox:checked').length;
|
||||||
$(this).parent().parent().toggleClass('selected');
|
$(this).parent().parent().toggleClass('selected');
|
||||||
if(!$(this).attr('checked')){
|
if (!$(this).attr('checked')) {
|
||||||
$('#select_all').attr('checked',false);
|
$('#select_all').attr('checked',false);
|
||||||
}else{
|
} else {
|
||||||
if(selectedCount==$('td.filename input:checkbox').length){
|
if (selectedCount===$('td.filename input:checkbox').length) {
|
||||||
$('#select_all').attr('checked',true);
|
$('#select_all').attr('checked',true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,10 +301,11 @@ $(document).ready(function() {
|
||||||
var dir=$('#dir').val()||'/';
|
var dir=$('#dir').val()||'/';
|
||||||
OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.'));
|
OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.'));
|
||||||
// use special download URL if provided, e.g. for public shared files
|
// use special download URL if provided, e.g. for public shared files
|
||||||
if ( (downloadURL = document.getElementById("downloadURL")) ) {
|
var downloadURL = document.getElementById("downloadURL");
|
||||||
window.location=downloadURL.value+"&download&files="+encodeURIComponent(fileslist);
|
if ( downloadURL ) {
|
||||||
|
window.location = downloadURL.value+"&download&files=" + encodeURIComponent(fileslist);
|
||||||
} else {
|
} else {
|
||||||
window.location=OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist });
|
window.location = OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist });
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
@ -376,12 +372,12 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function scanFiles(force, dir, users){
|
function scanFiles(force, dir, users) {
|
||||||
if (!OC.currentUser) {
|
if (!OC.currentUser) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!dir){
|
if (!dir) {
|
||||||
dir = '';
|
dir = '';
|
||||||
}
|
}
|
||||||
force = !!force; //cast to bool
|
force = !!force; //cast to bool
|
||||||
|
@ -399,17 +395,17 @@ function scanFiles(force, dir, users){
|
||||||
scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force: force,dir: dir});
|
scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force: force,dir: dir});
|
||||||
}
|
}
|
||||||
scanFiles.cancel = scannerEventSource.close.bind(scannerEventSource);
|
scanFiles.cancel = scannerEventSource.close.bind(scannerEventSource);
|
||||||
scannerEventSource.listen('count',function(count){
|
scannerEventSource.listen('count',function(count) {
|
||||||
console.log(count + ' files scanned')
|
console.log(count + ' files scanned');
|
||||||
});
|
});
|
||||||
scannerEventSource.listen('folder',function(path){
|
scannerEventSource.listen('folder',function(path) {
|
||||||
console.log('now scanning ' + path)
|
console.log('now scanning ' + path);
|
||||||
});
|
});
|
||||||
scannerEventSource.listen('done',function(count){
|
scannerEventSource.listen('done',function(count) {
|
||||||
scanFiles.scanning=false;
|
scanFiles.scanning=false;
|
||||||
console.log('done after ' + count + ' files');
|
console.log('done after ' + count + ' files');
|
||||||
});
|
});
|
||||||
scannerEventSource.listen('user',function(user){
|
scannerEventSource.listen('user',function(user) {
|
||||||
console.log('scanning files for ' + user);
|
console.log('scanning files for ' + user);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -418,14 +414,14 @@ scanFiles.scanning=false;
|
||||||
function boolOperationFinished(data, callback) {
|
function boolOperationFinished(data, callback) {
|
||||||
result = jQuery.parseJSON(data.responseText);
|
result = jQuery.parseJSON(data.responseText);
|
||||||
Files.updateMaxUploadFilesize(result);
|
Files.updateMaxUploadFilesize(result);
|
||||||
if(result.status == 'success'){
|
if (result.status === 'success') {
|
||||||
callback.call();
|
callback.call();
|
||||||
} else {
|
} else {
|
||||||
alert(result.data.message);
|
alert(result.data.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var createDragShadow = function(event){
|
var createDragShadow = function(event) {
|
||||||
//select dragged file
|
//select dragged file
|
||||||
var isDragSelected = $(event.target).parents('tr').find('td input:first').prop('checked');
|
var isDragSelected = $(event.target).parents('tr').find('td input:first').prop('checked');
|
||||||
if (!isDragSelected) {
|
if (!isDragSelected) {
|
||||||
|
@ -435,7 +431,7 @@ var createDragShadow = function(event){
|
||||||
|
|
||||||
var selectedFiles = getSelectedFilesTrash();
|
var selectedFiles = getSelectedFilesTrash();
|
||||||
|
|
||||||
if (!isDragSelected && selectedFiles.length == 1) {
|
if (!isDragSelected && selectedFiles.length === 1) {
|
||||||
//revert the selection
|
//revert the selection
|
||||||
$(event.target).parents('tr').find('td input:first').prop('checked',false);
|
$(event.target).parents('tr').find('td input:first').prop('checked',false);
|
||||||
}
|
}
|
||||||
|
@ -452,7 +448,7 @@ var createDragShadow = function(event){
|
||||||
|
|
||||||
var dir=$('#dir').val();
|
var dir=$('#dir').val();
|
||||||
|
|
||||||
$(selectedFiles).each(function(i,elem){
|
$(selectedFiles).each(function(i,elem) {
|
||||||
var newtr = $('<tr/>').attr('data-dir', dir).attr('data-filename', elem.name);
|
var newtr = $('<tr/>').attr('data-dir', dir).attr('data-filename', elem.name);
|
||||||
newtr.append($('<td/>').addClass('filename').text(elem.name));
|
newtr.append($('<td/>').addClass('filename').text(elem.name));
|
||||||
newtr.append($('<td/>').addClass('size').text(humanFileSize(elem.size)));
|
newtr.append($('<td/>').addClass('size').text(humanFileSize(elem.size)));
|
||||||
|
@ -461,14 +457,14 @@ var createDragShadow = function(event){
|
||||||
newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')');
|
newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')');
|
||||||
} else {
|
} else {
|
||||||
var path = getPathForPreview(elem.name);
|
var path = getPathForPreview(elem.name);
|
||||||
lazyLoadPreview(path, elem.mime, function(previewpath){
|
lazyLoadPreview(path, elem.mime, function(previewpath) {
|
||||||
newtr.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
newtr.find('td.filename').attr('style','background-image:url('+previewpath+')');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return dragshadow;
|
return dragshadow;
|
||||||
}
|
};
|
||||||
|
|
||||||
//options for file drag/drop
|
//options for file drag/drop
|
||||||
var dragOptions={
|
var dragOptions={
|
||||||
|
@ -478,7 +474,7 @@ var dragOptions={
|
||||||
stop: function(event, ui) {
|
stop: function(event, ui) {
|
||||||
$('#fileList tr td.filename').addClass('ui-draggable');
|
$('#fileList tr td.filename').addClass('ui-draggable');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
// sane browsers support using the distance option
|
// sane browsers support using the distance option
|
||||||
if ( $('html.ie').length === 0) {
|
if ( $('html.ie').length === 0) {
|
||||||
dragOptions['distance'] = 20;
|
dragOptions['distance'] = 20;
|
||||||
|
@ -491,20 +487,20 @@ var folderDropOptions={
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var target=$.trim($(this).find('.nametext').text());
|
var target = $.trim($(this).find('.nametext').text());
|
||||||
|
|
||||||
var files = ui.helper.find('tr');
|
var files = ui.helper.find('tr');
|
||||||
$(files).each(function(i,row){
|
$(files).each(function(i,row) {
|
||||||
var dir = $(row).data('dir');
|
var dir = $(row).data('dir');
|
||||||
var file = $(row).data('filename');
|
var file = $(row).data('filename');
|
||||||
$.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: dir+'/'+target }, function(result) {
|
$.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: dir+'/'+target }, function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result.status === 'success') {
|
if (result.status === 'success') {
|
||||||
//recalculate folder size
|
//recalculate folder size
|
||||||
var oldSize = $('#fileList tr').filterAttr('data-file',target).data('size');
|
var oldSize = $('#fileList tr[data-file="'+target+'"]').data('size');
|
||||||
var newSize = oldSize + $('#fileList tr').filterAttr('data-file',file).data('size');
|
var newSize = oldSize + $('#fileList tr[data-file="'+file+'"]').data('size');
|
||||||
$('#fileList tr').filterAttr('data-file',target).data('size', newSize);
|
$('#fileList tr[data-file="'+target+'"]').data('size', newSize);
|
||||||
$('#fileList tr').filterAttr('data-file',target).find('td.filesize').text(humanFileSize(newSize));
|
$('#fileList tr[data-file="'+target+'"]').find('td.filesize').text(humanFileSize(newSize));
|
||||||
|
|
||||||
FileList.remove(file);
|
FileList.remove(file);
|
||||||
procesSelection();
|
procesSelection();
|
||||||
|
@ -521,24 +517,24 @@ var folderDropOptions={
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
tolerance: 'pointer'
|
tolerance: 'pointer'
|
||||||
}
|
};
|
||||||
|
|
||||||
var crumbDropOptions={
|
var crumbDropOptions={
|
||||||
drop: function( event, ui ) {
|
drop: function( event, ui ) {
|
||||||
var target=$(this).data('dir');
|
var target=$(this).data('dir');
|
||||||
var dir=$('#dir').val();
|
var dir = $('#dir').val();
|
||||||
while(dir.substr(0,1)=='/'){//remove extra leading /'s
|
while(dir.substr(0,1) === '/') {//remove extra leading /'s
|
||||||
dir=dir.substr(1);
|
dir=dir.substr(1);
|
||||||
}
|
}
|
||||||
dir='/'+dir;
|
dir = '/' + dir;
|
||||||
if(dir.substr(-1,1)!='/'){
|
if (dir.substr(-1,1) !== '/') {
|
||||||
dir=dir+'/';
|
dir = dir + '/';
|
||||||
}
|
}
|
||||||
if(target==dir || target+'/'==dir){
|
if (target === dir || target+'/' === dir) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var files = ui.helper.find('tr');
|
var files = ui.helper.find('tr');
|
||||||
$(files).each(function(i,row){
|
$(files).each(function(i,row) {
|
||||||
var dir = $(row).data('dir');
|
var dir = $(row).data('dir');
|
||||||
var file = $(row).data('filename');
|
var file = $(row).data('filename');
|
||||||
$.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: target }, function(result) {
|
$.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: target }, function(result) {
|
||||||
|
@ -559,13 +555,17 @@ var crumbDropOptions={
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
tolerance: 'pointer'
|
tolerance: 'pointer'
|
||||||
}
|
};
|
||||||
|
|
||||||
function procesSelection(){
|
function procesSelection() {
|
||||||
var selected=getSelectedFilesTrash();
|
var selected = getSelectedFilesTrash();
|
||||||
var selectedFiles=selected.filter(function(el){return el.type=='file'});
|
var selectedFiles = selected.filter(function(el) {
|
||||||
var selectedFolders=selected.filter(function(el){return el.type=='dir'});
|
return el.type==='file';
|
||||||
if(selectedFiles.length==0 && selectedFolders.length==0) {
|
});
|
||||||
|
var selectedFolders = selected.filter(function(el) {
|
||||||
|
return el.type==='dir';
|
||||||
|
});
|
||||||
|
if (selectedFiles.length === 0 && selectedFolders.length === 0) {
|
||||||
$('#headerName>span.name').text(t('files','Name'));
|
$('#headerName>span.name').text(t('files','Name'));
|
||||||
$('#headerSize').text(t('files','Size'));
|
$('#headerSize').text(t('files','Size'));
|
||||||
$('#modified').text(t('files','Modified'));
|
$('#modified').text(t('files','Modified'));
|
||||||
|
@ -574,22 +574,22 @@ function procesSelection(){
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('.selectedActions').show();
|
$('.selectedActions').show();
|
||||||
var totalSize=0;
|
var totalSize = 0;
|
||||||
for(var i=0;i<selectedFiles.length;i++){
|
for(var i=0; i<selectedFiles.length; i++) {
|
||||||
totalSize+=selectedFiles[i].size;
|
totalSize+=selectedFiles[i].size;
|
||||||
};
|
};
|
||||||
for(var i=0;i<selectedFolders.length;i++){
|
for(var i=0; i<selectedFolders.length; i++) {
|
||||||
totalSize+=selectedFolders[i].size;
|
totalSize+=selectedFolders[i].size;
|
||||||
};
|
};
|
||||||
$('#headerSize').text(humanFileSize(totalSize));
|
$('#headerSize').text(humanFileSize(totalSize));
|
||||||
var selection='';
|
var selection = '';
|
||||||
if(selectedFolders.length>0){
|
if (selectedFolders.length > 0) {
|
||||||
selection += n('files', '%n folder', '%n folders', selectedFolders.length);
|
selection += n('files', '%n folder', '%n folders', selectedFolders.length);
|
||||||
if(selectedFiles.length>0){
|
if (selectedFiles.length > 0) {
|
||||||
selection+=' & ';
|
selection += ' & ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(selectedFiles.length>0){
|
if (selectedFiles.length>0) {
|
||||||
selection += n('files', '%n file', '%n files', selectedFiles.length);
|
selection += n('files', '%n file', '%n files', selectedFiles.length);
|
||||||
}
|
}
|
||||||
$('#headerName>span.name').text(selection);
|
$('#headerName>span.name').text(selection);
|
||||||
|
@ -600,37 +600,37 @@ function procesSelection(){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get a list of selected files
|
* @brief get a list of selected files
|
||||||
* @param string property (option) the property of the file requested
|
* @param {string} property (option) the property of the file requested
|
||||||
* @return array
|
* @return {array}
|
||||||
*
|
*
|
||||||
* possible values for property: name, mime, size and type
|
* possible values for property: name, mime, size and type
|
||||||
* if property is set, an array with that property for each file is returnd
|
* 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
|
* if it's ommited an array of objects with all properties is returned
|
||||||
*/
|
*/
|
||||||
function getSelectedFilesTrash(property){
|
function getSelectedFilesTrash(property) {
|
||||||
var elements=$('td.filename input:checkbox:checked').parent().parent();
|
var elements=$('td.filename input:checkbox:checked').parent().parent();
|
||||||
var files=[];
|
var files=[];
|
||||||
elements.each(function(i,element){
|
elements.each(function(i,element) {
|
||||||
var file={
|
var file={
|
||||||
name:$(element).attr('data-file'),
|
name:$(element).attr('data-file'),
|
||||||
mime:$(element).data('mime'),
|
mime:$(element).data('mime'),
|
||||||
type:$(element).data('type'),
|
type:$(element).data('type'),
|
||||||
size:$(element).data('size')
|
size:$(element).data('size')
|
||||||
};
|
};
|
||||||
if(property){
|
if (property) {
|
||||||
files.push(file[property]);
|
files.push(file[property]);
|
||||||
}else{
|
} else {
|
||||||
files.push(file);
|
files.push(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMimeIcon(mime, ready){
|
function getMimeIcon(mime, ready) {
|
||||||
if(getMimeIcon.cache[mime]){
|
if (getMimeIcon.cache[mime]) {
|
||||||
ready(getMimeIcon.cache[mime]);
|
ready(getMimeIcon.cache[mime]);
|
||||||
}else{
|
} else {
|
||||||
$.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path){
|
$.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path) {
|
||||||
getMimeIcon.cache[mime]=path;
|
getMimeIcon.cache[mime]=path;
|
||||||
ready(getMimeIcon.cache[mime]);
|
ready(getMimeIcon.cache[mime]);
|
||||||
});
|
});
|
||||||
|
@ -655,7 +655,7 @@ function lazyLoadPreview(path, mime, ready, width, height) {
|
||||||
if ( ! height ) {
|
if ( ! height ) {
|
||||||
height = $('#filestable').data('preview-y');
|
height = $('#filestable').data('preview-y');
|
||||||
}
|
}
|
||||||
if( $('#publicUploadButtonMock').length ) {
|
if ( $('#publicUploadButtonMock').length ) {
|
||||||
var previewURL = OC.Router.generate('core_ajax_public_preview', {file: path, x:width, y:height, t:$('#dirToken').val()});
|
var previewURL = OC.Router.generate('core_ajax_public_preview', {file: path, x:width, y:height, t:$('#dirToken').val()});
|
||||||
} else {
|
} else {
|
||||||
var previewURL = OC.Router.generate('core_ajax_preview', {file: path, x:width, y:height});
|
var previewURL = OC.Router.generate('core_ajax_preview', {file: path, x:width, y:height});
|
||||||
|
@ -669,8 +669,8 @@ function lazyLoadPreview(path, mime, ready, width, height) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUniqueName(name){
|
function getUniqueName(name) {
|
||||||
if($('tr').filterAttr('data-file',name).length>0){
|
if ($('tr[data-file="'+name+'"]').exists()) {
|
||||||
var parts=name.split('.');
|
var parts=name.split('.');
|
||||||
var extension = "";
|
var extension = "";
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
|
@ -679,9 +679,9 @@ function getUniqueName(name){
|
||||||
var base=parts.join('.');
|
var base=parts.join('.');
|
||||||
numMatch=base.match(/\((\d+)\)/);
|
numMatch=base.match(/\((\d+)\)/);
|
||||||
var num=2;
|
var num=2;
|
||||||
if(numMatch && numMatch.length>0){
|
if (numMatch && numMatch.length>0) {
|
||||||
num=parseInt(numMatch[numMatch.length-1])+1;
|
num=parseInt(numMatch[numMatch.length-1])+1;
|
||||||
base=base.split('(')
|
base=base.split('(');
|
||||||
base.pop();
|
base.pop();
|
||||||
base=$.trim(base.join('('));
|
base=$.trim(base.join('('));
|
||||||
}
|
}
|
||||||
|
@ -695,19 +695,19 @@ function getUniqueName(name){
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkTrashStatus() {
|
function checkTrashStatus() {
|
||||||
$.post(OC.filePath('files_trashbin', 'ajax', 'isEmpty.php'), function(result){
|
$.post(OC.filePath('files_trashbin', 'ajax', 'isEmpty.php'), function(result) {
|
||||||
if (result.data.isEmpty === false) {
|
if (result.data.isEmpty === false) {
|
||||||
$("input[type=button][id=trash]").removeAttr("disabled");
|
$("input[type=button][id=trash]").removeAttr("disabled");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClickBreadcrumb(e){
|
function onClickBreadcrumb(e) {
|
||||||
var $el = $(e.target).closest('.crumb'),
|
var $el = $(e.target).closest('.crumb'),
|
||||||
$targetDir = $el.data('dir');
|
$targetDir = $el.data('dir');
|
||||||
isPublic = !!$('#isPublic').val();
|
isPublic = !!$('#isPublic').val();
|
||||||
|
|
||||||
if ($targetDir !== undefined && !isPublic){
|
if ($targetDir !== undefined && !isPublic) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
FileList.changeDirectory(decodeURIComponent($targetDir));
|
FileList.changeDirectory(decodeURIComponent($targetDir));
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,15 @@ class App {
|
||||||
$result['data'] = array(
|
$result['data'] = array(
|
||||||
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved by ownCloud")
|
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved by ownCloud")
|
||||||
);
|
);
|
||||||
} elseif(
|
// rename to existing file is denied
|
||||||
|
} else if ($this->view->file_exists($dir . '/' . $newname)) {
|
||||||
|
|
||||||
|
$result['data'] = array(
|
||||||
|
'message' => $this->l10n->t(
|
||||||
|
"The name %s is already used in the folder %s. Please choose a different name.",
|
||||||
|
array($newname, $dir))
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
// rename to "." is denied
|
// rename to "." is denied
|
||||||
$newname !== '.' and
|
$newname !== '.' and
|
||||||
// rename of "/Shared" is denied
|
// rename of "/Shared" is denied
|
||||||
|
|
|
@ -933,7 +933,7 @@ jQuery.fn.selectRange = function(start, end) {
|
||||||
*/
|
*/
|
||||||
jQuery.fn.exists = function(){
|
jQuery.fn.exists = function(){
|
||||||
return this.length > 0;
|
return this.length > 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the server periodically every 15 mins to ensure that session doesnt
|
* Calls the server periodically every 15 mins to ensure that session doesnt
|
||||||
|
|
Loading…
Reference in New Issue