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=bc922106eccc00274f3db94b0ca648b4512d8f4f;hp=90fd49772a71f0027811817cd3a07671db19f0d1;hb=e4f46779d5d88553410f1a7178c385c427784982;hpb=c22c58ddd80d33523482ae75c233bbd6df069959 diff --git a/opendaylight/web/root/src/main/resources/js/lib.js b/opendaylight/web/root/src/main/resources/js/lib.js index 90fd49772a..bc922106ec 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) { @@ -230,6 +241,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 @@ -251,7 +265,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 = {}; @@ -261,6 +275,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); });