groups and reset
This commit is contained in:
		| @ -43,7 +43,8 @@ app.api = (function(app){ | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	function remove(url, callack){ | ||||
| 	function remove(url, callack, callack2){ | ||||
| 		if(!$.isFunction(callack)) callack = callack2; | ||||
| 		$.ajax({ | ||||
| 			type: 'delete', | ||||
| 			url: baseURL+url, | ||||
| @ -129,6 +130,7 @@ app.auth = (function(app) { | ||||
|  | ||||
| 	return { | ||||
| 		getToken: getToken, | ||||
| 		setToken: setToken, | ||||
| 		isLoggedIn: isLoggedIn, | ||||
| 		logIn: logIn, | ||||
| 		logOut: logOut, | ||||
| @ -222,6 +224,22 @@ app.host = (function(app){ | ||||
| 	} | ||||
| })(app); | ||||
|  | ||||
| app.group = (function(app){ | ||||
| 	function list(callack){ | ||||
| 		app.api.get('group?detail=true', function(error, data){ | ||||
| 			callack(error, data); | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	function remove(args, callack){ | ||||
| 		app.api.delete('group/'+args.cn, function(error, data){ | ||||
| 			callack(error, data); | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	return {list, remove} | ||||
| })(app) | ||||
|  | ||||
| app.util = (function(app){ | ||||
|  | ||||
| 	function getUrlParameter(name) { | ||||
| @ -231,21 +249,24 @@ app.util = (function(app){ | ||||
| 	    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); | ||||
| 	}; | ||||
|  | ||||
| 	function actionMessage(message, options){ | ||||
| 		options = options || {}; | ||||
| 		$target = options.$target || $('div.actionMessage'); | ||||
| 	function actionMessage(message, $target, type){ | ||||
| 		message = message || ''; | ||||
| 		$target = $target.closest('div.card').find('.actionMessage'); | ||||
| 		type = type || 'info'; | ||||
|  | ||||
| 		if($target.html() === message) return; | ||||
|  | ||||
| 		if($target.html()){ | ||||
| 			$target.slideUp('fast', function(){ | ||||
| 				$target.html('') | ||||
| 				if(message) actionMessage(message, options); | ||||
| 				$target.removeClass (function (index, className) { | ||||
| 					return (className.match (/(^|\s)bg-\S+/g) || []).join(' '); | ||||
| 				}); | ||||
| 				if(message) actionMessage(message, $target, type); | ||||
| 			}) | ||||
| 			return; | ||||
| 		}else{ | ||||
| 			if(options.type) $target.addClass('alert-' + options.type); | ||||
| 			if(type) $target.addClass('bg-' + type); | ||||
| 			$target.html(message).slideDown('fast'); | ||||
| 		} | ||||
| 	} | ||||
| @ -277,7 +298,10 @@ app.util = (function(app){ | ||||
| $.holdReady( true ); | ||||
| if(!location.pathname.includes('/login')){ | ||||
| 	app.auth.isLoggedIn(function(error, isLoggedIn){ | ||||
| 			console.log('here', error, isLoggedIn) | ||||
|  | ||||
| 		if(error || !isLoggedIn){ | ||||
| 			app.auth.logOut(function(){}) | ||||
| 			location.replace('/login/?redirect='+location.pathname); | ||||
| 		}else{ | ||||
| 			$.holdReady( false ); | ||||
| @ -296,9 +320,6 @@ $( document ).ready( function () { | ||||
| 		$( this ).closest( '.card' ).find( '.card-body' ).slideToggle( 'fast' ); | ||||
| 	}); | ||||
|  | ||||
| 	$( '.glyphicon-remove-circle' ).click( function () { | ||||
| 		$( this ).closest( 'div.panel' ).slideUp( 'fast' ); | ||||
| 	}); | ||||
|  | ||||
| 	$( '.glyphicon-refresh' ).each( function () { | ||||
| 		$(this).click( function () { | ||||
| @ -314,19 +335,21 @@ function formAJAX( btn, del ) { | ||||
| 	var formData = $form.find( '[name]' ).serializeObject(); // builds query formDataing | ||||
| 	var method = $form.attr('method') || 'post'; | ||||
|  | ||||
| 	if( !$form.validate( | ||||
| 		{ | ||||
| 			form: { | ||||
| 				alertCount: true, | ||||
| 				alertCountMessage: " errors found on this form!" | ||||
| 			} | ||||
| 		}) ) { | ||||
| 	app.util.actionMessage(  | ||||
| 		'<div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div>', | ||||
| 		$form, | ||||
| 		'info' | ||||
| 	); | ||||
|  | ||||
| 	if( !$form.validate()) { | ||||
| 		app.util.actionMessage('Please fix the form errors.', $form, 'danger') | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	app.api[method]($form.attr( 'action' ), formData, function(error, data){ | ||||
| 		app.util.actionMessage( data.message ); //re-populate table | ||||
| 	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