Fixed FELIX-3314 Sort UPnP devices in alphabetical order for Chrome Browser
https://issues.apache.org/jira/browse/FELIX-3314
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1309013 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/upnp/src/main/resources/res/upnp.js b/webconsole-plugins/upnp/src/main/resources/res/upnp.js
index 886b081..2c24d49 100644
--- a/webconsole-plugins/upnp/src/main/resources/res/upnp.js
+++ b/webconsole-plugins/upnp/src/main/resources/res/upnp.js
@@ -250,13 +250,25 @@
}, 'json');
}
+function sortNm(a) {
+ if (typeof a != 'undefined' && typeof a.props != undefined) {
+ var nm = a.props['UPnP.device.friendlyName'];
+ if (typeof nm != 'undefined') return nm.toLowerCase();
+ }
+ return '';
+}
+
+function sortFn(a,b) {
+ return sortNm(a) > sortNm(b) ? 1 : -1;
+}
+
function listDevices() {
browser.empty().addClass('ui-helper-hidden');
searching.removeClass('ui-helper-hidden');
-
+
$.post(pluginRoot, { 'action': 'listDevices' }, function(data) {
if (data && data.devices) {
- data.devices.sort(function(a,b){ return a.props['UPnP.device.friendlyName'] > b.props['UPnP.device.friendlyName']});
+ data.devices.sort(sortFn);
$.each(data.devices, function(index) {
var html = addDevice(this);
browser.treeview( { add: html.appendTo(browser) } );