-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathfile-selection-service.js
85 lines (70 loc) · 2.39 KB
/
file-selection-service.js
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
angular
.module('nzbhydraApp')
.factory('FileSelectionService', FileSelectionService);
function FileSelectionService($http, $q, $uibModal) {
var categories = {};
var selectedCategory = {};
var service = {
open: open
};
var deferred;
return service;
function open(fullPath, type) {
var instance = $uibModal.open({
templateUrl: 'static/html/file-selection.html',
controller: 'FileSelectionModalController',
size: "md",
resolve: {
data: function () {
return $http.post("internalapi/config/folderlisting", {
fullPath: angular.isDefined(fullPath) ? fullPath : null,
goUp: false,
type: type
});
},
type: function () {
return type;
}
}
});
instance.result.then(function (selection) {
deferred.resolve(selection);
}, function () {
deferred.reject("dismissed");
}
);
deferred = $q.defer();
return deferred.promise;
}
}
angular
.module('nzbhydraApp').controller('FileSelectionModalController', function ($scope, $http, $uibModalInstance, FileSelectionService, data, type) {
$scope.type = type;
$scope.showType = type === "file" ? "File" : "Folder";
$scope.data = data.data;
$scope.select = function (fileOrFolder, selectType) {
if (selectType === "file" && type === "file") {
$uibModalInstance.close(fileOrFolder.fullPath);
} else if (selectType === "folder") {
$http.post("internalapi/config/folderlisting", {
fullPath: fileOrFolder.fullPath,
type: type,
goUp: false
}).then(function (data) {
$scope.data = data.data;
})
}
};
$scope.goUp = function () {
$http.post("internalapi/config/folderlisting", {
fullPath: $scope.data.fullPath,
type: type,
goUp: true
}).then(function (data) {
$scope.data = data.data;
})
};
$scope.submit = function () {
$uibModalInstance.close($scope.data.fullPath);
}
});