diff --git a/public_html/deployment/js/functions.js b/public_html/deployment/js/functions.js index 72ed661656eac7c4f0c1b3959c06bd52ab36e407..4a64ce8e747ea6102a654aae0ca75e49f7f5a9c9 100644 --- a/public_html/deployment/js/functions.js +++ b/public_html/deployment/js/functions.js @@ -1,50 +1,77 @@ +// ---------------------------------------------------------------------- +// VARS +// ---------------------------------------------------------------------- + +var aWinBoxes = {}; +var WINBOX_background = "#456"; + +// ---------------------------------------------------------------------- +// FUNCTIONS +// ---------------------------------------------------------------------- /** * initialize soft scrolling for links with css class "scroll-link" * @see http://css-tricks.com/snippets/jquery/smooth-scrolling/ * @returns {undefined} */ -function initSoftscroll(){ - $(function() { - // $('a[href*=#]:not([href=#])').click(function() { - $('a.scroll-link').click(function() { - if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { - var target = $(this.hash); - target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); - if (target.length) { - $('html,body').animate({ - scrollTop: target.offset().top - 70 - }, 300); - return false; - } - } - }); +function initSoftscroll() { + $(function () { + // $('a[href*=#]:not([href=#])').click(function() { + $('a.scroll-link').click(function () { + if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { + var target = $(this.hash); + target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); + if (target.length) { + $('html,body').animate({ + scrollTop: target.offset().top - 70 + }, 300); + return false; + } + } + }); }); } -function showModalMessage(sMessage){ - $('#divmodalmessage').html(sMessage); - $('#divmodal').show(); + +/** + * Shows a modal message by setting the inner HTML of div#divmodalmessage + * to the given message, and showing div#divmodal. + * + * @param {string} sMessage - The message to display in the modal + */ +function showModalMessage(sMessage) { + $('#divmodalmessage').html(sMessage); + $('#divmodal').show(); +} + +/** + * Hide modal message box + */ +function hideModalMessage() { + $('#divmodal').hide(); + return false; } -function showIdAsModalMessage(sId, sTitle){ - - var o=$('#'+sId); - var sHtml='<a href="#" onclick="return hideModalMessage()" class="btn btn-danger" style="float:right"> X </a>' - + o.html() - + '<hr><a href="#" onclick="return hideModalMessage()" class="btn btn-primary"><i class="fa fa-check"></i> OK </a>' - ; - $('#divmodalmessage').html(sHtml); - $('#divmodal').show(); - - /* - var oWrapper=document.getElementById(sId); - new WinBox({ + +/** + * show a window displaying the content of a given dom id using Winbox + * + * @param {string} sId dom id of a div to show + * @param {string} sTitle title for the winbox window + * @returns + */ +function showIdAsModalMessage(sId, sTitle) { + + if (aWinBoxes[sId]) { + return true; + } + var oWrapper = document.getElementById(sId); + aWinBoxes[sId] = WinBox({ title: sTitle, - id: 'winbox-'+sId, + id: 'winbox-' + sId, border: 5, - background: "#628", - class: [ "no-min", "no-max", "no-full", "ciwinboxinfos" ], + background: WINBOX_background, + class: ["no-min", "no-max", "no-full", "ciwinboxinfos"], // modal: true, // collides with bootsrap3 .modal.less @@ -59,41 +86,37 @@ function showIdAsModalMessage(sId, sTitle){ right: 20, bottom: 20, left: 20, - // take content from existing div // mount: oWrapper - html: oWrapper.innerHTML - // html: 'hello' + // mount: document.getElementById(sId).cloneNode(true), + html: oWrapper.innerHTML, + + onclose: function () { + delete aWinBoxes[sId]; + } }); - */ return false; -} - -function hideModalMessage(){ - $('#divmodal').hide(); - return false; } -var aWinBoxes={}; /** * shellcmd plugin ... toggle output window * @param {string} isPluginOutputDiv id of the wrapper * @param {object} oLink a tag in the navbar with link for toggling window */ -function toggleShellWindow(isPluginOutputDiv, oLink){ - if(aWinBoxes[isPluginOutputDiv]){ +function toggleShellWindow(isPluginOutputDiv, oLink) { + if (aWinBoxes[isPluginOutputDiv]) { aWinBoxes[isPluginOutputDiv].close(); } else { - var oWrapper=document.getElementById(isPluginOutputDiv); + var oWrapper = document.getElementById(isPluginOutputDiv); aWinBoxes[isPluginOutputDiv] = WinBox({ title: oLink.innerText, - id: 'winbox-'+isPluginOutputDiv, + id: 'winbox-' + isPluginOutputDiv, border: 5, /*background: "#628",*/ - background: "#478", - class: [ "no-min", "no-max", /* "no-full", "no-resize", "no-move"*/ "ciwinbox" ], + background: WINBOX_background, + class: ["no-min", "no-max", /* "no-full", "no-resize", "no-move"*/ "ciwinbox"], // position + size x: "center", @@ -105,20 +128,20 @@ function toggleShellWindow(isPluginOutputDiv, oLink){ top: 70, right: 20, bottom: 20, - left: 20, + left: 20, // take content from existing div mount: oWrapper, - - onclose: function(){ + + onclose: function () { delete aWinBoxes[isPluginOutputDiv]; $(oLink).removeClass('active'); } }); - if(oLink){ + if (oLink) { $(oLink).addClass('active'); } - window.setTimeout("aWinBoxes['"+isPluginOutputDiv+"'].resize("+(oWrapper.clientWidth+25)+", "+(oWrapper.clientHeight+150)+").move('center', 'center')", 10); + window.setTimeout("aWinBoxes['" + isPluginOutputDiv + "'].resize(" + (oWrapper.clientWidth + 25) + ", " + (oWrapper.clientHeight + 150) + ").move('center', 'center')", 10); } } @@ -126,7 +149,7 @@ function toggleShellWindow(isPluginOutputDiv, oLink){ // general init in each page // ---------------------------------------------------------------------- -$(document).ready(function() { +$(document).ready(function () { initSoftscroll(); }); @@ -139,51 +162,51 @@ $(document).ready(function() { * get filtered action log table * @returns {undefined} */ -function updateActionlog(){ - var sUrlBase="/webservice/?class=Actionlog&action=getLogs&type=json&args="; - +function updateActionlog() { + var sUrlBase = "/webservice/?class=Actionlog&action=getLogs&type=json&args="; + // columns in output table - var aTableitems=["id", "time", "loglevel", "ip", "user", "project", "action", "message"]; - - var aArgs={ + var aTableitems = ["id", "time", "loglevel", "ip", "user", "project", "action", "message"]; + + var aArgs = { 'project': $('#selectproject').val(), - 'from': $('#selectfrom').val(), - 'to': $('#selectto').val(), - 'limit': $('#selectlimit').val(), + 'from': $('#selectfrom').val(), + 'to': $('#selectto').val(), + 'limit': $('#selectlimit').val(), } - + // --- get data - var sUrl=sUrlBase+'['+JSON.stringify(aArgs)+']'; - $.post( sUrl, function( aData ) { - var sHtml=''; - + var sUrl = sUrlBase + '[' + JSON.stringify(aArgs) + ']'; + $.post(sUrl, function (aData) { + var sHtml = ''; + // --- generate output - if (aData.length && aData[0]["id"]){ - for (i=0; i<aData.length; i++){ - sHtml+='<tr class="tractionlogs loglevel-'+aData[i]["loglevel"]+' '+aData[i]["project"]+'">'; - for (j=0; j<aTableitems.length; j++){ - sHtml+='<td>'+aData[i][aTableitems[j]]+'</td>'; + if (aData.length && aData[0]["id"]) { + for (i = 0; i < aData.length; i++) { + sHtml += '<tr class="tractionlogs loglevel-' + aData[i]["loglevel"] + ' ' + aData[i]["project"] + '">'; + for (j = 0; j < aTableitems.length; j++) { + sHtml += '<td>' + aData[i][aTableitems[j]] + '</td>'; } - sHtml+='</tr>'; + sHtml += '</tr>'; } } drawTimeline(aData); - - if (!sHtml){ - sHtml=sMsgNolog; // variable is set in actionlog.class.php + + if (!sHtml) { + sHtml = sMsgNolog; // variable is set in actionlog.class.php } else { - sHead=''; - for (j=0; j<aTableitems.length; j++){ - sHead+='<th>'+aTableitems[j]+'</th>'; + sHead = ''; + for (j = 0; j < aTableitems.length; j++) { + sHead += '<th>' + aTableitems[j] + '</th>'; } - sHead='<thead><tr>'+sHead+'</tr></thead>'; - sHtml='<table class="table table-condensed">'+sHead+'<tbody>'+sHtml+'</tbody></table>'; + sHead = '<thead><tr>' + sHead + '</tr></thead>'; + sHtml = '<table class="table table-condensed">' + sHead + '<tbody>' + sHtml + '</tbody></table>'; } $('#tableLogactions').html(sHtml); filterLogTable(); }); - + } /** * render timeline with Visjs @@ -191,32 +214,32 @@ function updateActionlog(){ * @param {array} aData * @returns {undefined} */ -function drawTimeline(aData){ - var sDataset=''; - +function drawTimeline(aData) { + var sDataset = ''; + var container = document.getElementById('divTimeline'); - if(!container){ + if (!container) { return false; } - container.innerHTML=''; // empty the div + container.innerHTML = ''; // empty the div - if (aData.length && aData[0]["id"]){ - for (i=0; i<aData.length; i++){ + if (aData.length && aData[0]["id"]) { + for (i = 0; i < aData.length; i++) { // keys are // var aTableitems=["id", "time", "loglevel", "ip", "user", "project", "action", "message"]; - sLabel=aData[i]["project"]+'<br>'+aData[i]["action"]; - sTitle=aData[i]["time"] + '<br>'+aData[i]["loglevel"]+'<br><br>Projekt: ' + aData[i]["project"] +'<br>User: ' + aData[i]["user"] + ' (' + aData[i]["ip"] +')<br>'+ aData[i]["message"] ; - sDataset+= (sDataset ? ', ': '' ) - + '{"id": '+i+', "content": "'+sLabel+'", "start": "'+aData[i]["time"].replace(/\ /, "T") +'", "title": "'+sTitle+'", "group": "'+aData[i]["project"]+'", "className": "loglevel-'+aData[i]["loglevel"]+'" }'; + sLabel = aData[i]["project"] + '<br>' + aData[i]["action"]; + sTitle = aData[i]["time"] + '<br>' + aData[i]["loglevel"] + '<br><br>Projekt: ' + aData[i]["project"] + '<br>User: ' + aData[i]["user"] + ' (' + aData[i]["ip"] + ')<br>' + aData[i]["message"]; + sDataset += (sDataset ? ', ' : '') + + '{"id": ' + i + ', "content": "' + sLabel + '", "start": "' + aData[i]["time"].replace(/\ /, "T") + '", "title": "' + sTitle + '", "group": "' + aData[i]["project"] + '", "className": "loglevel-' + aData[i]["loglevel"] + '" }'; } - aDataset=JSON.parse('['+sDataset+']'); - + aDataset = JSON.parse('[' + sDataset + ']'); + var items = new vis.DataSet(aDataset); - + // Configuration for the Timeline var options = { - // verticalScroll: false, - clickToUse: true + // verticalScroll: false, + clickToUse: true }; // Create a Timeline @@ -227,13 +250,13 @@ function drawTimeline(aData){ /** * filter table with action logs by filtertext (input field) */ -function filterLogTable(){ - var sSearch=$("#efilterlogs").val(); +function filterLogTable() { + var sSearch = $("#efilterlogs").val(); var Regex = new RegExp(sSearch, "i"); - $(".tractionlogs").each(function() { - sVisible="none"; - if ( Regex.exec(this.innerHTML)) { - sVisible=""; + $(".tractionlogs").each(function () { + sVisible = "none"; + if (Regex.exec(this.innerHTML)) { + sVisible = ""; } $(this).css("display", sVisible); }); @@ -243,12 +266,12 @@ function filterLogTable(){ // ---------------------------------------------------------------------- // tables // ---------------------------------------------------------------------- -var localStoreTablefilter="tblvalue" + location.pathname; +var localStoreTablefilter = "tblvalue" + location.pathname; // http://blog.mastykarz.nl/jquery-regex-filter/ jQuery.extend( - jQuery.expr[':'], { + jQuery.expr[':'], { regex: function (a, i, m) { var r = new RegExp(m[3], 'i'); return r.test(jQuery(a).text()); @@ -312,14 +335,14 @@ jQuery.fn.removeHighlight = function () { * add a filter form to a table * @returns {undefined} */ -function addFilterToTable(){ - var sValue=localStorage.getItem(localStoreTablefilter) ? localStorage.getItem(localStoreTablefilter) : ''; - var sForm='<form class="pure-form">\n\ +function addFilterToTable() { + var sValue = localStorage.getItem(localStoreTablefilter) ? localStorage.getItem(localStoreTablefilter) : ''; + var sForm = '<form class="pure-form">\n\ <fieldset>\n\ <label for="eFilter">\n\ <i class="fa fa-filter"></i> Tabelle filtern\n\ </label>\n\ - <input type="text" id="eFilter" size="40" name="q" placeholder="Suchbegriff..." value="'+sValue+'" onkeypress="filterTable(this);" onkeyup="filterTable(this);" onchange="filterTable(this);">\n\ + <input type="text" id="eFilter" size="40" name="q" placeholder="Suchbegriff..." value="'+ sValue + '" onkeypress="filterTable(this);" onkeyup="filterTable(this);" onchange="filterTable(this);">\n\ <button class="pure-button" onclick="$(\'#eFilter\').val(\'\'); filterTable(); return false;"><i class="fa fa-times"></i> </button>\n\ <span id="filterinfo"></span>\n\ </fieldset>\n\ @@ -357,9 +380,9 @@ function filterTable() { }); sInfo = (iVisible == ($("tr").length - 1)) - ? "ges.: <strong>" + ($("tr").length - 1) + "</strong> Einträge" - : "<strong>" + iVisible + "</strong> von " + ($("tr").length - 1) + " Einträgen" - ; + ? "ges.: <strong>" + ($("tr").length - 1) + "</strong> Einträge" + : "<strong>" + iVisible + "</strong> von " + ($("tr").length - 1) + " Einträgen" + ; $('#filterinfo').html(sInfo); } @@ -368,13 +391,15 @@ function filterTable() { // ---------------------------------------------------------------------- // API secret // ---------------------------------------------------------------------- -function generateSecret(length){ - - var result = ''; - var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - var charactersLength = characters.length; - for ( var i = 0; i < length; i++ ) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; +function generateSecret(length) { + + var result = ''; + var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + var charactersLength = characters.length; + for (var i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; } + +// ----------------------------------------------------------------------