Updated frontend
This commit is contained in:
+71
-248
@@ -1,91 +1,4 @@
|
||||
var app = {};
|
||||
|
||||
app.api = (function(app){
|
||||
var baseURL = '/api/'
|
||||
|
||||
function post(url, data, callack){
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callack(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function put(url, data, callack){
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callack(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function remove(url, callack, callack2){
|
||||
if(!$.isFunction(callack)) callack = callack2;
|
||||
$.ajax({
|
||||
type: 'delete',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callack(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function get(url, callack){
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: baseURL+url,
|
||||
headers:{
|
||||
'auth-token': app.auth.getToken()
|
||||
},
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
complete: function(res, text){
|
||||
callack(
|
||||
text !== 'success' ? res.statusText : null,
|
||||
JSON.parse(res.responseText),
|
||||
res.status
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {post: post, get: get, put: put, delete: remove}
|
||||
})(app)
|
||||
|
||||
app.auth = (function(app) {
|
||||
app._auth = (function(app) {
|
||||
var user = {}
|
||||
function setToken(token){
|
||||
localStorage.setItem('APIToken', token);
|
||||
@@ -143,9 +56,9 @@ app.auth = (function(app) {
|
||||
|
||||
app.user = (function(app){
|
||||
function list(callack){
|
||||
app.api.get('user/?detail=true', function(error, data){
|
||||
callack(error, data);
|
||||
})
|
||||
return app.api.get('user/?detail=true', function(error, data){
|
||||
if(callack) callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function add(args, callack){
|
||||
@@ -183,54 +96,26 @@ app.user = (function(app){
|
||||
});
|
||||
}
|
||||
|
||||
return {list, remove, createInvite};
|
||||
|
||||
})(app);
|
||||
|
||||
app.host = (function(app){
|
||||
function list(callack){
|
||||
app.api.get('host/?detail=true', function(error, data){
|
||||
callack(error, data.hosts)
|
||||
function setActive(uid, active, callack){
|
||||
app.api.put('user/' + uid + '/active', {active: active}, function(error, data){
|
||||
if(callack) callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function get(host, callack){
|
||||
app.api.get('host/' + host, function(error, data){
|
||||
callack(error, data)
|
||||
});
|
||||
}
|
||||
return {list, remove, createInvite, setActive};
|
||||
|
||||
function add(args, callack){
|
||||
app.api.post('host/', args, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function edit(args, callack){
|
||||
app.api.put('host/' + args.edit_host, args, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function remove(args, callack){
|
||||
app.api.delete('host/'+ args.host, function(error, data){
|
||||
callack(error, data);
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
list: list,
|
||||
get: get,
|
||||
add: add,
|
||||
edit: edit,
|
||||
remove: remove,
|
||||
}
|
||||
})(app);
|
||||
|
||||
app.group = (function(app){
|
||||
function list(callack){
|
||||
app.api.get('group?detail=true', function(error, data){
|
||||
callack(error, data);
|
||||
return app.api.get('group?detail=true', function(error, data){
|
||||
if(callack) callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function get(cn, callack){
|
||||
return app.api.get('group/' + cn + '?detail=true', function(error, data){
|
||||
if(callack) callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -240,133 +125,71 @@ app.group = (function(app){
|
||||
});
|
||||
}
|
||||
|
||||
return {list, remove}
|
||||
return {list, get, remove}
|
||||
})(app)
|
||||
|
||||
app.oauthClient = (function(app){
|
||||
function list(callack){
|
||||
return app.api.get('oauth/client/', function(error, data){
|
||||
if(callack) callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function add(args, callack){
|
||||
app.api.post('oauth/client/', args, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function remove(args, callack){
|
||||
if(!confirm('Delete OAuth client "' + args.client_id + '"?')) return false;
|
||||
app.api.delete('oauth/client/' + args.client_id, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function update(args, callack){
|
||||
app.api.put('oauth/client/' + args.client_id, args, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function rotateSecret(args, callack){
|
||||
app.api.post('oauth/client/' + args.client_id + '/rotate', {}, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
return { list, add, remove, update, rotateSecret };
|
||||
})(app);
|
||||
|
||||
app.impersonate = (function(app){
|
||||
function create(uid, callack){
|
||||
app.api.post('auth/impersonate/' + uid, {}, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function revoke(uid, callack){
|
||||
app.api.delete('auth/impersonate/' + uid, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
return {create, revoke};
|
||||
})(app);
|
||||
|
||||
app.token = (function(app){
|
||||
function list(name, callack){
|
||||
if($.isFunction(name)){
|
||||
callack = name;
|
||||
name = ''
|
||||
name = '';
|
||||
}
|
||||
app.api.get('token/'+name+'?detail=true', function(error, data){
|
||||
callack(error, data);
|
||||
return app.api.get('token/' + name + '?detail=true', function(error, data){
|
||||
if(callack) callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
return {list}
|
||||
})(app)
|
||||
|
||||
app.util = (function(app){
|
||||
|
||||
function getUrlParameter(name) {
|
||||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
||||
var results = regex.exec(location.search);
|
||||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
};
|
||||
|
||||
function actionMessage(message, $target, type){
|
||||
message = message || '';
|
||||
$target = $($target.closest('div.card').find('.actionMessage')[0]);
|
||||
type = type || 'info';
|
||||
|
||||
if($target.html() === message) return;
|
||||
|
||||
if($target.html()){
|
||||
$target.slideUp('fast', function(){
|
||||
$target.html('')
|
||||
$target.removeClass (function (index, className) {
|
||||
return (className.match (/(^|\s)bg-\S+/g) || []).join(' ');
|
||||
});
|
||||
if(message) actionMessage(message, $target, type);
|
||||
})
|
||||
return;
|
||||
}else{
|
||||
if(type) $target.addClass('bg-' + type);
|
||||
$target.html(message).slideDown('fast');
|
||||
}
|
||||
}
|
||||
|
||||
$.fn.serializeObject = function() {
|
||||
var
|
||||
arr = $(this).serializeArray(),
|
||||
obj = {};
|
||||
|
||||
for(var i = 0; i < arr.length; i++) {
|
||||
if(obj[arr[i].name] === undefined) {
|
||||
obj[arr[i].name] = arr[i].value;
|
||||
} else {
|
||||
if(!(obj[arr[i].name] instanceof Array)) {
|
||||
obj[arr[i].name] = [obj[arr[i].name]];
|
||||
}
|
||||
obj[arr[i].name].push(arr[i].value);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
return {
|
||||
getUrlParameter: getUrlParameter,
|
||||
actionMessage: actionMessage
|
||||
}
|
||||
})(app);
|
||||
|
||||
$.holdReady( true );
|
||||
if(!location.pathname.includes('/login')){
|
||||
app.auth.isLoggedIn(function(error, isLoggedIn){
|
||||
if(error || !isLoggedIn){
|
||||
app.auth.logOut(function(){})
|
||||
location.replace('/login/?redirect='+location.pathname);
|
||||
}else{
|
||||
$.holdReady( false );
|
||||
}
|
||||
})
|
||||
}else{
|
||||
$.holdReady( false );
|
||||
}
|
||||
|
||||
$( document ).ready( function () {
|
||||
|
||||
$( 'div.row' ).fadeIn( 'slow' ); //show the page
|
||||
|
||||
//panel button's
|
||||
$( '.fa-arrows-v' ).click( function () {
|
||||
$( this ).closest( '.card' ).find( '.card-body' ).slideToggle( 'fast' );
|
||||
});
|
||||
|
||||
|
||||
$( '.glyphicon-refresh' ).each( function () {
|
||||
$(this).click( function () {
|
||||
tableAJAX();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//ajax form submit
|
||||
function formAJAX( btn, del ) {
|
||||
event.preventDefault(); // avoid to execute the actual submit of the form.
|
||||
var $form = $(btn).closest( '[action]' ); // gets the 'form' parent
|
||||
var formData = $form.find( '[name]' ).serializeObject(); // builds query formDataing
|
||||
var method = $form.attr('method') || 'post';
|
||||
|
||||
if( !$form.validate()) {
|
||||
app.util.actionMessage('Please fix the form errors.', $form, 'danger')
|
||||
return false;
|
||||
}
|
||||
|
||||
app.util.actionMessage(
|
||||
'<div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div>',
|
||||
$form,
|
||||
'info'
|
||||
);
|
||||
|
||||
app.api[method]($form.attr('action'), formData, function(error, data){
|
||||
app.util.actionMessage(data.message, $form, error ? 'danger' : 'success'); //re-populate table
|
||||
if(!error){
|
||||
$form.trigger("reset");
|
||||
eval($form.attr('evalAJAX')); //gets JS to run after completion
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user