gui
This commit is contained in:
@ -23,6 +23,45 @@ app.api = (function(app){
|
||||
});
|
||||
}
|
||||
|
||||
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){
|
||||
$.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',
|
||||
@ -42,7 +81,7 @@ app.api = (function(app){
|
||||
});
|
||||
}
|
||||
|
||||
return {post: post, get: get}
|
||||
return {post: post, get: get, put: put, delete: remove}
|
||||
})(app)
|
||||
|
||||
app.auth = (function(app) {
|
||||
@ -56,11 +95,11 @@ app.auth = (function(app) {
|
||||
|
||||
function isLoggedIn(callack){
|
||||
if(getToken()){
|
||||
return app.api.get('users/me', function(error, data){
|
||||
return app.api.get('user/me', function(error, data){
|
||||
return callack(error, data.username);
|
||||
})
|
||||
}else{
|
||||
callack(false, false);
|
||||
callack(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,20 +112,50 @@ app.auth = (function(app) {
|
||||
});
|
||||
}
|
||||
|
||||
function logOut(){
|
||||
localStorage.removeItem('APIToken');
|
||||
}
|
||||
|
||||
return {
|
||||
getToken: getToken,
|
||||
isLoggedIn: isLoggedIn,
|
||||
logIn:logIn
|
||||
logIn: logIn,
|
||||
logOut: logOut,
|
||||
}
|
||||
|
||||
})(app);
|
||||
|
||||
app.users = (function(app){
|
||||
app.user = (function(app){
|
||||
function list(callack){
|
||||
app.api.get('user/?detail=true', function(error, data){
|
||||
callack(error, data);
|
||||
})
|
||||
}
|
||||
|
||||
function add(args, callack){
|
||||
app.api.post('user/', args, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function remove(args, callack){
|
||||
app.api.delete('user/'+ args.username, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function changePassword(args, callack){
|
||||
app.api.put('users/'+ arg.username || '', args, function(error, data){
|
||||
callack(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function createInvite(callack){
|
||||
app.api.post('users/invite', function(error, data, status){
|
||||
app.api.post('user/invite', function(error, data, status){
|
||||
callack(error, data.token);
|
||||
});
|
||||
}
|
||||
|
||||
function consumeInvite(args){
|
||||
app.api.post('/auth/invite/'+args.token, args, function(error, data){
|
||||
if(data.token){
|
||||
@ -96,31 +165,48 @@ app.users = (function(app){
|
||||
callack(error)
|
||||
});
|
||||
}
|
||||
|
||||
return {list, remove};
|
||||
|
||||
})(app);
|
||||
|
||||
app.hosts = (function(app){
|
||||
app.host = (function(app){
|
||||
function list(callack){
|
||||
app.api.get('hosts/?detail=true', function(error, data){
|
||||
app.api.get('host/?detail=true', function(error, data){
|
||||
callack(error, data.hosts)
|
||||
});
|
||||
}
|
||||
|
||||
function get(host, callack){
|
||||
app.api.get('hosts/' + host, function(error, data){
|
||||
app.api.get('host/' + host, function(error, data){
|
||||
callack(error, data)
|
||||
});
|
||||
}
|
||||
|
||||
function add(args, callack){
|
||||
app.api.post('hosts/', args, function(error, data){
|
||||
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
|
||||
add: add,
|
||||
edit: edit,
|
||||
remove: remove,
|
||||
}
|
||||
})(app);
|
||||
|
||||
@ -133,18 +219,21 @@ app.util = (function(app){
|
||||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
};
|
||||
|
||||
function actionMessage(message, $target){
|
||||
$target = $target || $('div.actionMessage');
|
||||
function actionMessage(message, options){
|
||||
options = options || {};
|
||||
$target = options.$target || $('div.actionMessage');
|
||||
message = message || '';
|
||||
|
||||
if($target.html() === message) return;
|
||||
|
||||
if($target.html()){
|
||||
$target.slideUp('fast', function(){
|
||||
$target.html('')
|
||||
if(message) actionMessage(message);
|
||||
if(message) actionMessage(message, options);
|
||||
})
|
||||
return;
|
||||
}else{
|
||||
if(options.type) $target.addClass('alert-' + options.type);
|
||||
$target.html(message).slideDown('fast');
|
||||
}
|
||||
}
|
||||
@ -173,7 +262,18 @@ app.util = (function(app){
|
||||
}
|
||||
})(app);
|
||||
|
||||
|
||||
$.holdReady( true );
|
||||
if(!location.pathname.includes('/login')){
|
||||
app.auth.isLoggedIn(function(error, isLoggedIn){
|
||||
if(error || !isLoggedIn){
|
||||
location.replace('/login/?redirect='+location.pathname);
|
||||
}else{
|
||||
$.holdReady( false );
|
||||
}
|
||||
})
|
||||
}else{
|
||||
$.holdReady( false );
|
||||
}
|
||||
|
||||
$( document ).ready( function () {
|
||||
|
||||
@ -195,9 +295,14 @@ $( document ).ready( function () {
|
||||
|
||||
//ajax form submit
|
||||
function formAJAX( btn, del ) {
|
||||
var $form = $(btn).closest( '[action]' ), // gets the 'form' parent
|
||||
str = $form.find( '[name]' ).serialize(); // builds query string
|
||||
/*if( !$form.validate(
|
||||
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';
|
||||
|
||||
console.log('formAJAX method', method)
|
||||
|
||||
if( !$form.validate(
|
||||
{
|
||||
form: {
|
||||
alertCount: true,
|
||||
@ -205,21 +310,11 @@ function formAJAX( btn, del ) {
|
||||
}
|
||||
}) ) {
|
||||
return false;
|
||||
}*/
|
||||
if( del ){ // delete request
|
||||
if( confirm( 'Are you sure?' ) ) {
|
||||
str += "&deleteThis=true"; // adds delete to query string
|
||||
}else{
|
||||
event.preventDefault(); // avoid to execute the actual submit of the form
|
||||
return false; //cancels function
|
||||
}
|
||||
}
|
||||
|
||||
$.post( $form.attr( 'action' ), str, function ( data ) { // sends post data to server validate
|
||||
tableAJAX( data.action_message ); //re-populate table
|
||||
app.api[method]($form.attr( 'action' ), formData, function(error, data){
|
||||
tableAJAX( data.message ); //re-populate table
|
||||
eval( $form.attr( 'evalAJAX' ) ); //gets JS to run after completion
|
||||
});
|
||||
|
||||
eval( $form.attr( 'evalAJAX' ) ); //gets JS to run after completion
|
||||
event.preventDefault(); // avoid to execute the actual submit of the form.
|
||||
return false; // avoid to execute the actual submit of the form.
|
||||
}
|
@ -140,7 +140,7 @@ $.validateSettings({
|
||||
password: function( value ) {
|
||||
var reg = /^(?=[^\d_].*?\d)\w(\w|[!@#$%]){1,48}/;
|
||||
if ( reg.test( value ) === false ) {
|
||||
return "Try again";
|
||||
return "Weak password, Try again";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user