Current File : //usr/local/jetapps/var/www/jetbackup5/docroot/app/controllers_enduser/restore/files.js |
define([
'app',
], function(app) {
app.controller("restore_files_enduser",
["$rootScope", "$scope", "$routeParams", "$location", "$timeout", "$interval", "api", "meta", "lang", "consts", "permissions", "alert", "popup",
function($rootScope, $scope, $routeParams, $location, $timeout, $interval, api, meta, lang, consts, permissions, alert, popup) {
$scope.backups = [];
$scope.selected = {_id:''};
$scope.files = undefined;
meta = meta.new("enduser_files_backups");
$scope.meta = meta;
$scope.metaData = meta.getData();
meta.setSortReverse(false);
if(!meta.getSortBy()) meta.setSortBy("created");
if(!meta.getSortDirection()) meta.setSortDirection("desc");
meta.setPageSizes([10,25,50,100]);
meta.setPageSize(10);
meta.setSortFields(["username", "owner"]);
meta.setTotalItems($scope.backups.length);
$scope.selectedBackup = function(backup) {
$scope.files = undefined;
if($scope.selected._id !== backup._id) $scope.selected = backup;
else $scope.selected = {_id:''};
};
$scope.totalFiles = function() {
if($scope.files === undefined) return null;
var output = 0;
for(var path in $scope.files) output++;
if(!output) return null;
return output;
};
$scope.fileBrowse = function() {
popup.open({
size: "xl",
template: 'fileManagerPopup',
scope: $scope,
resolve: {
files: function() { return $scope.files; },
backup: function() { return $scope.selected; }
}
}).result.then(function(files) {
var total = 0;
for(var path in files) total++;
$scope.files = total ? files : undefined;
}, function(){});
};
$scope.prepareSummary = function (type) {
var files = {};
if($scope.files !== undefined) files[$scope.selected._id] = $scope.files;
$scope.showSummary(type, [$scope.selected], files);
};
$scope.fetch = function () {
$scope.backups = [];
$scope.selected = {_id:''};
$scope.files = undefined;
var apiParams = {
name: $scope.loggedAccount.username,
type: consts.BACKUP_TYPE_ACCOUNT,
contains: consts.BACKUP_TYPE_ACCOUNT_HOMEDIR,
account_id: $scope.loggedAccount._id,
skip: meta.getSkip(),
limit: meta.getPageSize(),
filter: meta.getFilter(),
sort: {},
find: {}
};
apiParams.sort[meta.getSortBy()] = meta.getSortDirectionInt();
api.listBackupForTypeName({
data: apiParams,
success: function (data) {
meta.setTotalItems(data.total);
meta.calculate(data.backups);
for(var i = 0; i < data.backups.length; i++) {
var names = [];
for(var j = 0; j < data.backups[i].schedules.length; j++) names.push(consts.SCHEDULE_TYPES[data.backups[i].schedules[j]]);
data.backups[i].schedules_names = names.join(",");
$scope.backups.push(data.backups[i]);
}
}
});
};
$timeout($scope.fetch);
}
]
);
});