Skip to content

Commit abe817e

Browse files
Update password set function to give feedback in the same way as updating persistence and delay
1 parent 5f6aa72 commit abe817e

2 files changed

Lines changed: 46 additions & 28 deletions

File tree

amplipi/updater/static/index.html

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,43 @@ <h1><span class="text-white">Ampli</span><span class="text-danger">Pi</span></h1
109109
}
110110
}
111111

112+
async function set_password() {
113+
const password_box = document.getElementById("password");
114+
const password = password_box.value
115+
const confirm_password_box = document.getElementById("confirm-password");
116+
const confirm_password = confirm_password_box.value
117+
118+
const button = document.getElementById('password-submit');
119+
const spinner = document.getElementById('password-spinner');
120+
const success = document.getElementById('password-success');
121+
const fail = document.getElementById('password-fail');
122+
const no_match = document.getElementById('password-no-match');
123+
124+
if(password != confirm_password) {
125+
setVisibility(no_match, fail, success, spinner, button);
126+
} else {
127+
body = JSON.stringify({'password':password})
128+
129+
res = await fetch('/password', {
130+
method: 'POST',
131+
body: body,
132+
headers: {
133+
"Content-Type": "application/json",
134+
}
135+
});
136+
137+
if(res.ok) {
138+
setVisibility(success, spinner, button, fail, no_match);
139+
} else {
140+
setVisibility(fail, success, spinner, button, no_match);
141+
}
142+
}
143+
144+
setTimeout(() => { // Reset to default after delay at the end
145+
setVisibility(button, spinner, success, fail, no_match);
146+
}, 1500);
147+
}
148+
112149
async function getPersist() {
113150
const response = await fetch("/settings/persist_logs", { method: "GET" });
114151
const data = await response.json();
@@ -180,7 +217,15 @@ <h6 class="hover-label">
180217
<input id="confirm-password" type="password">
181218
</div>
182219
<div>
183-
<a id="password" role="button" class="btn btn-primary btn-sm text-center" onClick="set_password();">Update Password</a>
220+
<a id="password-submit" role="button" class="btn btn-primary btn-sm text-center" onClick="set_password();">Update Password</a>
221+
<a id="password-success" role="button" class="btn btn-primary btn-sm text-center" style="display: none; background-color: #00AA00;">Success!</a>
222+
<a id="password-fail" role="button" class="btn btn-primary btn-sm text-center" style="display: none; background-color: #DD0000;">Failure...</a>
223+
<a id="password-no-match" role="button" class="btn btn-primary btn-sm text-center" style="display: none; background-color: #DD0000;">Passwords do not match!</a>
224+
<div id="password-spinner" style="display: none;">
225+
<i class="fa fa-circle-o-notch fa-spin" style="font-size:24px"></i>
226+
</div>
227+
</div>
228+
<div>
184229
</div>
185230
</div>
186231
</div>

amplipi/updater/static/js/update-ui.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -243,33 +243,6 @@ function populate_available_releases(releases) {
243243
}
244244
}
245245

246-
async function set_password() {
247-
password = $('#password').val()
248-
confirm_password = $('#confirm-password').val()
249-
250-
if(password != confirm_password) {
251-
alert("Passwords do not match.");
252-
return;
253-
}
254-
255-
body = JSON.stringify({'password':password})
256-
257-
res = await fetch('/password', {
258-
method: 'POST',
259-
body: body,
260-
headers: {
261-
"Content-Type": "application/json",
262-
}
263-
});
264-
265-
if(!res.ok) {
266-
alert(`Error: ${res.statusText}`);
267-
return;
268-
}
269-
270-
alert('Password set.');
271-
}
272-
273246
async function requestSupportTunnel() {
274247
// the below is 2 lines long intentionally, because it renders into a <pre> tag.
275248
$('#support-tunnel-detail').text(`Requesting a support tunnel. This may take up to 60s.

0 commit comments

Comments
 (0)