Provide select dropdown for app inbox

This commit is contained in:
Johannes Zellner
2021-12-03 11:23:25 +01:00
parent b9b2ebe202
commit e248b2aacf
3 changed files with 53 additions and 50 deletions

View File

@@ -804,6 +804,10 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
}
};
function findInbox(inboxes, app) {
return inboxes.find(function (i) { return i.name === app.inboxName && i.domain === (app.inboxDomain || app.domain); });
}
$scope.email = {
enableMailbox: true,
mailboxName: '',
@@ -813,13 +817,12 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
mailboxError: {},
mailboxBusy: false,
enableInbox: true,
inboxName: '',
inboxDomain: null,
currentInboxName: '',
currentInboxDomainName: '',
inboxError: {},
inboxBusy: false,
enableInbox: true,
inboxes: [],
currentInbox: null,
inbox: null,
show: function () {
var app = $scope.app;
@@ -832,13 +835,16 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.email.currentMailboxName = app.mailboxName || '';
$scope.email.currentMailboxDomainName = $scope.email.mailboxDomain ? $scope.email.mailboxDomain.domain : '';
$scope.inboxForm.$setPristine();
$scope.email.inboxError = {};
$scope.email.enableInbox = app.enableInbox ? '1' : '0';
$scope.email.inboxName = app.inboxName || '';
$scope.email.inboxDomain = $scope.domains.filter(function (d) { return d.domain === (app.inboxDomain || app.domain); })[0];
$scope.email.currentInboxName = app.inboxName || '';
$scope.email.currentInboxDomainName = $scope.email.inboxDomain ? $scope.email.inboxDomain.domain : '';
$scope.email.enableInbox = app.enableInbox ? true : false;
Client.getAllMailboxes(function (error, mailboxes) {
if (error) console.error('Failed to list mailboxes.', error);
$scope.email.inboxes = mailboxes.map(function (m) { return { display: m.name + '@' + m.domain, name: m.name, domain: m.domain }; });
$scope.email.currentInbox = findInbox($scope.email.inboxes, app);
$scope.email.inbox = findInbox($scope.email.inboxes, app);
});
},
submitMailbox: function () {
@@ -885,34 +891,29 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.email.inboxBusy = true;
var data = {
enable: $scope.email.enableInbox === '1'
enable: $scope.email.enableInbox
};
if (data.enable) {
data.inboxName = $scope.email.inboxName;
data.inboxDomain = $scope.email.inboxDomain.domain;
data.inboxName = $scope.email.inbox.name;
data.inboxDomain = $scope.email.inbox.domain;
}
Client.configureApp($scope.app.id, 'inbox', data, function (error) {
if (error && error.statusCode === 400) {
$scope.email.inboxBusy = false;
$scope.email.error.inboxName = error.message;
$scope.inboxForm.$setPristine();
return;
}
if (error) return Client.error(error);
$scope.inboxForm.$setPristine();
refreshApp($scope.app.id, function (error) {
if (error) return Client.error(error);
// when the mailboxName is 'reset', this will fill it up with the default again
$scope.email.enableInbox = $scope.app.enableInbox ? '1' : '0';
$scope.email.inboxName = $scope.app.inboxName || '';
$scope.email.inboxDomain = $scope.domains.filter(function (d) { return d.domain === ($scope.app.inboxDomain || $scope.app.domain); })[0];
$scope.email.currentInboxName = $scope.app.inboxName || '';
$scope.email.currentInboxDomainName = $scope.email.inboxDomain ? $scope.email.inboxDomain.domain : '';
$scope.email.enableInbox = $scope.app.enableInbox ? true : false;
$scope.email.currentInbox = findInbox($scope.email.inboxes, $scope.app);
$scope.email.inbox = findInbox($scope.email.inboxes, $scope.app);
$timeout(function () { $scope.email.inboxBusy = false; }, 1000);
});