Mini Shell
define([
'app',
], function(app) {
app.controller("restore_enduser",
["$rootScope", "$scope", "$routeParams", "$location", "$timeout", "$interval", "api", "meta", "lang", "popup", "permissions", "consts",
function($rootScope, $scope, $routeParams, $location, $timeout, $interval, api, meta, lang, popup, permissions, consts) {
$rootScope.$emit('menuItem', 'Restore');
$scope.currentSection = {};
$scope.selected = {};
$scope.sectionTemplate = '';
$scope.sections = [
{_id: 'full', name: lang.t("Full Account"), icon: 'fa-cubes', hidden: !permissions.canManageFullBackups},
{_id: 'files', name: lang.t("Home Directory"), icon: 'fa-folder', hidden: !permissions.canManageFileBackups},
{_id: 'cron', name: lang.t("Cron Jobs"), icon: 'fa-user-clock', hidden: !permissions.canManageCronBackups},
{_id: 'db', name: lang.t("Databases"), icon: 'fa-database', hidden: !permissions.canManageDatabaseBackups},
{_id: 'dbuser', name: lang.t("Database Users"), icon: 'fa-user-tie', hidden: !permissions.canManageDatabaseBackups},
{_id: 'dns', name: lang.t("Domains"), icon: 'fa-map-marker-alt', hidden: !permissions.canManageDNSZoneBackups},
{_id: 'ssl', name: lang.t("Certificates"), icon: 'fa-lock', hidden: !permissions.canManageCertificateBackups},
{_id: 'email', name: lang.t("Email Accounts"), icon: 'fa-envelope', hidden: !permissions.canManageEmailBackups},
{_id: 'ftp', name: lang.t("FTP Accounts"), icon: 'fa-file', hidden: !permissions.canManageFTPBackups}
];
$scope.saveNotes = function (backup, keyEvent) {
backup.notes = backup.notes.substr(0, 40);
if(keyEvent && keyEvent.which !== 13) return;
api.manageBackupNotes({
data: { _id: backup._id, notes: backup.notes },
success: function (data, message) { alert.success(message); },
failed: function (message) { alert.error(message); },
});
backup.editing = false;
};
$scope.isSelected = function () {
for(var id in $scope.selected) return true;
return false;
};
$scope.isSelectedBackup = function (backup) {
return $scope.selected[backup._id] !== undefined;
};
$scope.selectedBackup = function(backup) {
if($scope.selected[backup._id] !== undefined) delete $scope.selected[backup._id];
else $scope.selected[backup._id] = backup;
};
$scope.prepareSummary = function (type) {
var backups = [];
for(var id in $scope.selected) backups.push($scope.selected[id]);
$scope.showSummary(type, backups);
};
$scope.changeBackup = function(backup) {
backup.options = [];
if(backup.new_id === backup._id) {
backup.options_real = {};
backup.new_id = '';
return;
}
var oldId = backup._id;
var newBackup = backup.options_real[backup.new_id];
for(var key in newBackup) backup[key] = newBackup[key];
if($scope.selected[oldId] !== undefined) {
delete $scope.selected[oldId];
$scope.selected[backup._id] = backup;
}
backup.options_real = {};
backup.new_id = '';
};
$scope.selectBackup = function(backup) {
backup.new_id = backup._id;
backup.options = [];
backup.options_real = {};
var apiParams = {
account_id: backup.account_id,
type: backup.backup_type,
contains: backup.backup_contains,
name: backup.name,
sort: { created: -1 }
};
if(backup.params.engine !== undefined) apiParams.engine = backup.params.engine;
api.listBackupForTypeName({
data: apiParams,
success: function (data) {
for(var i = 0; i < data.backups.length; i++) {
backup.options.push({ _id: data.backups[i]._id, display: lang.d(data.backups[i].created, 'shorttime') });
backup.options_real[data.backups[i]._id] = data.backups[i];
}
}
});
};
$scope.showSummary = function (type, items, files) {
popup.open({
size: "xl",
template: 'backups',
templateViews: 'views_enduser',
controller: 'backups_enduser',
resolve: {
section: function () { return $scope.currentSection; },
summary: function () { return type; },
items: function() { return items; },
files: function () { return files !== undefined ? files : {}; }
}
}).result.then(function(refresh) {
if(refresh) $scope.fetch();
}, function(){});
};
$scope.changeSection = function (section) {
$scope.changeView('restore/' + section._id);
};
$scope.loadSection = function (type) {
for(var i = 0; i < $scope.sections.length; i++) {
var section = $scope.sections[i];
if(section._id !== type || section.hidden) continue;
$scope.currentSection = section;
$scope.sectionTemplate = $scope.includePath('restore/' + section._id, 'views_enduser');
return;
}
for(var i = 0; i < $scope.sections.length; i++) {
var section = $scope.sections[i];
if(section.hidden) continue;
$scope.currentSection = section;
$scope.sectionTemplate = $scope.includePath('restore/' + section._id, 'views_enduser');
return;
}
};
$scope.loadSection($routeParams.type);
}
]
);
});
Zerion Mini Shell 1.0