X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fweb%2Froot%2Fsrc%2Fmain%2Fresources%2Fjs%2Flib.js;h=811d35e12b6a289a594e52b3b6d23e625db5cffa;hp=81188571644552e6159aeca5b4cec813d0eda1bd;hb=6ff76389794bdf58986c97d8ea5c544712eeb43b;hpb=4a5b8b61c06c7091a7de5ed9df7456fa325dd909
diff --git a/opendaylight/web/root/src/main/resources/js/lib.js b/opendaylight/web/root/src/main/resources/js/lib.js
index 8118857164..811d35e12b 100644
--- a/opendaylight/web/root/src/main/resources/js/lib.js
+++ b/opendaylight/web/root/src/main/resources/js/lib.js
@@ -67,6 +67,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'));
@@ -95,9 +157,9 @@ one.lib.dashlet = {
if (body.length == 0 && !(typeof thead === 'undefined')) {
var $tr = $(document.createElement('tr'));
var $td = $(document.createElement('td'));
- $td.attr("colspan", thead.length);
- $td.text("No data available");
- $td.addClass("empty");
+ $td.attr('colspan', thead.length);
+ $td.text('No data available');
+ $td.addClass('empty');
$tr.append($td);
$tbody.append($tr);
return $tbody;
@@ -105,21 +167,25 @@ one.lib.dashlet = {
// else, populate as usual
$(body).each(function(index, value) {
var $tr = $(document.createElement('tr'));
- // data-id
- if (value['id'] != undefined) {
- $tr.attr('data-id', value['id']);
- }
- // add classes
- $(value["type"]).each(function(index, value) {
- $tr.addClass(value);
- });
- // add entries
- $(value["entry"]).each(function(index, value) {
- var $td = $(document.createElement('td'));
- $td.append(value);
- $tr.append($td);
+ $.each(value, function(key, value) {
+ if (key == 'type') {
+ // add classes
+ $(value).each(function(index, value) {
+ $tr.addClass(value);
+ });
+ } else if (key == 'entry') {
+ // add entries
+ $(value).each(function(index, value) {
+ var $td = $(document.createElement('td'));
+ $td.append(value);
+ $tr.append($td);
+ });
+ } else {
+ // data field
+ $tr.attr('data-' + key, value);
+ }
+ $tbody.append($tr);
});
- $tbody.append($tr);
});
return $tbody;
}
@@ -185,7 +251,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 = {};
@@ -195,6 +261,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);
});
@@ -279,4 +363,4 @@ one.lib.alert = function(alert) {
one.lib.registry.alert = setTimeout(function() {
$("#alert").slideUp();
}, 8000);
-}
\ No newline at end of file
+}