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
+7 -28
View File
@@ -1019,43 +1019,22 @@
<div class="radio">
<label>
<input type="radio" ng-model="email.enableInbox" value="1"> {{ 'app.email.inbox.enable' | tr }}
<input type="radio" ng-model="email.enableInbox" ng-value="true"> {{ 'app.email.inbox.enable' | tr }}
</label>
</div>
<div ng-style="{ 'padding-left': '20px' }">
<p ng-bind-html="'app.email.inbox.enableDescription' | tr:{ domain: app.domain, domainConfigLink: ('/#/email/' + app.domain) }"></p>
<form role="form" name="inboxForm" ng-submit="email.submitInbox()" autocomplete="off">
<fieldset ng-disabled="email.enableInbox === '0'">
<div class="form-group" ng-class="{ 'has-error': inboxForm.$dirty && email.error.inboxName }">
<div class="has-error" ng-show="email.error.inboxName">{{ email.error.inboxName }}</div>
<div class="input-group form-inline" ng-class="{ 'has-error': !inboxForm.inboxName.$dirty && email.error.inboxName }">
<input type="text" ng-required="email.enableInbox === '1'" class="form-control" name="inboxName" ng-model="email.inboxName">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span>{{ '@' + email.inboxDomain.domain }}</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li ng-repeat="domain in domains">
<a href="" ng-click="email.inboxDomain = domain">{{ domain.domain }}</a>
</li>
</ul>
</div>
</div>
<br/>
</div>
</fieldset>
<input class="ng-hide" type="submit" ng-disabled="(email.currentInboxDomainName === email.inboxDomain.domain && email.currentInboxName === email.inboxName) || email.inboxBusy || app.error || app.taskId"/>
</form>
<div class="form-group" ng-class="{ 'has-error': email.error.inboxName }">
<div class="has-error" ng-show="email.error.inboxName">{{ email.error.inboxName }}</div>
<multiselect name="inboxSelect" ng-model="email.inbox" ng-disabled="!email.enableInbox" options="inbox.display for inbox in email.inboxes" data-multiple="false" filter-after-rows="5" scroll-after-rows="10"></multiselect>
</div>
</div>
<div class="radio">
<label>
<input type="radio" ng-model="email.enableInbox" value="0"> {{ 'app.email.inbox.disable' | tr }}
<input type="radio" ng-model="email.enableInbox" ng-value="false"> {{ 'app.email.inbox.disable' | tr }}
</label>
</div>
@@ -1067,7 +1046,7 @@
<div class="row" ng-show="app.manifest.addons.recvmail">
<div class="col-md-12 text-right">
<br/>
<button class="btn btn-outline btn-primary pull-right" ng-click="email.submitInbox()" ng-disabled="inboxForm.$invalid || (app.enableInbox === email.enableInbox && email.currentInboxDomainName === email.inboxDomain.domain && email.currentInboxName === email.inboxName) || email.inboxBusy || app.error || app.taskId" tooltip-enable="app.error || app.taskId" uib-tooltip="{{ app.error ? 'App is in error state' : 'App is busy' }}">
<button class="btn btn-outline btn-primary pull-right" ng-click="email.submitInbox()" ng-disabled="(email.enableInbox && !email.inbox) || (app.enableInbox === email.enableInbox && email.currentInbox.name === email.inbox.name && email.currentInbox.domain === email.inbox.domain) || email.inboxBusy || app.error || app.taskId" tooltip-enable="app.error || app.taskId" uib-tooltip="{{ app.error ? 'App is in error state' : 'App is busy' }}">
<i class="fa fa-circle-notch fa-spin" ng-show="email.inboxBusy"></i> {{ 'app.email.from.saveAction' | tr }}
</button>
</div>
+23 -22
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);
});