Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Filemanager): file d&d with beautified paths
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusweiss committed Apr 8, 2021
1 parent 1bce7c1 commit 7fd34dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions tine20/Filemanager/js/Model.js
Expand Up @@ -41,7 +41,8 @@ Tine.Filemanager.Model.NodeMixin = {
statics: {
type(path) {
path = String(path);
return path.lastIndexOf('/') === --path.length || path.split('/').pop().lastIndexOf('.') < 0 ? 'folder' : 'file';
const basename = path.split('/').pop(); // do not use basename() here -> recursion!
return path.lastIndexOf('/') === --path.length || basename.lastIndexOf('.') < Math.max(1, basename.length - 5) ? 'folder' : 'file';
},

dirname(path) {
Expand Down Expand Up @@ -268,14 +269,14 @@ Tine.Filemanager.nodeBackendMixin = {
targetPath = target;

if(target.data) {
targetPath = target.data.path + (target.data.type == 'folder' ? '/' : '');
targetPath = target.data.path;
}
else if (target.attributes) {
targetPath = target.attributes.path + '/';
targetPath = target.attributes.path;
treeIsTarget = true;
}
else if (target.path) {
targetPath = target.path + (target.type == 'folder' ? '/' : '');
targetPath = target.path;
}

for(var i=0; i<items.length; i++) {
Expand All @@ -291,7 +292,7 @@ Tine.Filemanager.nodeBackendMixin = {
itemName = itemName.name;
}

destinationFilenames.push(targetPath + (targetPath.match(/\/$/) ? itemName : ''));
destinationFilenames.push(Tine.Filemanager.Model.Node.sanitize(targetPath + (targetPath.match(/\/$/) ? itemName : '')));
}

var method = this.appName + ".copyNodes",
Expand Down
10 changes: 5 additions & 5 deletions tine20/Filemanager/js/NodeTreePanel.js
Expand Up @@ -101,7 +101,7 @@ Tine.Filemanager.NodeTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
var _ = window.lodash,
me = this,
path = data.path,
parentPath = path.replace(new RegExp(_.escapeRegExp(data.name) + '$'), ''),
parentPath = Tine.Filemanager.Model.Node.dirname(path),
node = this.getNodeById(data.id),
pathChange = node && node.attributes && node.attributes.nodeRecord.get('path') != path;

Expand Down Expand Up @@ -460,7 +460,7 @@ Tine.Filemanager.NodeTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
}

if (index > 2) {
var c = curNode.findChild('path', curPath + '/' + keys[index]);
var c = curNode.findChild('path', Tine.Filemanager.Model.Node.sanitize(curPath + keys[index]));
} else {
var c = curNode.findChild('id', keys[index]);
}
Expand Down Expand Up @@ -511,7 +511,7 @@ Tine.Filemanager.NodeTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
if(typeof nodeName == 'object') {
nodeName = nodeName.name;
}
newPath = targetPath + '/' + nodeName;
newPath = Tine.Filemanager.Model.Node.sanitize(targetPath + nodeName);

copy = new Ext.tree.AsyncTreeNode({text: node.text, path: newPath, name: node.attributes.name
, nodeRecord: node.attributes.nodeRecord, account_grants: node.attributes.account_grants});
Expand All @@ -525,7 +525,7 @@ Tine.Filemanager.NodeTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
var nodeData = Ext.copyTo({}, node.data, this.recordClass.getFieldNames());
var newNodeRecord = new this.recordClass(nodeData);

newPath = targetPath + '/' + nodeName;
newPath = Tine.Filemanager.Model.Node.sanitize(targetPath + nodeName);
copy = new Ext.tree.AsyncTreeNode({text: nodeName, path: newPath, name: node.data.name
, nodeRecord: newNodeRecord, account_grants: node.data.account_grants});
}
Expand Down Expand Up @@ -583,7 +583,7 @@ Tine.Filemanager.NodeTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
}

var fileName = file.name || file.fileName,
filePath = targetNodePath + '/' + fileName;
filePath = Tine.Filemanager.Model.Node.sanitize(targetNodePath + fileName);

var upload = new Ext.ux.file.Upload({
fmDirector: treePanel,
Expand Down

0 comments on commit 7fd34dd

Please sign in to comment.