///////////////////////////////////////////////////////////////////////////////
/// master.js
/// arangodb js api
///////////////////////////////////////////////////////////////////////////////
var welcomeMSG = ""
+ " _ \n"
+ " __ _ _ __ __ _ _ __ __ _ ___ ___| |__ \n"
+ " / _` | '__/ _` | '_ \\ / _` |/ _ \\/ __| '_ \\ \n"
+ " | (_| | | | (_| | | | | (_| | (_) \\__ \\ | | | \n"
+ " \\__,_|_| \\__,_|_| |_|\\__, |\\___/|___/_| |_| \n"
+ " |___/ \n"
+ " \n"
+ "Welcome to arangosh Copyright (c) 2012 triAGENS GmbH.";
var existingCharts;
var statDivCount;
// documents global vars
var collectionTotalPages;
var collectionCurrentPage;
var globalDocumentCopy = { };
var globalCollectionName;
var checkCollectionName;
var printedHelp = false;
var open = false;
var rowCounter = 0;
var shArray = [];
var BaseUrl = "/_admin/html/index.html";
// a static cache
var CollectionTypes = { };
$(document).ready(function() {
showCursor();
//hide incomplete functions
$("#uploadFile").attr("disabled", "disabled");
$("#uploadFileImport").attr("disabled", "disabled");
$("#uploadFileSearch").attr("disabled", "disabled");
///////////////////////////////////////////////////////////////////////////////
/// global variables
///////////////////////////////////////////////////////////////////////////////
var tableView = true;
var sid = ($.cookie("sid"));
var currentUser;
//logtable vars
var currentPage = 1;
var currentAmount;
var currentTableID = "#logTableID";
var currentLoglevel = 5;
//live click for all log tables
var tables = ["#logTableID", "#critLogTableID", "#warnLogTableID", "#infoLogTableID", "#debugLogTableID"];
$.each(tables, function(v, i ) {
$(i + '_prev').live('click', function () {
if ( i == "#logTableID" ) {
createNextPagination("all");
}
else {
createNextPagination();
}
});
$(i + '_next').live('click', function () {
if ( i == "#logTableID" ) {
createPrevPagination("all");
}
else {
createPrevPagination();
}
});
$(i + '_last').live('click', function () {
createLogTable(currentLoglevel);
});
$(i+ '_first').live('click', function () {
createLastLogPagination(i);
});
});
$("#documents_prev").live('click', function () {
createPrevDocPagination();
});
$("#documents_next").live('click', function () {
createNextDocPagination();
});
$("#documents_first").live('click', function () {
createFirstPagination("#documentsTable");
});
$("#documents_last").live('click', function () {
createLastPagination("#documentsTable");
});
///////////////////////////////////////////////////////////////////////////////
//statistics live click buttons close
///////////////////////////////////////////////////////////////////////////////
$(".statsClose").live('click', function () {
var divID = $(this).parent().parent();
var chart = $(this).parent().parent().attr('id');
var chartID = JSON.parse(chart.replace(/\D/g, '' ));
var todelete;
$.each(existingCharts, function(x, i ) {
var tempid = i.id;
if (tempid == chartID) {
todelete = x;
}
});
existingCharts.splice(todelete, 1);
$("#chartBox"+chartID).remove();
stateSaving();
if (temptop > 150 && templeft > 20) {
templeft = templeft - 10;
temptop = temptop - 10;
}
});
///////////////////////////////////////////////////////////////////////////////
// show statistic settings
///////////////////////////////////////////////////////////////////////////////
$(".statsSettings").live('click', function () {
var chartID = $(this).parent().next("div");
var settingsID = $(this).parent().next("div").next("div");
$(chartID).hide();
$(settingsID).fadeIn();
});
///////////////////////////////////////////////////////////////////////////////
// show statistics charts
///////////////////////////////////////////////////////////////////////////////
$(".statsCharts").live('click', function () {
var chartID = $(this).parent().next("div");
var settingsID = $(this).parent().next("div").next("div");
stateSaving();
updateChartBoxes();
$(settingsID).hide();
$(chartID).fadeIn();
});
///////////////////////////////////////////////////////////////////////////////
/// html customizations
///////////////////////////////////////////////////////////////////////////////
$('#logView ul').append('
');
///////////////////////////////////////////////////////////////////////////////
/// initialize jquery tabs
///////////////////////////////////////////////////////////////////////////////
$("#tabs").tabs({
select: function(event, ui) {
if (ui.index == 0) {
currentLoglevel = 5;
createLogTable(5);
}
else {
currentLoglevel = ui.index;
createLogTable(ui.index);
}
}
});
///////////////////////////////////////////////////////////////////////////////
/// disable grey'd out buttons
///////////////////////////////////////////////////////////////////////////////
$(".nofunction").attr("disabled", "true");
///////////////////////////////////////////////////////////////////////////////
/// checks for a login user cookie, creates new sessions if null
///////////////////////////////////////////////////////////////////////////////
// if ($.cookie("sid") == null) {
// $('#logoutButton').hide();
// $('#movetologinButton').show();
// $.ajax({
// type: "POST",
// url: "/_admin/user-manager/session/",
// contentType: "application/json",
// processData: false,
// success: function(data) {
// $.cookie("sid", data.sid);
// },
// error: function(data) {
// }
// });
// }
///////////////////////////////////////////////////////////////////////////////
/// if user exists, then:
///////////////////////////////////////////////////////////////////////////////
if ($.cookie("rights") != null || $.cookie("user") != null) {
$('#loginWindow').hide();
$('#movetologinButton').hide();
$('#logoutButton').show();
$('#activeUser').text($.cookie("user") + '!');
currentUser = $.cookie("user");
}
else {
$('#logoutButton').hide();
}
///////////////////////////////////////////////////////////////////////////////
/// draws collection table
///////////////////////////////////////////////////////////////////////////////
var collectionTable = $('#collectionsTableID').dataTable({
"aaSorting": [[ 2, "desc" ]],
"bPaginate": false,
"bFilter": false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": false,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{"sWidth":"150px", "bSortable":false, "sClass":"leftCell"}, {"sWidth": "200px"}, {"sWidth": "200px"}, {"sWidth": "150px"}, null, {"sWidth": "100px"}, {"sWidth": "200px"}, {"sWidth": "200px", "sClass":"rightCell"} ],
"aoColumnDefs": [{ "sClass": "alignRight", "aTargets": [ 6, 7 ] }],
"oLanguage": {"sEmptyTable": "No collections"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws the document edit table
///////////////////////////////////////////////////////////////////////////////
var documentEditTable = $('#documentEditTableID').dataTable({
"aaSorting": [[ 1, "desc" ]],
"bAutoWidth": false,
"bFilter": false,
"bPaginate":false,
"bSortable": false,
"bLengthChange": false,
"bDeferRender": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{"sClass":"read_only leftCell", "bSortable": false, "sWidth": "30px"},
{"sClass":"writeable", "bSortable": false, "sWidth":"400px" },
{"sClass":"writeable rightCell", "bSortable": false},
{"bVisible": false } ],
"oLanguage": {"sEmptyTable": "No documents"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws new doc view table
///////////////////////////////////////////////////////////////////////////////
var newDocumentTable = $('#NewDocumentTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bSortable": false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"read_only center leftCell","bSortable": false, "sWidth": "30px"},
{"sClass":"writeable", "bSortable": false, "sWidth":"250px" },
{"sClass":"writeable rightCell", "bSortable": false },
{"bVisible": false } ]
});
///////////////////////////////////////////////////////////////////////////////
/// draws documents table
///////////////////////////////////////////////////////////////////////////////
var documentsTable = $('#documentsTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bSortable": false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": false,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"read_only leftCell", "bSortable": false, "sWidth":"80px"},
{ "sClass":"read_only","bSortable": false, "sWidth": "200px"},
{ "sClass":"read_only","bSortable": false, "sWidth": "100px"},
{ "sClass":"read_only","bSortable": false, "sWidth": "100px"},
{ "bSortable": false, "sClass": "cuttedContent rightCell"}],
"oLanguage": { "sEmptyTable": "No documents"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws crit log table
///////////////////////////////////////////////////////////////////////////////
var critLogTable = $('#critLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No critical logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws warn log table
///////////////////////////////////////////////////////////////////////////////
var warnLogTable = $('#warnLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No warning logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws info log table
///////////////////////////////////////////////////////////////////////////////
var infoLogTable = $('#infoLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No info logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws debug log table
///////////////////////////////////////////////////////////////////////////////
var debugLogTable = $('#debugLogTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No debug logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// draws "all" log table
///////////////////////////////////////////////////////////////////////////////
var logTable = $('#logTableID').dataTable({
"bFilter": false,
"bPaginate":false,
"bLengthChange": false,
"bDeferRender": true,
"bAutoWidth": true,
"iDisplayLength": -1,
"bJQueryUI": true,
"aoColumns": [{ "sClass":"center", "sWidth": "100px", "bSortable":false}, {"bSortable":false}],
"oLanguage": {"sEmptyTable": "No logfiles available"}
});
///////////////////////////////////////////////////////////////////////////////
/// creates layout using jquery ui
///////////////////////////////////////////////////////////////////////////////
$('body').layout({
closable: false,
resizable: false,
applyDefaultStyles: false,
north__spacing_open: 0,
north__spacing_closed: 0,
center__spacing_open: 0,
south__spacing_open: 0,
south__spacing_closed: 0
});
///////////////////////////////////////////////////////////////////////////////
/// location check
///////////////////////////////////////////////////////////////////////////////
$.address.change(function(event) {
///////////////////////////////////////////////////////////////////////////////
/// Home
///////////////////////////////////////////////////////////////////////////////
if (location.hash == '' || location.hash =='#') {
drawCollectionsTable();
$('#subCenterView').hide();
$('#centerView').show();
$('#collectionsView').show();
createnav("Collections");
highlightNav("#nav1");
highlightNavButton("#Collections");
}
///////////////////////////////////////////////////////////////////////////////
/// new document table view (collection)
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 12) == "#collection," ) {
$("#addNewDocButton").removeAttr("disabled");
tableView = true;
$('#toggleNewDocButtonText').text('Edit Source');
var collectionID = location.hash.substr(12, location.hash.length);
var collID = collectionID.split(",");
$.ajax({
type: "GET",
url: "/_api/collection/" + collID[0] + "?" + getRandomToken(),
contentType: "application/json",
processData: false,
success: function(data) {
collectionName = data.name;
$('#nav2').text(collectionName);
$('#nav2').attr('href', '#showCollection,' +collID[0]);
$('#nav1').attr('class', 'arrowbg');
},
error: function(data) {
}
});
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav2').attr('class', 'arrowbg');
$('#nav3').text('new document');
highlightNav("#nav3");
newDocumentTable.fnClearTable();
documentTableMakeEditable('#NewDocumentTableID');
hideAllSubDivs();
$('#collectionsView').hide();
$('#newDocumentView').show();
$('#NewDocumentTableView').show();
$('#NewDocumentSourceView').hide();
}
///////////////////////////////////////////////////////////////////////////////
/// showe edit documents view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 14) == "#editDocument,") {
tableView = true;
$("#addEditedDocRowButton").removeAttr("disabled");
$('#toggleEditedDocButton').val('Edit Source');
$('#toggleEditedDocButtonText').text('Edit Source');
$('#documentEditSourceView').hide();
$('#documentEditTableView').show();
var collectiondocID = location.hash.substr(14, location.hash.length);
collectionID = collectiondocID.split("/");
$.ajax({
type: "GET",
url: "/_api/collection/" + collectionID + "?" + getRandomToken(),
contentType: "application/json",
processData: false,
success: function(data) {
collectionName = data.name;
$('#nav2').text(collectionName);
$('#nav2').attr('href', '#showCollection,' +collectionID[0]);
},
error: function(data) {
}
});
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav1').attr('class', 'arrowbg');
$('#nav2').attr('class', 'arrowbg');
$('#nav3').text('Edit document:' + collectionID[1]);
$.ajax({
type: "GET",
url: "/_api/document/" + collectiondocID + "?" + getRandomToken(),
contentType: "application/json",
processData: false,
success: function(data) {
$('#documentEditSourceBox').val(JSON.stringify(data));
documentEditTable.fnClearTable();
hideAllSubDivs();
$('#collectionsView').hide();
$('#documentEditView').show();
$('#documentEditSourceView').hide();
$.each(data, function(key, val) {
if (isSystemAttribute(key)) {
documentEditTable.fnAddData(["", key, value2html(val, true), JSON.stringify(val)]);
}
else {
documentEditTable.fnAddData(['',key, value2html(val), JSON.stringify(val)]);
}
});
documentTableMakeEditable('#documentEditTableID');
showCursor();
},
error: function(data) {
}
});
}
///////////////////////////////////////////////////////////////////////////////
/// show colletions documents view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 16) == "#showCollection,") {
$('#nav1').removeClass('highlighted');
var found = location.hash.match(/,([a-zA-Z0-9\-_]+)(,.+)?$/);
if (! found) {
throw "invalid URL";
}
globalAjaxCursorChange();
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav2').attr('href', null);
$('#nav3').text('');
highlightNav("#nav2");
$("#nav3").removeClass("arrowbg");
$("#nav2").removeClass("arrowbg");
$("#nav1").addClass("arrowbg");
hideAllSubDivs();
$('#collectionsView').hide();
$('#documentsView').show();
loadDocuments(found[1], collectionCurrentPage);
}
///////////////////////////////////////////////////////////////////////////////
/// shows edit collection view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash.substr(0, 16) == "#editCollection,") {
var collectionID = location.hash.substr(16, location.hash.length);
var collectionName;
var tmpStatus;
$.ajax({
type: "GET",
url: "/_api/collection/" + collectionID + "/properties" + "?" + getRandomToken(),
contentType: "application/json",
processData: false,
success: function(data) {
collectionName = data.name;
$('#nav2').text('Edit: ' + collectionName);
$('#editCollectionName').val(data.name);
$('#editCollectionID').text(data.id);
$('#editCollectionType').text(collectionType(data));
$('#editCollectionJournalSize').val(data.journalSize / 1024 / 1024);
$('input:radio[name=editWaitForSync][value=' + String(data.waitForSync) + ']').attr("checked", "checked");
switch (data.status) {
case 1: tmpStatus = "new born collection"; break;
case 2: tmpStatus = "unloaded"; break;
case 3: tmpStatus = "loaded"; break;
case 4: tmpStatus = "in the process of being unloaded"; break;
case 5: tmpStatus = "deleted"; break;
}
$('#editCollectionStatus').text(tmpStatus);
checkCollectionName = collectionName;
},
error: function(data) {
}
});
$('#nav1').text('Collections');
$('#nav1').attr('href', '#');
$('#nav1').attr('class', 'arrowbg');
hideAllSubDivs();
$('#collectionsView').hide();
$('#editCollectionView').show();
$('#editCollectionName').focus();
}
///////////////////////////////////////////////////////////////////////////////
/// shows log view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#logs") {
createLogTable(5);
hideAllSubDivs();
$('#collectionsView').hide();
$('#logView').show();
createnav ("Logs");
highlightNavButton("#Logs");
showCursor();
}
///////////////////////////////////////////////////////////////////////////////
/// shows status view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#status") {
$('#graphBox').empty();
stateReading();
hideAllSubDivs();
$('#collectionsView').hide();
$('#statusView').show();
createnav ("Statistics");
highlightNavButton("#Status");
makeDraggableAndResizable();
//TODO
createChartBoxes();
updateGraphs();
}
///////////////////////////////////////////////////////////////////////////////
/// shows query view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#query") {
hideAllSubDivs();
$('#collectionsView').hide();
$('#queryView').show();
createnav ("Query");
highlightNavButton("#Query");
$('#queryContent').focus();
}
///////////////////////////////////////////////////////////////////////////////
/// shows avocsh view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#avocsh") {
hideAllSubDivs();
$('#avocshContent').val('');
$('#collectionsView').hide();
$('#avocshView').show();
createnav ("ArangoDB Shell");
highlightNavButton("#AvocSH");
$('#avocshContent').focus();
if (printedHelp === false) {
print(welcomeMSG + require("arangosh").HELP);
printedHelp = true;
start_pretty_print();
}
$("#avocshContent").autocomplete({
source: shArray
});
}
///////////////////////////////////////////////////////////////////////////////
/// shows create new collection view
///////////////////////////////////////////////////////////////////////////////
else if (location.hash == "#createCollection") {
$('#nav1').attr('href', '#');
$('#nav1').text('Collections');
$('#nav2').text('Create new collection');
$('#nav1').attr('class', 'arrowbg');
highlightNavButton("#Collections");
hideAllSubDivs();
$('#collectionsView').hide();
$('#createCollectionView').show();
$('#createCollName').focus();
$('#createCollName').val('');
$('#createCollSize').val('');
}
});
///////////////////////////////////////////////////////////////////////////////
/// saves edited document
///////////////////////////////////////////////////////////////////////////////
$('#saveEditedDocButton').live('click', function () {
if (tableView == true) {
var data = documentEditTable.fnGetData();
var result = {};
var documentID;
for (row in data) {
var row_data = data[row];
if ( row_data[1] == "_id" ) {
documentID = JSON.parse(row_data[3]);
}
else {
result[row_data[1]] = JSON.parse(row_data[3]);
}
}
$.ajax({
type: "PUT",
url: "/_api/document/" + documentID,
data: JSON.stringify(result),
contentType: "application/json",
processData: false,
success: function(data) {
tableView = true;
var collID = documentID.split("/");
window.location.href = "#showCollection," + collID[0];
},
error: function(data) {
alert(getErrorMessage(data));
}
});
}
else {
try {
var documentID = globalDocumentCopy._id;
var boxContent = $('#documentEditSourceBox').val();
boxContent = stateReplace(boxContent);
parsedContent = JSON.parse(boxContent);
$.ajax({
type: "PUT",
url: "/_api/document/" + documentID,
data: JSON.stringify(parsedContent),
contentType: "application/json",
processData: false,
success: function(data) {
tableView = true;
$('#toggleEditedDocButton').val('Edit Source');
var collID = documentID.split("/");
window.location.href = "#showCollection," + collID[0];
},
error: function(data) {
alert(getErrorMessage(data));
}
});
}
catch(e) {
alert("Please make sure the entered value is a valid json string.");
}
}
});
///////////////////////////////////////////////////////////////////////////////
/// live click function for refreshLogButton
///////////////////////////////////////////////////////////////////////////////
$('#refreshLogButton').live('click', function () {
var selected = $("#tabs").tabs( "option", "selected" );
switch (selected) {
case 0:
createLogTable(5);
break;
default:
createLogTable(selected);
break;
}
});
///////////////////////////////////////////////////////////////////////////////
/// adds a new row in edit document view
///////////////////////////////////////////////////////////////////////////////
$('#addEditedDocRowButton').live('click', function () {
if (tableView == true) {
rowCounter = rowCounter + 1;
documentEditTable.fnAddData(['', "somekey" + rowCounter, value2html("editme"), JSON.stringify("editme")]);
documentTableMakeEditable('#documentEditTableID');
showCursor();
}
else {
}
});
///////////////////////////////////////////////////////////////////////////////
/// saves a new created document
///////////////////////////////////////////////////////////////////////////////
$('#saveNewDocButton').live('click', function () {
var post;
var found = location.hash.match(/,([a-zA-Z0-9\-_]+),.+$/);
if (! found) {
throw "invalid URL";
}
var collectionID = found[1];
if (tableView == true) {
var data = newDocumentTable.fnGetData();
var result = {};
for (row in data) {
var row_data = data[row];
result[row_data[1]] = JSON.parse(row_data[3]);
}
post = JSON.stringify(result);
}
else {
var boxContent = $('#NewDocumentSourceBox').val();
var jsonContent = JSON.parse(boxContent);
$.each(jsonContent, function(row1, row2) {
if ( row1 == '_id') {
collectionID = row2;
}
});
try {
post = JSON.stringify(jsonContent);
}
catch(e) {
alert("Please make sure the entered value is a valid json string.");
}
}
$.ajax({
type: "POST",
url: "/_api/" + collectionApiType(collectionID) + "?collection=" + collectionID,
data: post,
contentType: "application/json",
processData: false,
success: function(data) {
tableView = true;
window.location.href = "#showCollection," + collectionID;
},
error: function(data) {
alert(getErrorMessage(data));
}
});
});
///////////////////////////////////////////////////////////////////////////////
/// adds a new row in new document view
///////////////////////////////////////////////////////////////////////////////
$('#addNewDocButton').live('click', function () {
if (tableView == true) {
rowCounter = rowCounter + 1;
newDocumentTable.fnAddData(['', "somekey" + rowCounter, value2html("editme"), JSON.stringify("editme")]);
documentTableMakeEditable('#NewDocumentTableID');
showCursor();
}
else {
}
});
///////////////////////////////////////////////////////////////////////////////
/// toggle button for source / table - edit document view
///////////////////////////////////////////////////////////////////////////////
$('#toggleEditedDocButton').live('click', function () {
if (tableView == true) {
var content = documentEditTable.fnGetData();
var result = {};
for (row in content) {
var row_data = content[row];
result[row_data[1]] = JSON.parse(row_data[3]);
}
var copies = { }; // copy system attributes
for (var a in systemAttributes()) {
copies[a] = result[a];
delete result[a];
}
globalDocumentCopy = copies;
var myFormattedString = FormatJSON(result);
$('#documentEditSourceBox').val(myFormattedString);
$('#documentEditTableView').toggle();
$('#documentEditSourceView').toggle();
tableView = false;
$('#toggleEditedDocButtonText').text('Edit Table');
$("#addEditedDocRowButton").attr("disabled", "disabled");
}
else {
try {
var boxContent = $('#documentEditSourceBox').val();
boxContent = stateReplace(boxContent);
parsedContent = JSON.parse(boxContent);
documentEditTable.fnClearTable();
$.each(parsedContent, function(key, val) {
documentEditTable.fnAddData(['