118 lines
3.4 KiB
JavaScript
118 lines
3.4 KiB
JavaScript
/* exported SettingsController */
|
|
/* global $:true */
|
|
|
|
'use strict';
|
|
|
|
|
|
var SettingsController = function ($scope, Client) {
|
|
$scope.user = Client.getUserInfo();
|
|
$scope.config = Client.getConfig();
|
|
$scope.nakedDomainApp = null;
|
|
$scope.drives = [];
|
|
|
|
$scope.setNakedDomain = function () {
|
|
var appid = $scope.nakedDomainApp ? $scope.nakedDomainApp.id : null;
|
|
|
|
Client.setNakedDomain(appid, function (error) {
|
|
if (error) return console.error('Error setting naked domain', error);
|
|
});
|
|
};
|
|
|
|
$scope.changePassword = function () {
|
|
window.location.href = '#/userpassword';
|
|
};
|
|
|
|
$scope.backup = function () {
|
|
$('#backupProgressModal').modal('show');
|
|
$scope.$parent.initialized = false;
|
|
|
|
Client.backup(function (error) {
|
|
if (error) console.error(error);
|
|
|
|
// now start query
|
|
function checkIfDone() {
|
|
Client.version(function (error) {
|
|
if (error) return window.setTimeout(checkIfDone, 1000);
|
|
|
|
$('#backupProgressModal').modal('hide');
|
|
$scope.$parent.initialized = true;
|
|
});
|
|
}
|
|
|
|
window.setTimeout(checkIfDone, 5000);
|
|
});
|
|
};
|
|
|
|
$scope.reboot = function () {
|
|
$('#rebootModal').modal('hide');
|
|
$('#rebootProgressModal').modal('show');
|
|
$scope.$parent.initialized = false;
|
|
|
|
Client.reboot(function (error) {
|
|
if (error) console.error(error);
|
|
|
|
// now start query
|
|
function checkIfDone() {
|
|
Client.version(function (error) {
|
|
if (error) return window.setTimeout(checkIfDone, 1000);
|
|
|
|
$('#rebootProgressModal').modal('hide');
|
|
|
|
window.setTimeout(window.location.reload.bind(window.location), 1000);
|
|
});
|
|
}
|
|
|
|
window.setTimeout(checkIfDone, 5000);
|
|
});
|
|
};
|
|
|
|
$scope.update = function () {
|
|
$('#updateModal').modal('hide');
|
|
$('#updateProgressModal').modal('show');
|
|
$scope.$parent.initialized = false;
|
|
|
|
Client.update(function (error) {
|
|
if (error) console.error(error);
|
|
|
|
// now start query
|
|
function checkIfDone() {
|
|
Client.version(function (error) {
|
|
if (error) return window.setTimeout(checkIfDone, 1000);
|
|
|
|
$('#updateProgressModal').modal('hide');
|
|
|
|
window.setTimeout(window.location.reload.bind(window.location), 1000);
|
|
});
|
|
}
|
|
|
|
window.setTimeout(checkIfDone, 5000);
|
|
});
|
|
};
|
|
|
|
Client.onConfig(function () {
|
|
$scope.tokenInUse = Client._token;
|
|
|
|
Client.getApps(function (error, apps) {
|
|
if (error) console.error('Error loading app list');
|
|
$scope.apps = apps;
|
|
|
|
Client.getNakedDomain(function (error, appid) {
|
|
if (error) return console.error(error);
|
|
|
|
for (var i = 0; i < $scope.apps.length; i++) {
|
|
if ($scope.apps[i].id === appid) {
|
|
$scope.nakedDomainApp = $scope.apps[i];
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
Client.stats(function (error, stats) {
|
|
if (error) return console.error(error);
|
|
|
|
$scope.drives = stats.drives;
|
|
});
|
|
});
|
|
});
|
|
};
|