X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fweb%2Froot%2Fsrc%2Fmain%2Fresources%2Fjs%2Flib.js;h=c265760b97d28ff95210822e7bb0bf02293af925;hb=3a117f105f127bb255dd44f3cdde28e45d4d389a;hp=6b73668ab885d3c351e2bfcf15622710555381d8;hpb=d6a8638df6f25c5f163242654d7608be36f3aa6d;p=controller.git diff --git a/opendaylight/web/root/src/main/resources/js/lib.js b/opendaylight/web/root/src/main/resources/js/lib.js index 6b73668ab8..c265760b97 100644 --- a/opendaylight/web/root/src/main/resources/js/lib.js +++ b/opendaylight/web/root/src/main/resources/js/lib.js @@ -26,6 +26,17 @@ one.lib.dashlet = { $h4.text(header); return $h4; }, + label : function(name, type) { + var $span = $(document.createElement('span')); + $span.addClass('label'); + if (type !== undefined) { + $span.addClass(type); + } else if (type !== null) { + $span.addClass('label-info'); + } + $span.append(name); + return $span; + }, list : function(list) { var $ul = $(document.createElement('ul')); $(list).each(function(index, value) { @@ -67,6 +78,68 @@ one.lib.dashlet = { return $buttonGroup; } }, + datagrid: { + /* + * The init function returns HTML markup for the datagrid per the options provided. Each consumer + * of the datagrid must first call init and then provide the datasource for the grid. + * id: this is the id of the table + * options: { + * searchable: true/false, + * pagination: turned off for now, + * flexibleRowsPerPage: turned off + * } + * classes : String containing bootstrap related classes. For ex: "table-striped table-condensed" + * The classes "table", "table-bordered" and "datagrid" will be added by default + */ + init: function(id, options, classes) { + var $fuelGridContainerDiv = $(document.createElement("div")); + $fuelGridContainerDiv.addClass("fuelux"); + $table = $(document.createElement("table")); + $table.attr("id", id); + $table.addClass("table table-bordered datagrid"); + $table.addClass(classes); + // create datagrid header + $thead = $(document.createElement("thead")); + $headertr = $(document.createElement("tr")); + $headerth = $(document.createElement("th")); + // create datagrid footer + $tfoot = $(document.createElement("tfoot")); + $footertr = $(document.createElement("tr")); + $footerth = $(document.createElement("th")); + if(options.searchable == true) { + $headerth.append(one.lib.dashlet.datagrid._searchable()); + } + if(options.flexibleRowsPerPage == true) { + $footerth.append(one.lib.dashlet.datagrid._rowsPerPage(options.popout)); + } + if(options.pagination == true) { + $footerth.append(one.lib.dashlet.datagrid._pagination()); + } + $headertr.append($headerth); + $thead.append($headertr); + $footertr.append($footerth); + $tfoot.append($footertr); + $table.append($thead).append($tfoot); + $fuelGridContainerDiv.append($table); + return $fuelGridContainerDiv; + }, + _searchable: function() { + var searchHTML = "
"; + return searchHTML; + }, + _pagination: function() { + var html = ''; + return html; + }, + _rowsPerPage: function(popout) { + if(popout) { + var html = ''; + } else { + var html = ''; + } + return html; + } + }, table : { table : function(classes, id) { var $table = $(document.createElement('table')); @@ -153,7 +226,10 @@ one.lib.modal = { return $clone; }, // populate modal - populate : function($modal, header, $body, footer) { + populate : function($modal, header, $body, footer, ajax) { + if (ajax === undefined && ajax !== false) { + $.getJSON('/web.json'); // session check per modal + } var $h3 = $modal.find("h3"); $h3.text(header); @@ -168,6 +244,9 @@ one.lib.modal = { spawn : function(id, header, $body, footer) { var $modal = one.lib.modal.clone(id); one.lib.modal.populate($modal, header, $body, footer); + $modal.on('hide', function () { + $('.modal-body').scrollTop(0); + }); return $modal; }, // empty modal @@ -189,7 +268,7 @@ one.lib.modal = { one.lib.form = { // create select-option form element select : { - create : function(options, multiple) { + create : function(options, multiple, sort) { // assert - auto assign if (options == undefined) options = {}; @@ -199,6 +278,24 @@ one.lib.form = { $select.attr("multiple", "multiple"); } var optionArray = one.lib.form.select.options(options); + + // If specified, sort the option elements based on their text field + if (sort == true && optionArray.length > 1) { + var shifted = true; + var limit = optionArray.length; + while (shifted) { + shifted = false; + for ( var i = 1; i < limit; i++) { + if (optionArray[i - 1].text() > optionArray[i].text()) { + var swap = optionArray[i - 1]; + optionArray[i - 1] = optionArray[i]; + optionArray[i] = swap; + shifted = true; + } + } + } + } + $(optionArray).each(function(index, value) { $select.append(value); }); @@ -274,6 +371,18 @@ one.lib.nav = { } } +one.lib.helper = { + parseInt : function(value) { + return (value != null && value.trim() !== '') ? + parseInt(value) : '' + }, + parseFloat : function(value) { + return (value != null && value.trim() !== '') ? + parseFloat(value) : '' + } +} + + /** ALERT */ one.lib.alert = function(alert) { $("#alert p").text(alert);