Mini Shell
'use strict';
define(['app'], function(app) {
app.controller("backups_enduser",
["$uibModalInstance","$rootScope", "$scope", "$q", "$location", "$timeout", "api", "meta", "util", "permissions", "consts", "lang", "alert", "popup", "summary", "items", "files", "section",
function ($uibModalInstance, $rootScope, $scope, $q, $location, $timeout, api, meta, util, permissions, consts, lang, alert, popup, summary, items, files, section) {
$scope.loading = false;
$scope.accountData = $scope.loggedAccount;
$scope.items = items;
$scope.files = files;
$scope.list = {};
$scope.list_checked = {};
$scope.summary_gotoqueue = true;
$scope.summary_type = summary;
$scope.summary_tpl = $scope.includePath('backups' + summary + 'Summary', 'views_enduser');
$scope.restore_conditions = [];
$scope.conditions = {};
$scope.options = {
owner: '',
package: ''
};
$scope.encryption = { encrypted: false, key: '' };
$scope.noPermissions = [];
if(section._id === 'full') {
if(!permissions.canManageFileBackups) $scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_HOMEDIR);
if(!permissions.canManageCronBackups) $scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_CRON_JOBS);
if(!permissions.canManageDatabaseBackups) {
$scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_DATABASES);
$scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_DATABASE_USERS);
}
if(!permissions.canManageDNSZoneBackups) $scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_DOMAINS);
if(!permissions.canManageCertificateBackups) $scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_CERTIFICATES);
if(!permissions.canManageEmailBackups) $scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_EMAILS);
if(!permissions.canManageFTPBackups) $scope.noPermissions.push(consts.BACKUP_TYPE_ACCOUNT_FTP);
}
for (var i = 0; i < $scope.items.length; i++) {
var backup = $scope.items[i];
backup.checked = true;
if($scope.list[backup.backup_contains] === undefined) $scope.list[backup.backup_contains] = [];
$scope.list[backup.backup_contains].push(backup);
}
$scope.close = function () { $uibModalInstance.dismiss(); };
$scope.askForEncryptionKey = function() {
return $scope.encryption.encrypted && $scope.accountData.backup_type == 1 && $scope.accountData.encryption_key_type == 1;
};
$scope.ok = function () { $uibModalInstance.close(); };
$scope.calculateSummary = function() {
var gotData = false;
$scope.encryption.encrypted = false;
$scope.list_checked = {};
for(var contains in $scope.list) {
for(var i = 0; i < $scope.list[contains].length; i++) {
var backup = $scope.list[contains][i];
if(!backup.checked) continue;
if(!$scope.encryption.encrypted && backup.encrypted) $scope.encryption.encrypted = true;
if($scope.list_checked[contains] === undefined) $scope.list_checked[contains] = [];
$scope.list_checked[contains].push($scope.list[contains][i]);
gotData = true;
}
}
if(!gotData) $uibModalInstance.dismiss();
};
$scope.gotItems = function(types) {
for(var i = 0; i < types.length; i++) {
if($scope.list_checked[types[i]] !== undefined) return true;
}
return false;
};
$scope.restore = function() {
for(var i = 0; i < $scope.restore_conditions.length; i++) {
var condition = $scope.restore_conditions[i];
if($scope.conditions[condition._id] === undefined || !$scope.conditions[condition._id]) {
alert.error(lang.t("Please accept all restore conditions"));
return;
}
}
if($scope.askForEncryptionKey() && !$scope.encryption.key) {
alert.error(lang.t("You must provide \"Backups Private Encryption Key\""));
return;
}
var list = $scope.items;
var ids = [];
for(var i = 0; i < list.length; i++) if(list[i].checked) ids.push(list[i]._id);
var options = util.duplicateObject($scope.options);
api.addQueueItems({
data: { type: consts.QUEUE_ITEM_TYPE_RESTORE, items: ids, files: $scope.files, options: options, encryption_key: $scope.encryption.key },
success: function (data, message) {
$scope.encryption.key = '';
alert.success(message);
$uibModalInstance.close();
if($scope.summary_gotoqueue) $location.path("/queue");
},
failed: function (message) {
alert.error(message);
}
});
};
$scope.download = function() {
if($scope.askForEncryptionKey() && !$scope.encryption.key) {
alert.error(lang.t("You must provide \"Backups Private Encryption Key\""));
return;
}
var list = $scope.items;
var ids = [];
for(var i = 0; i < list.length; i++) if(list[i].checked) ids.push(list[i]._id);
api.addQueueItems({
data: { type: consts.QUEUE_ITEM_TYPE_DOWNLOAD, items: ids, files: $scope.files, encryption_key: $scope.encryption.key },
success: function (data, message) {
$scope.encryption.key = '';
alert.success(message);
$uibModalInstance.close();
if($scope.summary_gotoqueue) $location.path("/queue");
},
failed: function (message) {
alert.error(message);
}
});
};
$scope.removeItems = function(contains) {
for(var i = 0; i < $scope.list[contains].length; i++) {
var backup = $scope.list[contains][i];
backup.checked = false;
}
$scope.calculateSummary();
};
api.listRestoreConditions({
data: { find: { disabled: 0 } },
success: function (data) {
$scope.restore_conditions = data.conditions;
}
});
$scope.calculateSummary();
}
]
);
});
Zerion Mini Shell 1.0