static.js.forms.js Maven / Gradle / Ivy
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, token) {
var type = $("#type").val();
$.getJSON("/api/" + type + "s/list?client=" + client + "&token=" + token, function(data) {
var count = 0;
var list = data.forms;
if (type == "workflow") {
list = data.workflows;
}
$("#formlisttable > tbody").html("");
$("#formlisttable").append(
$.map(list, function (item, index) {
count++;
return ''
+ '' + item.name + ' '
+ '' + item.uuid + ' '
+ '' + item.updated_date + ' '
+ ''
+ ''
+ ' '
+ ''
+ ' '
+ ''
+ ' '
+ ' ';
}).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();
}
if (count == 0) {
$("#formlisttable").append("No " + type + "s ");
}
});
}
function backbutton() {
updateClientList();
$("#formlist").slideDown( "slow", function() {
$("#uploadform").hide();
$("#formdelete").hide();
hidemessages();
});
}
$(document).ready(function() {
$("#formdelete").hide();
$("#uploadform").hide();
updateClientList();
$(".clientlist").change(function() {
clientListOnChange();
});
$(".backbutton").click(function(){
backbutton();
});
$("#next-button").click(function() {
var client = $("#formsclient");
var token = $("#next-button").data("token");
updateFormsTable(client.val(), token);
});
$("#prev-button").click(function() {
var client = $("#formsclient");
var token = $("#prev-button").data("token");
updateFormsTable(client.val(), token);
});
$("#uploadformbutton").click(function() {
$("#uploadform").show();
$("#formlist").slideUp( "slow", function() {
});
});
$('#uploadformform').submit(function(e) {
var type = $("#type").val();
$.ajax( {
url: '/api/' + type + 's/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();
});
$("#formlisttable").on( "click", "button", function() {
if ($(this).text() == "Delete") {
var type = $("#type").val();
var client = $(this).data("client");
$('.client').attr("value", client);
var uuid = $(this).data("uuid");
$('.uuid').attr("value", uuid);
var name = $(this).data("name");
$('.name').attr("value", name);
$("#formdelete").show();
$("#formlist").slideUp( "slow", function() {
});
}
});
$(".deleteform").submit(function(event) {
deleteForm($(this));
return false;
});
});