1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
backupApp.directive('destinationFolderPicker', function() {
return {
restrict: 'E',
require: ['ngModel'],
scope: {
ngModel: '=',
ngShowHidden: '=',
ngHideUserNode: '='
},
templateUrl: 'templates/targetfolderpicker.html',
controller: function($scope, $timeout, SystemInfo, AppService, AppUtils) {
var scope = $scope;
scope.systeminfo = SystemInfo.watch($scope);
$scope.treedata = {};
function compareablePath(path) {
var dirsep = scope.systeminfo.DirectorySeparator || '/';
if (path.substr(0, 1) == '%' && path.substr(path.length - 1, 1) == '%')
path += dirsep;
return scope.systeminfo.CaseSensitiveFilesystem ? path : path.toLowerCase();
};
function setIconCls(n) {
var cp = compareablePath(n.id);
var dirsep = scope.systeminfo.DirectorySeparator || '/';
if (cp == compareablePath('%MY_DOCUMENTS%'))
n.iconCls = 'x-tree-icon-mydocuments';
else if (cp == compareablePath('%MY_MUSIC%'))
n.iconCls = 'x-tree-icon-mymusic';
else if (cp == compareablePath('%MY_PICTURES%'))
n.iconCls = 'x-tree-icon-mypictures';
else if (cp == compareablePath('%DESKTOP%'))
n.iconCls = 'x-tree-icon-desktop';
else if (cp == compareablePath('%HOME%'))
n.iconCls = 'x-tree-icon-home';
else if (cp.substr(cp.length - 1, 1) != dirsep)
n.iconCls = 'x-tree-icon-leaf';
}
$scope.toggleExpanded = function(node) {
if (node.root && $scope.ngHideUserNode)
return;
node.expanded = !node.expanded;
if (node.root || node.iconCls == 'x-tree-icon-leaf' || node.iconCls == 'x-tree-icon-locked')
return;
if (!node.children && !node.loading) {
node.loading = true;
AppService.post('/filesystem?onlyfolders=true&showhidden=true', {path: node.id}).then(function(data) {
node.children = data.data;
node.loading = false;
}, function() {
node.loading = false;
node.expanded = false;
AppUtils.connectionError.apply(AppUtils, arguments);
});
}
};
$scope.toggleSelected = function(node) {
if (scope.selectednode != null)
scope.selectednode.selected = false;
scope.selectednode = node;
scope.selectednode.selected = true;
scope.ngModel = node.id;
};
function updateHideUserNode() {
if ($scope.treedata.children == null)
return;
if ($scope.ngHideUserNode) {
scope.treedata.children[0].invisible = true;
scope.treedata.children[1].expanded = true;
} else {
scope.treedata.children[0].invisible = false;
}
}
$scope.$watch('ngHideUserNode', updateHideUserNode);
AppService.post('/filesystem?onlyfolders=true&showhidden=true', {path: '/'}).then(function(data) {
var usernode = {
text: 'User data',
root: true,
iconCls: 'x-tree-icon-userdata',
expanded: true,
children: []
};
var systemnode = {
text: 'Computer',
root: true,
iconCls: 'x-tree-icon-computer',
children: []
};
scope.treedata.children = [
usernode,
systemnode
];
for(var i = 0; i < data.data.length; i++) {
if (data.data[i].id.indexOf('%') == 0) {
setIconCls(data.data[i]);
usernode.children.push(data.data[i]);
}
else
systemnode.children.push(data.data[i]);
}
updateHideUserNode();
}, AppUtils.connectionError);
}
}
});
|