/////////////////////////////////////////////////////////////////////////////// /// master.js /// avocadodb js api /////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { showCursor(); /////////////////////////////////////////////////////////////////////////////// /// global variables /////////////////////////////////////////////////////////////////////////////// var userScreenSize = $(window).width(); var open = false; 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 + '_next').live('click', function () { createNextPagination(); }); $(i + '_prev').live('click', function () { createPrevPagination(); }); }); /////////////////////////////////////////////////////////////////////////////// /// html customizations /////////////////////////////////////////////////////////////////////////////// $('#logView ul').append('
'); /////////////////////////////////////////////////////////////////////////////// /// initialize jquery tabs /////////////////////////////////////////////////////////////////////////////// $("#tabs").tabs({ select: function(event, ui) { if (ui.index == 0) { createLogTable(5); } else { createLogTable(ui.index); } } }); /////////////////////////////////////////////////////////////////////////////// /// 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({ "bFilter": false, "bLengthChange": false, "bDeferRender": true, "bAutoWidth": false, "iDisplayLength": -1, "bJQueryUI": true, "aoColumns": [{"sWidth":"150px", "bSortable":false}, null, null, null, null, null ], "oLanguage": {"sEmptyTable": "No collections"} }); /////////////////////////////////////////////////////////////////////////////// /// draws the document edit table /////////////////////////////////////////////////////////////////////////////// var documentEditTable = $('#documentEditTableID').dataTable({ "aaSorting": [], "bFilter": false, "bPaginate":false, "bSortable": false, "bLengthChange": false, "bDeferRender": true, "bAutoWidth": true, "iDisplayLength": -1, "bJQueryUI": true, "aoColumns": [{ "sClass":"center", "sClass":"read_only","bSortable": false, "sWidth": "30px"}, {"sClass":"writeable", "bSortable": false }, {"sClass":"writeable", "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":"center", "sClass":"read_only","bSortable": false, "sWidth": "170px"}, {"sClass":"writeable", "bSortable": false }, {"sClass":"writeable", "bSortable": false }, {"bVisible": false}] }); /////////////////////////////////////////////////////////////////////////////// /// draws documents table /////////////////////////////////////////////////////////////////////////////// var documentsTable = $('#documentsTableID').dataTable({ "bFilter": false, "bPaginate":false, "bSortable": false, "bLengthChange": false, "bDeferRender": true, "bAutoWidth": true, "iDisplayLength": -1, "bJQueryUI": true, "aoColumns": [{ "sClass":"center", "sClass":"read_only","bSortable": false, "sWidth": "80px"}, {"sClass":"read_only","bSortable": false, "sWidth": "125px"}, {"sClass":"read_only","bSortable": false, "sWidth": "60px"}, {"bSortable": false}], "oLanguage": {"sEmptyTable": "No documents"} }); /////////////////////////////////////////////////////////////////////////////// /// draws edit collection table /////////////////////////////////////////////////////////////////////////////// var editCollectionTable = $('#editCollectionTableID').dataTable({ "bFilter": false, "bPaginate":false, "bSortable": false, "bLengthChange": false, "bDeferRender": true, "bAutoWidth": true, "iDisplayLength": -1, "bJQueryUI": true, "aoColumns": [{ "sClass":"center", "sClass":"read_only","bSortable": false, "sWidth": "100px"}, {"sClass":"read_only","bSortable": false}, {"sClass":"read_only","bSortable": false}] }); /////////////////////////////////////////////////////////////////////////////// /// draws create collection table /////////////////////////////////////////////////////////////////////////////// var createCollectionTable = $('#createCollectionTableID').dataTable({ "bFilter": false, "bPaginate":false, "bSortable": false, "bLengthChange": false, "bDeferRender": true, "bAutoWidth": true, "iDisplayLength": -1, "bJQueryUI": true, "aoColumns": [{ "sClass":"center", "sClass":"read_only","bSortable": false, "sWidth": "100px"}, {"sClass":"read_only","bSortable": false}, {"bSortable": false}] }); /////////////////////////////////////////////////////////////////////////////// /// 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}], "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}], "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}], "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}], "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}], "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, center__spacing_open:0, south__spacing_closed: 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"); } /////////////////////////////////////////////////////////////////////////////// /// new document table view (collection) /////////////////////////////////////////////////////////////////////////////// else if (location.hash.substr(0, 12) == "#collection?" ) { tableView = true; var collectionID = location.hash.substr(12, location.hash.length); var collID = collectionID.split("="); $.ajax({ type: "GET", url: "/_api/collection/" + collID[0], contentType: "application/json", processData: false, success: function(data) { collectionName = data.name; $('#nav2').text('-> ' + collectionName); $('#nav2').attr('href', '#showCollection?' +collID[0]); }, error: function(data) { } }); $('#nav1').text('Collections'); $('#nav1').attr('href', '#'); $('#nav3').text('-> New Document'); newDocumentTable.fnClearTable(); newDocumentTable.fnAddData(['', "key", value2html("clicktoedit"), "clicktoedit" ]); 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; var collectiondocID = location.hash.substr(14, location.hash.length); collectionID = collectiondocID.split("/"); $.ajax({ type: "GET", url: "/_api/collection/" + collectionID, 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', '#'); $('#nav3').text('-> Edit:' + collectionID[1]); $.ajax({ type: "GET", url: "/document/" + collectiondocID, 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 (key == '_id' || key == '_rev') { documentEditTable.fnAddData(["", key, val, val]); } else { documentEditTable.fnAddData(['',key, value2html(val), val]); } }); documentTableMakeEditable('#documentEditTableID'); }, error: function(data) { } }); } /////////////////////////////////////////////////////////////////////////////// /// show colletions documents view /////////////////////////////////////////////////////////////////////////////// else if (location.hash.substr(0, 16) == "#showCollection?") { var collectionID = location.hash.substr(16, location.hash.length); var collectionName; $.ajax({ type: "GET", url: "/_api/collection/" + collectionID, contentType: "application/json", processData: false, success: function(data) { collectionName = data.name; $('#nav2').text('-> ' + collectionName); }, error: function(data) { } }); $('#nav1').text('Collections'); $('#nav1').attr('href', '#'); $('#nav2').attr('href', null); $('#nav3').text(''); $.ajax({ type: "GET", url: "/document?collection=" + collectionID, contentType: "application/json", processData: false, success: function(data) { documentsTable.fnClearTable(); hideAllSubDivs(); $('#collectionsView').hide(); $('#documentsView').show(); $.each(data, function(key, val) { $.each(val, function(key, val) { $.ajax({ type: "GET", url: val, contentType: "application/json", processData: false, success: function(data) { var dataString; var content; dataString = JSON.stringify(data); var escapedContent = escaped(dataString); var userContent; if (userScreenSize <= 1024) { userContent = 150; } else if (userScreenSize > 1024 && userScreenSize < 1680) { userContent = 250; } else if (userScreenSize > 1680) { userContent = 350; } if (escapedContent.length > userContent) { content = escapedContent.substr(0,(userContent-3))+'...'; } else { content = escapedContent; } documentsTable.fnAddData(['', data._id, data._rev, content]); }, error: function (data) { } }); }); }); }, error: function(data) { } }); } /////////////////////////////////////////////////////////////////////////////// /// shows edit collection view /////////////////////////////////////////////////////////////////////////////// else if (location.hash.substr(0, 16) == "#editCollection?") { var collectionID = location.hash.substr(16, location.hash.length); var collectionName; $.ajax({ type: "GET", url: "/_api/collection/" + collectionID, contentType: "application/json", processData: false, success: function(data) { collectionName = data.name; $('#nav2').text('-> Edit: ' + collectionName); }, error: function(data) { } }); $('#nav1').text('Collections'); $('#nav1').attr('href', '#'); $.ajax({ type: "GET", url: "/_api/collection/" + collectionID, contentType: "application/json", processData: false, success: function(data) { editCollectionTable.fnClearTable(); $.each(data, function(key, val) { if (key == 'name') { editCollectionTable.fnAddData(["editable", key, val]); } else if (key == 'status' || key == 'id') { editCollectionTable.fnAddData(["", key, val]); } }); hideAllSubDivs(); $('#collectionsView').hide(); $('#editCollectionView').show(); /* add custom cell class */ var i = 0; $('.read_only', editCollectionTable.fnGetNodes() ).each(function () { if ( i == 1) { $(this).removeClass('read_only'); i = 0; } if (this.innerHTML == "name") { i = 1; } }); $('#editCollectionTableID').dataTable().makeEditable({ sUpdateURL: function(value, settings) { return value; } }); }, error: function(data) { alert("error"); } }); } /////////////////////////////////////////////////////////////////////////////// /// shows log view /////////////////////////////////////////////////////////////////////////////// else if (location.hash == "#logs") { createLogTable(5); hideAllSubDivs(); $('#collectionsView').hide(); $('#logView').show(); createnav ("Logs"); } /////////////////////////////////////////////////////////////////////////////// /// shows status view /////////////////////////////////////////////////////////////////////////////// else if (location.hash == "#status") { hideAllSubDivs(); $('#collectionsView').hide(); $('#statusView').show(); createnav ("Status"); } /////////////////////////////////////////////////////////////////////////////// /// shows config view /////////////////////////////////////////////////////////////////////////////// else if (location.hash == "#config") { hideAllSubDivs(); $('#collectionsView').hide(); $('#configView').show(); createnav ("Config"); var content={"Menue":{"Haha":"wert1", "ahha":"wert2"}, "Favoriten":{"top10":"content"},"Test":{"testing":"hallo 123 test"}}; $("#configView").empty(); $.each(content, function(data) { $('#configView').append('' + client + '
'); try { var server = "server:" + eval(data); $('#avocshWindow').append('' + server + '
'); } catch(e) { $('#avocshWindow').append('Error:' + e + '
'); } $("#avocshWindow").animate({scrollTop:$("#avocshWindow")[0].scrollHeight}, 1); $("#avocshContent").val(''); return false; }); /////////////////////////////////////////////////////////////////////////////// /// submit query content /////////////////////////////////////////////////////////////////////////////// $('#submitQuery').live('click', function () { var data = {query:$('#queryContent').val()}; $.ajax({ type: "POST", url: "/_api/cursor", data: JSON.stringify(data), contentType: "application/json", processData: false, success: function(data) { $("#queryOutput").empty(); $("#queryOutput").append('' + JSON.stringify(data) + ''); }, error: function(data) { $("#queryOutput").empty(); $("#queryOutput").append('' + JSON.stringify(data) + ''); } }); }); /////////////////////////////////////////////////////////////////////////////// /// draws view of creating a new document /////////////////////////////////////////////////////////////////////////////// $('#addDocumentButton').live('click', function () { toSplit = window.location.hash; var collID = toSplit.split("?"); window.location.href = "#collection?" + collID[1] + "=newDocument"; }); /////////////////////////////////////////////////////////////////////////////// /// delete a document /////////////////////////////////////////////////////////////////////////////// $('#documentsView tr td button').live('click', function () { var aPos = documentsTable.fnGetPosition(this.parentElement); var aData = documentsTable.fnGetData(aPos[0]); var row = $(this).closest("tr").get(0); var documentID = aData[1]; if (this.id == "deleteDoc") { try { $.ajax({ type: 'DELETE', contentType: "application/json", url: "/document/" + documentID }); } catch(e) { alert(e); } documentsTable.fnDeleteRow(documentsTable.fnGetPosition(row)); } if (this.id == "editDoc") { window.location.href = "#editDocument?" + documentID; } }); /////////////////////////////////////////////////////////////////////////////// /// check top menue buttons /////////////////////////////////////////////////////////////////////////////// $('#menue button').live('click', function () { if (this.id == "Collections") { $('#subCenterView').hide(); $('#collectionsView').show(); window.location.href = "#"; } if (this.id == "Logs") { window.location.href = "#logs"; } if (this.id == "Status") { window.location.href = "#status"; } if (this.id == "Configuration") { window.location.href = "#config"; } if (this.id == "Query") { window.location.href = "#query"; } if (this.id == "AvocSH") { window.location.href = "#avocsh"; } }); /////////////////////////////////////////////////////////////////////////////// /// saves an edited collection /////////////////////////////////////////////////////////////////////////////// $('#saveEditedCollection').live('click', function () { var newColName; var currentid; var data = editCollectionTable.fnGetData(); $.each(data, function(info, key) { if (key[1] == 'name') { newColName = key[2]; } if (key[1] == 'id') { currentid = key[2]; } }); $.ajax({ type: "PUT", url: "/_api/collection/" + currentid + "/rename", data: '{"name":"' + newColName + '"}', contentType: "application/json", processData: false, success: function(data) { alert("Collection renamed"); window.location.href = ""; $('#subCenterView').hide(); $('#centerView').show(); drawCollectionsTable(); }, error: function(data) { alert(JSON.stringify(data)); } }); }); /////////////////////////////////////////////////////////////////////////////// /// cancels the creation of a new collection /////////////////////////////////////////////////////////////////////////////// $('#cancelNewCollection').live('click', function () { window.location.href = "#"; }); /////////////////////////////////////////////////////////////////////////////// /// saves a new collection /////////////////////////////////////////////////////////////////////////////// $('#saveNewCollection').live('click', function () { var namePos = [0, 0, 1][1]; var wfsPos = [1, 1, 1][1]; var namedata = createCollectionTable.fnGetData(namePos); var wfsdata = createCollectionTable.fnGetData(wfsPos); var name = namedata[2]; var wfs = wfsdata[2]; if (wfs == "true") { var wfschecked = true; } else if (wfs == "false") { var wfschecked = false; } $.ajax({ type: "POST", url: "/_api/collection", data: '{"name":"' + name + '", "waitForSync":"' + wfschecked + '"}', contentType: "application/json", processData: false, success: function(data) { alert("Collection created"); window.location.href = ""; $('#subCenterView').hide(); $('#centerView').show(); drawCollectionsTable(); }, error: function(data) { alert(JSON.stringify(data)); } }); }); /////////////////////////////////////////////////////////////////////////////// /// live-click function for buttons: "createCollection" & "refreshCollections" /////////////////////////////////////////////////////////////////////////////// $('#centerView button').live('click', function () { if (this.id == "createCollection") { window.location.href = "#createCollection"; return false; } if (this.id == "refreshCollections") { drawCollectionsTable(); } }); /////////////////////////////////////////////////////////////////////////////// /// live-click function for buttons in "collectionsTableID td" /////////////////////////////////////////////////////////////////////////////// $('#collectionsTableID td button').live('click', function () { var collectionsTable = $('#collectionsTableID').dataTable(); var aPos = collectionsTable.fnGetPosition(this.parentElement); var aData = collectionsTable.fnGetData(aPos[0]); var collectionID = aData[1]; var collectionName = aData[2]; /////////////////////////////////////////////////////////////////////////////// ///delete a collection /////////////////////////////////////////////////////////////////////////////// if (this.id == "delete") { $( "#dialog-deleteCollection" ).dialog({ resizable: false, height:180, modal: true, buttons: { "Delete collection": function() { $( this ).dialog( "close" ); $.ajax({ type: 'DELETE', url: "/_api/collection/" + collectionID, success: function () { drawCollectionsTable(); }, error: function () { alert('Error'); } }); }, Cancel: function() { $( this ).dialog( "close" ); } } }); } /////////////////////////////////////////////////////////////////////////////// /// jump to edit collection view /////////////////////////////////////////////////////////////////////////////// if (this.id == "edit") { window.location.href = "#editCollection?" + collectionID; } /////////////////////////////////////////////////////////////////////////////// /// jump to doc view of a collection /////////////////////////////////////////////////////////////////////////////// if (this.id == "showdocs" ) { window.location.href = "#showCollection?" + collectionID; } /////////////////////////////////////////////////////////////////////////////// /// load a collection into memory /////////////////////////////////////////////////////////////////////////////// if (this.id == "load") { $.ajax({ type: 'PUT', url: "/_api/collection/" + collectionID + "/load", success: function () { alert('Collection: ' + collectionID + ' loaded'); drawCollectionsTable(); }, error: function () { alert('Error'); } }); } /////////////////////////////////////////////////////////////////////////////// /// unload a collection from memory /////////////////////////////////////////////////////////////////////////////// if (this.id == "unload") { $.ajax({ type: 'PUT', url: "/_api/collection/" + collectionID + "/unload", success: function () { alert('Collection: ' + collectionID + ' unloaded'); drawCollectionsTable(); }, error: function () { alert('Error'); } }); } }); }); /////////////////////////////////////////////////////////////////////////////// /// hide all divs inside of #centerView /////////////////////////////////////////////////////////////////////////////// function hideAllSubDivs () { $('#subCenterView').show(); $('#collectionsEditView').hide(); $('#newCollectionView').hide(); $('#documentsView').hide(); $('#documentEditView').hide(); $('#newDocumentView').hide(); $('#createCollectionView').hide(); $('#editCollectionView').hide(); $('#logView').hide(); $('#statusView').hide(); $('#configView').hide(); $('#avocshView').hide(); $('#queryView').hide(); } /////////////////////////////////////////////////////////////////////////////// /// draw and fill collections table /////////////////////////////////////////////////////////////////////////////// function drawCollectionsTable () { var collectionsTable = $('#collectionsTableID').dataTable(); collectionsTable.fnClearTable(); $.getJSON("/_api/collection/", function(data) { var items=[]; $.each(data.collections, function(key, val) { var tempStatus = val.status; if (tempStatus == 1) { tempStatus = "new born collection"; } else if (tempStatus == 2) { tempStatus = "unloaded"; items.push(['', val.id, val.name, tempStatus, "", ""]); } else if (tempStatus == 3) { tempStatus = "loaded"; items.push(['', val.id, val.name, tempStatus, "", ""]); } else if (tempStatus == 4) { tempStatus = "in the process of being unloaded"; items.push(["", val.id, val.name, tempStatus, "", ""]); } else if (tempStatus == 5) { tempStatus = "deleted"; items.push(["", val.id, val.name, tempStatus, "", ""]); } /* else { tempStatus = "corrupted"; items.push(["", ""+ val.id + "", ""+ val.name + "", "" + tempStatus + "", "", ""]); }*/ }); $('#collectionsTableID').dataTable().fnAddData(items); showCursor(); }); } /////////////////////////////////////////////////////////////////////////////// /// short function to enable edit mode for a table /////////////////////////////////////////////////////////////////////////////// function documentTableMakeEditable (tableID) { var documentEditTable = $(tableID).dataTable(); var i = 0; $('.writeable', documentEditTable.fnGetNodes() ).each(function () { if ( i == 1) { $(this).removeClass('writeable'); i = 0; } if (this.innerHTML == "_id" || this.innerHTML == "_rev") { $(this).removeClass('writeable'); i = 1; } }); //jeditable init $('.writeable', documentEditTable.fnGetNodes()).editable(function(value, settings) { var aPos = documentEditTable.fnGetPosition(this); if (aPos[1] == 1) { documentEditTable.fnUpdate(value, aPos[0], aPos[1]); return value; } if (aPos[1] == 2) { var oldContent = JSON.parse(documentEditTable.fnGetData(aPos[0], aPos[1] + 1)); var test = getTypedValue(value); if (String(value) == String(oldContent)) { // no change return value2html(oldContent); } else { // change documentEditTable.fnUpdate(JSON.stringify(test), aPos[0], aPos[1] + 1); return value2html(test); } } },{ data: function() { var aPos = documentEditTable.fnGetPosition(this); var value = documentEditTable.fnGetData(aPos[0], aPos[1]); if (aPos[1] == 1) { return value; } if (aPos[1] == 2) { //marker var oldContent = documentEditTable.fnGetData(aPos[0], aPos[1] + 1); if (typeof(oldContent) == 'object') { return JSON.stringify(oldContent); } else { return oldContent; } } }, //type: 'textarea', tooltip: 'click to edit', cssclass : 'jediTextarea', submit: 'Okay', cancel: 'Cancel', onblur: 'cancel', style: 'display: inline' }); } /////////////////////////////////////////////////////////////////////////////// /// escape a string /////////////////////////////////////////////////////////////////////////////// function escaped (value) { return value.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "&"); } /////////////////////////////////////////////////////////////////////////////// /// get value of user edited tabel cell /////////////////////////////////////////////////////////////////////////////// function getTypedValue (value) { if (value == 'true') { return true; } if (value == 'false') { return false; } if (value == 'null') { return null; } if (value.match(/^-?((\d+)?\.)?\d+$/)) { // TODO: support exp notation return parseFloat(value); } try { // assume list or object var test = JSON.parse(value); if (test instanceof Array) { // value is an array return test; } if (typeof(test) == 'object') { // value is an object return test; } } catch (err) { } // fallback: value is a string value = value + ''; if (value.substr(0, 1) == '"' && value.substr(-1) == '"' ) { value = value.substr(1, value.length-2); } return value; } /////////////////////////////////////////////////////////////////////////////// /// checks type fo typed cell value /////////////////////////////////////////////////////////////////////////////// function value2html (value) { var checked = typeof(value); switch(checked) { case 'number': return ("number: " + value); case 'string': return ("string: " + escaped(value)); case 'boolean': return ("boolean: " + value); case 'object': if (value instanceof Array) { return ("array: " + JSON.stringify(value)); } else { return ("object: "+ JSON.stringify(value)); } } } /////////////////////////////////////////////////////////////////////////////// /// draw breadcrumb navigation /////////////////////////////////////////////////////////////////////////////// function createnav (menue) { $('#nav1').text(menue); $('#nav2').text(''); $('#nav3').text(''); $('#nav4').text(''); if (menue == "Collections") { $('#nav1').attr('href', '#'); } else { $('#nav1').attr('href',null); } } /////////////////////////////////////////////////////////////////////////////// /// animated footer div /////////////////////////////////////////////////////////////////////////////// $(function() { var open = false; $('#footerSlideButton').click(function() { if(open === false) { $('#footerSlideContent').animate({ height: '120px' }); $(this).css('backgroundPosition', 'bottom left'); open = true; $('#movetologinButton').text("Hide"); } else { $('#footerSlideContent').animate({ height: '25px' }); $(this).css('backgroundPosition', 'top left'); open = false; $('#movetologinButton').text("Login"); } }); $('#movetologinButton').click(function() { if(open === false) { $('#movetologinButton').text("Hide"); $('#footerSlideContent').animate({ height: '120px' }); $('#footerSlideButton').css('backgroundPosition', 'bottom left'); open = true; } else { $('#movetologinButton').text("Login"); $('#footerSlideContent').animate({ height: '25px' }); $('#footerSlideButton').css('backgroundPosition', 'top left'); open = false; } }); }); /////////////////////////////////////////////////////////////////////////////// /// Log tables pagination /////////////////////////////////////////////////////////////////////////////// function createLogTable(loglevel) { currentPage = 1; currentLoglevel = loglevel; //set tableid if (loglevel == 1) {currentTableID = "#critLogTableID";} else if (loglevel == 2) {currentTableID = "#warnLogTableID";} else if (loglevel == 3) {currentTableID = "#infoLogTableID";} else if (loglevel == 4) {currentTableID = "#debugLogTableID";} else if (loglevel == 5) {currentTableID = "#logTableID";} //get first rows $.getJSON("/_admin/log?level="+loglevel+"&size=10", function(data) { var items=[]; var i=0; currentAmount = data.totalAmount; //clear table $(currentTableID).dataTable().fnClearTable(); //draw first 10 rows $.each(data.lid, function () { $(currentTableID).dataTable().fnAddData([data.level[i], data.text[i]]); i++; }); }); } function createPrevPagination() { if (currentPage == 1) { return 0; } var prevPage = JSON.parse(currentPage) - 1; var offset = prevPage * 10 - 10; $.getJSON("/_admin/log?level="+currentLoglevel+"&size=10&offset="+offset, function(data) { $(currentTableID).dataTable().fnClearTable(); var i = 0; $.each(data.level, function() { $(currentTableID).dataTable().fnAddData([data.level[i], data.text[i]]); i++; }); currentPage = JSON.parse(currentPage) - 1; }); } function createNextPagination() { var totalPages = Math.ceil(currentAmount / 10); var offset = currentPage * 10; if (currentPage == totalPages) { return 0; } $.getJSON("/_admin/log?level="+currentLoglevel+"&size=10&offset="+offset, function(data) { $(currentTableID).dataTable().fnClearTable(); var i = 0; $.each(data.level, function() { $(currentTableID).dataTable().fnAddData([data.level[i], data.text[i]]); i++ }); currentPage = JSON.parse(currentPage) + 1; }); } function showCursor() { $(':button').mouseover(function () { $(this).css('cursor', 'pointer'); }); }