Fix account switcher: use currentEmail as ng-model so display updates immediately

This commit is contained in:
usmannasir
2026-03-05 05:34:32 +05:00
parent 3705dcc7b8
commit a9f48d6781
2 changed files with 8 additions and 8 deletions

View File

@@ -109,7 +109,6 @@ app.controller('webmailCtrl', ['$scope', '$http', '$sce', '$timeout', function($
// ── State ────────────────────────────────────────────────
$scope.currentEmail = '';
$scope.managedAccounts = [];
$scope.switchEmail = '';
$scope.folders = [];
$scope.currentFolder = 'INBOX';
$scope.messages = [];
@@ -169,7 +168,6 @@ app.controller('webmailCtrl', ['$scope', '$http', '$sce', '$timeout', function($
if (data.status === 1) {
$scope.currentEmail = data.email;
$scope.managedAccounts = data.accounts || [];
$scope.switchEmail = data.email;
$scope.loadFolders();
$scope.loadSettings();
} else {
@@ -180,10 +178,10 @@ app.controller('webmailCtrl', ['$scope', '$http', '$sce', '$timeout', function($
// ── Account Switching ────────────────────────────────────
$scope.switchAccount = function() {
if (!$scope.switchEmail || $scope.switchEmail === $scope.currentEmail) return;
apiCall('/webmail/api/switchAccount', {email: $scope.switchEmail}, function(data) {
var newEmail = $scope.currentEmail;
if (!newEmail) return;
apiCall('/webmail/api/switchAccount', {email: newEmail}, function(data) {
if (data.status === 1) {
$scope.currentEmail = data.email;
$scope.currentFolder = 'INBOX';
$scope.currentPage = 1;
$scope.openMsg = null;
@@ -195,8 +193,10 @@ app.controller('webmailCtrl', ['$scope', '$http', '$sce', '$timeout', function($
$scope.loadFolders();
$scope.loadSettings();
} else {
notify(data.error_message, 'error');
notify(data.error_message || 'Failed to switch account', 'error');
}
}, function() {
notify('Failed to switch account', 'error');
});
};

View File

@@ -15,7 +15,7 @@
<span>{$ currentEmail $}</span>
</div>
<div class="wm-account-switch">
<select ng-model="switchEmail" ng-change="switchAccount()"
<select ng-model="currentEmail" ng-change="switchAccount()"
ng-options="a for a in managedAccounts" class="wm-account-select">
</select>
</div>
@@ -435,6 +435,6 @@
</div>
</div>
<script src="{% static 'webmail/webmail.js' %}?v=2"></script>
<script src="{% static 'webmail/webmail.js' %}?v=3"></script>
{% endblock %}