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

static.js.clients.js Maven / Gradle / Ivy

function saveClient(sel, url, type) {

	var data = sel.serialize();
	
	$.ajax({
		headers: {          
             Accept : "application/vnd.formkiq.v1+json"
		},
		type : 'POST',
		url  : url + "?" + data,
		contentType: 'application/json; charset=utf-8',
		dataType    : 'json',		
		success :  function(data) {
			hidemessages();			
			showsuccess(sel, "Client " + type);
		},
		error: function (data) {
			hidemessages();
			var text = JSON.parse(data.responseText)
			showerror(sel, "Unable to " + type + " Client - " + text.message);
		}
	});
}		

function updateClient(client) {
	
	$.getJSON("/api/clients/get?client=" + client, function(data) {	
		$(".clientname").attr("value", data.clientname);
		$(".client").attr("value", data.client);
	});
}

function updateClientListTable(token) {
	$.getJSON("/api/clients/list?token=" + token, function() {
	})
	.done(function(data) {
		
		$("#clientlisttable > tbody").html("");
		$("#clientlisttable").append(
			    $.map(data.clients, function (item, index) {
			    	return '' + item.client + '' 
			    		+ '' + item.clientname + '' 
			    		+ '' 
			    		+ '  '
			    		+ '  '
			    		+ ''
			    		+ ''
			    		+ '';
		}).join());
		
		if (data.prevtoken === undefined) {
			$('#prev-button').hide();
		} else {
			$('#prev-button').show();
			$('#prev-button').data('token', data.prevtoken);
		}
		
		if (data.nexttoken === undefined) {
			$('#next-button').hide();
		} else {
			$("#next-button").data("token", data.nexttoken );			
			$('#next-button').show();
		}	
	})
	.fail(function(data) {
		
		var text = JSON.parse(data.responseText)
		showerror("#clienteditdiv", "Unable to Save Client - " + text.data);
	});
}

function backbutton() {
	updateClientListTable("");
	$("#clientlist").slideDown( "slow", function() {    				
		$("#clientadd").hide();
		$("#clientedit").hide();
		$("#clientresetsecret").hide();
		$("#clientdelete").hide();
	});
}

$(document).ready(function() {

	$("#clientadd").hide();
	$("#clientedit").hide();
	$("#clientresetsecret").hide();
	$("#clientdelete").hide();
	
	updateClientListTable("");
	
	$("#generatetokens").click(function() {
		$('#client').attr("value", makeid(5));
		$('#clientsecret').attr("value", makeid(10));
	});
		
	$("#generatetokens2").click(function() {
		$('#clientsecret2').attr("value", makeid(10));
	});
	
	$('.clientsave').submit(function(event) {
		saveClient($(this), "/api/clients/save", "Save")
		return false;
	});	
	
	$('.deleteclient').submit(function(event) {
		saveClient($(this), "/api/clients/delete", "Delete")
		return false;
	});	
	
	$("#addclientbutton").click(function() {
		$("#clientadd").show();
		$("#clientlist").slideUp( "slow", function() {
		});
	});
	
	$(".backbutton").click(function(){
		 backbutton();
	});
	
	$("#clientlisttable").on( "click", "button", function() {
				
		var client = $(this).data("client");
		updateClient(client);
		
		if ($(this).text() == "Delete") {

			$("#clientdelete").show();
			$("#clientlist").slideUp( "slow", function() {			
			});

		} else if ($(this).text() == "Reset Secret") {
			
			$("#clientresetsecret").show();
			$("#clientlist").slideUp( "slow", function() {			
			});
			
		} else {

			$("#clientedit").show();
			$("#clientlist").slideUp( "slow", function() {			
			});
		}
	});
	
	$("#next-button").click(function() {
		var token = $("#next-button").data("token");
		updateClientListTable(token);
	});
	
	$("#prev-button").click(function() {
		var token = $("#prev-button").data("token");
		updateClientListTable(token);
	});
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy