From 5c5c34aa5a9a04c80be9d75f5c4e50d3ef4c9413 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 30 Nov 2006 03:18:37 +0000 Subject: Order categories alphabetically. --- www/ajax/rrdui.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/www/ajax/rrdui.js b/www/ajax/rrdui.js index 74bd8f2..f6c907e 100644 --- a/www/ajax/rrdui.js +++ b/www/ajax/rrdui.js @@ -12,7 +12,7 @@ if(ENDPOINT.charAt(0) != '/') /* TODO: Loading indicator */ var categoryCurrent = null; -var categoriesList = new Object(); +var categoriesList = new Array(); var categoryArea = document.getElementById("headers"); var xmlData = null; var gdoc = null; @@ -45,25 +45,22 @@ function loadedGraphData(doc) displayCategories(); - var cat; + var cat, i; // Initially load any bookmarked category if(location.hash) { cat = location.hash.substr(1); - if(categoriesList[cat]) - categoryCurrent = cat; + for(i = 0; i < categoriesList.length; i++) + { + if(cat == categoriesList[i]) + categoryCurrent = cat; + } } // No category loaded, choose inital if(!categoryCurrent) - { - for(cat in categoriesList) - { - categoryCurrent = cat; - break; - } - } + categoryCurrent = categoriesList[0]; displayCurrentPage(); } @@ -596,8 +593,8 @@ function changeCategory(evt) function displayCategories() { - categoriesList = new Object(); - var cat, i, name; + var categories = new Object(); + var cat, i; /* Get the template and clean it up a bit */ var template = document.getElementById("header-template"); @@ -611,11 +608,17 @@ function displayCategories() cat = "Other"; graphs.item(i).setAttribute("category", "Other"); } - categoriesList[cat] = true; + categories[cat] = true; } - for(name in categoriesList) + categoriesList = new Array(); + for(cat in categories) + categoriesList.push(cat); + categoriesList.sort(); + + for(i in categoriesList) { + var name = categoriesList[i]; var el = template.cloneNode(false); el.removeAttribute("id"); el.appendChild(document.createTextNode(name)); -- cgit v1.2.3