Adopt @simpleworkjs/frontend's messages/modal/validate modules
Same swap as sso-manager-node/jump-host: vendored app.util.actionMessage/ actionConfirm replaced by @simpleworkjs/frontend's app.messages.action/ confirm (real HTML-escaping, toast fallback); vendored val.js replaced by the package's app.validate.js. proxy's host/target/hostname validation rules (mirrored from the backend's utils/hostname_validate.js — wildcard DNS patterns, not something other apps need) move to public/js/app.js, registered via $.validateSettings, since they're proxy-specific and don't belong in the shared package's generic rule set (eq/user/password/ip). app.api/app.auth/app.pubsub/app.socket in app-base.js are untouched, same reasoning as sso-manager-node's PR. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,14 +28,14 @@
|
||||
|
||||
function removeGroup(name){
|
||||
app.group.remove(name, function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.LocalGroup.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.LocalGroup.$this, 'danger');
|
||||
$.scope.LocalGroup.remove(name);
|
||||
});
|
||||
}
|
||||
|
||||
function removeMember(group, username){
|
||||
app.group.removeMember(group, username, function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.LocalGroup.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.LocalGroup.$this, 'danger');
|
||||
// websocket update echoes the new member list.
|
||||
});
|
||||
}
|
||||
@@ -47,14 +47,14 @@
|
||||
let username = ($input.val() || '').trim();
|
||||
if(!username) return;
|
||||
app.group.addMember(group, username, function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.LocalGroup.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.LocalGroup.$this, 'danger');
|
||||
$input.val('');
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
app.group.list(function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.LocalGroup.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.LocalGroup.$this, 'danger');
|
||||
for(let g of data.results) $.scope.LocalGroup.push(g);
|
||||
});
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
function hostPopulate(){
|
||||
app.api.get('host?detail=1&provider=1', function(error, res){
|
||||
if(error) return app.util.actionMessage(error, $.scope.hosts.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.hosts.$this, 'danger');
|
||||
|
||||
for(let host of res.results){
|
||||
$.scope.hosts.push(hostParseRow(host));
|
||||
@@ -152,9 +152,9 @@
|
||||
let password = $pass.val();
|
||||
if(!password) return;
|
||||
app.api.put('host/' + encodeURIComponent(host) + '/basicauth-user/' + encodeURIComponent(username), {password}, function(error, data){
|
||||
if(error) return app.util.actionMessage((data && data.message) || 'Failed to update password', $rows, 'danger');
|
||||
if(error) return app.messages.action((data && data.message) || 'Failed to update password', $rows, 'danger');
|
||||
$pass.val('');
|
||||
app.util.actionMessage('Password updated for "' + username + '".', $rows, 'success');
|
||||
app.messages.action('Password updated for "' + username + '".', $rows, 'success');
|
||||
});
|
||||
});
|
||||
// No confirm step, matching this form's existing "Delete" button
|
||||
@@ -163,7 +163,7 @@
|
||||
let $del = $('<button type="button" class="btn btn-sm btn-outline-danger"><i class="fa-solid fa-trash"></i></button>');
|
||||
$del.on('click', function(){
|
||||
app.api.delete('host/' + encodeURIComponent(host) + '/basicauth-user/' + encodeURIComponent(username), function(error, data){
|
||||
if(error) return app.util.actionMessage((data && data.message) || 'Failed to delete user', $rows, 'danger');
|
||||
if(error) return app.messages.action((data && data.message) || 'Failed to delete user', $rows, 'danger');
|
||||
$tr.remove();
|
||||
$('.basicauth-current').text(Object.keys((data && data.basicauth_users) || {}).join(', ') || 'none');
|
||||
});
|
||||
@@ -291,7 +291,7 @@
|
||||
|
||||
function hostDownloadCert(host, type){
|
||||
app.host.getCert({host}, function(error, data){
|
||||
if(error) app.util.actionMessage(error.message, $.scope.hosts.$this, 'danger');
|
||||
if(error) app.messages.action(error.message, $.scope.hosts.$this, 'danger');
|
||||
app.util.downloadFile(`${host}-${type}.crt`, data[type])
|
||||
});
|
||||
}
|
||||
@@ -322,9 +322,9 @@
|
||||
app.host.clearCache(function(error, data){
|
||||
$btn.prop('disabled', false);
|
||||
if(error){
|
||||
return app.util.actionMessage(error.message || error, $.scope.hosts.$this, 'danger');
|
||||
return app.messages.action(error.message || error, $.scope.hosts.$this, 'danger');
|
||||
}
|
||||
app.util.actionMessage(data.message, $.scope.hosts.$this, 'success');
|
||||
app.messages.action(data.message, $.scope.hosts.$this, 'success');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
function removePermission(id){
|
||||
app.permission.remove(id, function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.Permission.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.Permission.$this, 'danger');
|
||||
// The websocket echo removes the row; drop it locally too for snappiness.
|
||||
$.scope.Permission.remove(id);
|
||||
});
|
||||
@@ -51,7 +51,7 @@
|
||||
$(document).ready(function(){
|
||||
// Existing permissions.
|
||||
app.permission.list(function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.Permission.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.Permission.$this, 'danger');
|
||||
for(let p of data.results) $.scope.Permission.push(p);
|
||||
});
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
$(document).ready(function(){
|
||||
app.api.get('user/me', function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $('#profile-card'), 'danger');
|
||||
if(error) return app.messages.action(error, $('#profile-card'), 'danger');
|
||||
renderProfile(data);
|
||||
});
|
||||
});
|
||||
@@ -170,7 +170,7 @@
|
||||
|
||||
function tableAJAX(){
|
||||
app.apiToken.list(function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.apiTokenCard.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.apiTokenCard.$this, 'danger');
|
||||
$.scope.apiTokenCard.empty();
|
||||
(data.results || []).forEach(function(token){
|
||||
$.scope.apiTokenCard.push(processToken(token));
|
||||
@@ -181,7 +181,7 @@
|
||||
function revokeToken(id, name, btn){
|
||||
if(!confirm('Revoke API token "' + name + '"? It stops working immediately.')) return;
|
||||
app.apiToken.remove({id: id}, function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $(btn).closest('.card'), 'danger');
|
||||
if(error) return app.messages.action(error, $(btn).closest('.card'), 'danger');
|
||||
$.scope.apiTokenCard.remove('id', id);
|
||||
});
|
||||
}
|
||||
@@ -189,7 +189,7 @@
|
||||
function rotateToken(id, name, btn){
|
||||
if(!confirm('Rotate API token "' + name + '"? The old token stops working immediately.')) return;
|
||||
app.apiToken.rotate({id: id}, function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $(btn).closest('.card'), 'danger');
|
||||
if(error) return app.messages.action(error, $(btn).closest('.card'), 'danger');
|
||||
showSecret(data.token);
|
||||
tableAJAX();
|
||||
});
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
<script type="text/javascript" src="/static-modules/@fortawesome/fontawesome-free/js/all.min.js"></script>
|
||||
<script type="text/javascript" src='/static-modules/mustache/mustache.min.js'></script>
|
||||
<script type="text/javascript" src='/static-modules/jq-repeat/dist/js/jq-repeat.js'></script>
|
||||
<script type="text/javascript" src='/static/lib/js/val.js'></script>
|
||||
<script type="text/javascript" src="/static-modules/moment/moment.js"></script>
|
||||
<script type="text/javascript" src="/static/lib/js/app-base.js"></script>
|
||||
<script type="text/javascript" src="/static-modules/@simpleworkjs/frontend/lib/app.messages.js"></script>
|
||||
<script type="text/javascript" src="/static-modules/@simpleworkjs/frontend/lib/app.modal.js"></script>
|
||||
<script type="text/javascript" src="/static-modules/@simpleworkjs/frontend/lib/app.validate.js"></script>
|
||||
<script type="text/javascript" src="/static/js/app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
function populateUsers(actionMessage){
|
||||
app.user.list(function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.users.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.users.$this, 'danger');
|
||||
for(let user of data.results){
|
||||
$.scope.users.push(user);
|
||||
}
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
function removeUser(username){
|
||||
app.user.remove({username: username}, function(error, data){
|
||||
if(error) return app.util.actionMessage(error, $.scope.users.$this, 'danger');
|
||||
if(error) return app.messages.action(error, $.scope.users.$this, 'danger');
|
||||
$.scope.users.remove(username);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user