All Downloads are FREE. Search and download functionalities are using the official Maven repository.

static.js.users.js Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
function saveUser(sel, url, successcallback) {

	var data = sel.serialize();
	
	$.ajax({
		type : 'POST',
		url  : url + "?" + data,
		contentType: 'application/json; charset=utf-8',
		dataType    : 'json',		
		success :  function(data) {
			
			hidemessages();
			showsuccess(sel, "User Saved");
			typeof successcallback === 'function' && successcallback(data);
		},
		error: function (data) {
			hidemessages();
			var text = JSON.parse(data.responseText)
			showerror(sel, "Unable to Save - " + text.message);
		}
	});
}

function updateUserListTable() {
	$.getJSON("/api/users/list", function() {
	})
	.done(function(data) {
		
		$("#userlisttable > tbody").html("");
		$("#userlisttable").append(
			    $.map(data.users, function (item, index) {
			    	return '' 
			    		+ '' + item.email + '' 
			    		+ '' + item.role + '' 
			    		+ '' + item.status + ''
			    		+ ''
			    		+ '';
		}).join());
	})
	.fail(function(data) {
		
		var text = JSON.parse(data.responseText)
		showerror("#usereditdiv", "Unable to Save User - " + text.data);
	});
}

function updateClientList() {
	$.getJSON("/api/clients/list", function(data) {
		$(".clientlist").append(
			    $.map(data.clients, function (item, index) {
			    	return '';
		}).join());
	});
}

function updateEditUserTable(email) {
	
	$('.email').attr("value", email);
	
	$.getJSON("/api/users/get?email=" + email, function(data) {		
		$('#statusedit').val(data.status);
		$('#roleedit').val(data.role);
		
		$("#userclientlisttable > tbody").html("");
		$("#userclientlisttable").append(
			    $.map(data.clients, function (item, index) {
			    	return '' 
			    		+ '' + item.client + '' 
			    		+ '' + item.clientname + '' 
			    		+ '';
		}).join());
	});
}

function backbutton() {
	updateUserListTable();
	$("#userlist").slideDown( "slow", function() {    				
		$("#useredit").hide();
		$("#useradd").hide();
		$("#userclientslist").hide();
		$("#adduserclients").hide();
		$("#useraddclient").val('');
		
		hidemessages();
	});
}

$(document).ready(function() {
	
	updateClientList();
	updateUserListTable();
	
	$("#useredit").hide();
	$("#useradd").hide();
	$("#userclientslist").hide();
	$("#adduserclients").hide();

	$("#userlisttable").on( "click", "button", function() {
		
		var list = $(this).closest('tr').children('td')
		var email = list[0].innerHTML;
		updateEditUserTable(email);
		
		$("#useredit").show();
		$("#userclientslist").show();
		$("#adduserclients").show();
		$("#useradd").hide();
		$("#userlist").slideUp( "slow", function() {			
		});
	});
	
	$("#adduserbutton").click(function() {
		$("#useradd").show();
		$("#userlist").slideUp( "slow", function() {
		});
	});

	$(".backbutton").click(function(){
		 backbutton();
	});

	$('#useraddform').submit(function(event) {
		saveUser($(this), "/api/users/save");
		return false;
	});
	
	$('#usereditform').submit(function(event) {
		saveUser($(this), "/api/users/save");
		return false;
	});
	
	$('#useraddclientform').submit(function(event) {
		saveUser($(this), "/api/users/save", function(data) {
			updateEditUserTable(data.id);
		});
		
		return false;
	});	
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy