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

static.js.forms.js Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
function updateClientList() {
	$.getJSON("/api/clients/list", function(data) {
		$(".clientlist").append(
			    $.map(data.clients, function (item, index) {
			    	return '';
		}).join());
		
		clientListOnChange();
	});
}

function clientListOnChange() {
	var client = $("#formsclient");
	updateFormsTable(client.val());
}

function updateFormsTable(client) {
	
	$.getJSON("/api/forms/list?client=" + client, function(data) {
		
		var count = 0;
		$("#formlisttable > tbody").html("");
		$("#formlisttable").append(
			    $.map(data.forms, function (item, index) {
			    	count++;
			    	return '' 
			    		+ '' + item.name + '' 
			    		+ '' + item.uuid + ''
			    		+ '' + item.updated_date + ''
			    		+ ''
			    		+ '';
		}).join());
			
		if (count == 0) {
			$("#formlisttable").append("No Forms");
		}
	});
}

function updateFormsTable2(formname, formuuid) {
	
	var client = $("#formsclient").val();
	
	$("#formlisttitle2").html(formname + " Form(s)");
	$.getJSON("/api/forms/list?client=" + client + "&form=" + formuuid, function(data) {
		
		var count = 0;
		$("#formlisttable2 > tbody").html("");
		$("#formlisttable2").append(
			    $.map(data.forms, function (item, index) {
			    	count++;
			    	return '' 
			    		+ '' + item.name + '' 
			    		+ '' + item.uuid + ''
			    		+ '' + item.updated_date + ''
			    		+ '';
		}).join());
			
		if (count == 0) {
			$("#formlisttable2").append("No Forms");
		}
	});
}

function backbutton() {

	updateClientList();
	
	$("#formlist").slideDown( "slow", function() {    				
		$("#uploadform").hide();		
		hidemessages();
	});
}

$(document).ready(function() {
	
	$("#uploadform").hide();
	$("#formlist2").hide();
	
	updateClientList();
	
	$(".clientlist").change(function() {
		clientListOnChange();
	});
	
	$(".backbutton").click(function(){
		 backbutton();
	});
	
	$("#formlisttable").on( "click", "button", function() {
		
		var list = $(this).closest('tr').children('td')
		var name = list[0].innerHTML;
		var uuid = list[1].innerHTML;
		updateFormsTable2(name, uuid);
		
		$("#formlist2").slideDown( "fast", function() {
		});
	});
	
	$("#uploadformbutton").click(function() {
		$("#uploadform").show();
		$("#formlist2").hide();
		$("#formlist").slideUp( "slow", function() {
		});
	});
	
	$('#uploadformform').submit(function(e) {
		
	    $.ajax( {
			url: '/api/forms/save',
			type: 'POST',
			contentType: false,
			data: new FormData(this),
			processData: false
	    }).done(function() {
    		hidemessages();
			showsuccess("#uploadformform", "Form Uploaded");
			document.getElementById("uploadformform").reset();
  		}).fail(function(data) {  		
    		hidemessages();
			var text = JSON.parse(data.responseText)
			showerror("#uploadformform", "Unable to Upload - " + text.message);
		});
	    
	    e.preventDefault();
	});
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy