June 25 - Optimize codes
This commit is contained in:
@@ -31,8 +31,8 @@
|
||||
<td><span class="badge badge-{{ 'success' if u.is_active else 'danger' }}">{{ 'Yes' if u.is_active else 'No' }}</span></td>
|
||||
<td class="text-muted">{{ u.created_at.strftime('%Y-%m-%d') if u.created_at else '—' }}</td>
|
||||
<td class="actions">
|
||||
<button class="btn btn-ghost btn-sm"
|
||||
onclick='openEditUser({{ u|tojson }})'>✎ Edit</button>
|
||||
<button class="btn btn-ghost btn-sm js-edit-user"
|
||||
data-user="{{ u|tojson|e }}">✎ Edit</button>
|
||||
{% if u.email %}
|
||||
<button class="btn btn-ghost btn-sm js-send-reset"
|
||||
data-id="{{ u.id }}" data-username="{{ u.username }}" data-email="{{ u.email }}"
|
||||
@@ -170,6 +170,13 @@ document.querySelectorAll('.js-delete-user').forEach(function(btn) {
|
||||
});
|
||||
});
|
||||
|
||||
/* Edit user — data-user attribute avoids single-quote apostrophe breakage */
|
||||
document.querySelectorAll('.js-edit-user').forEach(function(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
openEditUser(JSON.parse(btn.dataset.user));
|
||||
});
|
||||
});
|
||||
|
||||
function openEditUser(u) {
|
||||
document.getElementById('edit-username').value = u.username;
|
||||
document.getElementById('edit-full-name').value = u.full_name || '';
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{{ url_for('static', filename='js/pw-strength.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
|
||||
@@ -46,23 +46,7 @@
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
(function() {
|
||||
var input = document.getElementById('password');
|
||||
var fill = document.getElementById('pw-fill');
|
||||
var lbl = document.getElementById('pw-label');
|
||||
var map = ['pw-weak','pw-weak','pw-fair','pw-strong','pw-great','pw-great'];
|
||||
var lbls = ['Weak','Weak','Fair','Strong','Very strong','Very strong'];
|
||||
input.addEventListener('input', function() {
|
||||
if (!this.value) { fill.className='pw-strength-fill'; lbl.className='pw-strength-label'; lbl.textContent=''; return; }
|
||||
var pw=this.value, s=0;
|
||||
if (pw.length>=8) s++; if (pw.length>=12) s++;
|
||||
if (/[A-Z]/.test(pw)) s++; if (/[0-9]/.test(pw)) s++; if (/[^A-Za-z0-9]/.test(pw)) s++;
|
||||
fill.className='pw-strength-fill '+map[s];
|
||||
lbl.className='pw-strength-label '+map[s];
|
||||
lbl.textContent=lbls[s];
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
<script src="{{ url_for('static', filename='js/pw-strength.js') }}"></script>
|
||||
<script>attachPasswordStrength('password', 'pw-fill', 'pw-label');</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -293,13 +293,22 @@ document.getElementById('site-list').addEventListener('click', function(e) {
|
||||
method: 'POST', credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded', 'X-CSRFToken': getCsrfToken()},
|
||||
body: 'user_note='
|
||||
}).then(function() {
|
||||
}).then(function(r) {
|
||||
if (!r.ok) throw new Error('Server error ' + r.status);
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'alert alert-success';
|
||||
toast.style.cssText = 'position:fixed;top:1rem;right:1rem;z-index:9999;min-width:220px;box-shadow:var(--shadow)';
|
||||
toast.textContent = '✔ ' + siteName + ' marked checked';
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(function() { location.reload(); }, 700);
|
||||
}).catch(function(err) {
|
||||
btn.disabled = false;
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'alert alert-danger';
|
||||
toast.style.cssText = 'position:fixed;top:1rem;right:1rem;z-index:9999;min-width:220px;box-shadow:var(--shadow)';
|
||||
toast.textContent = '✖ Failed to mark checked. Please try again.';
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(function() { toast.remove(); }, 4000);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -353,13 +362,22 @@ document.getElementById('site-list').addEventListener('click', function(e) {
|
||||
method: 'POST', credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded', 'X-CSRFToken': getCsrfToken()},
|
||||
body: ''
|
||||
}).then(function() {
|
||||
}).then(function(r) {
|
||||
if (!r.ok) throw new Error('Server error ' + r.status);
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'alert alert-info';
|
||||
toast.style.cssText = 'position:fixed;top:1rem;right:1rem;z-index:9999;min-width:220px;box-shadow:var(--shadow)';
|
||||
toast.textContent = '↩ Check removed for ' + siteName;
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(function() { location.reload(); }, 700);
|
||||
}).catch(function(err) {
|
||||
btn.disabled = false;
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'alert alert-danger';
|
||||
toast.style.cssText = 'position:fixed;top:1rem;right:1rem;z-index:9999;min-width:220px;box-shadow:var(--shadow)';
|
||||
toast.textContent = '✖ Failed to remove check. Please try again.';
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(function() { toast.remove(); }, 4000);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user