[CalendarServer-changes] [12847] CalendarServer/trunk/calendarserver/webadmin/work.xhtml

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 7 13:34:28 PST 2014


Revision: 12847
          http://trac.calendarserver.org//changeset/12847
Author:   wsanchez at apple.com
Date:     2014-03-07 13:34:28 -0800 (Fri, 07 Mar 2014)
Log Message:
-----------
refactor a bit

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/webadmin/work.xhtml

Modified: CalendarServer/trunk/calendarserver/webadmin/work.xhtml
===================================================================
--- CalendarServer/trunk/calendarserver/webadmin/work.xhtml	2014-03-07 21:00:13 UTC (rev 12846)
+++ CalendarServer/trunk/calendarserver/webadmin/work.xhtml	2014-03-07 21:34:28 UTC (rev 12847)
@@ -57,6 +57,8 @@
     <script>
     //<![CDATA[
 
+      var debug = false;
+
       var workTypeDescriptions = {
         // Scheduling
         "SCHEDULE_ORGANIZER_WORK": "Schedule Organizer",
@@ -90,7 +92,7 @@
         "FIND_MIN_VALID_REVISION_WORK": "Revision Cleanup: Find Minimum",
       };
 
-      var jobItemAttributeDescriptions = {
+      var jobAttributeDescriptions = {
         "jobID": "Job ID",
         "priority": "Job Priority",
         "notBefore": "Not Before",
@@ -107,6 +109,7 @@
         "work_attendee": "Attendee",
       }
 
+
       // Function to return keys from an object in order, followed by keys
       // from another which were not in the first.
       // We use this in case we get a JSON dictionary with keys that haven't
@@ -127,14 +130,9 @@
         }
       }
 
-      var debug = false;
 
       var maxSeen = 30;
 
-      var eventSource;
-      var itemTypeEventListener;
-      var itemTypeEventListenerWorkType;
-
       function drawChart(data) {
         var items = [];
 
@@ -261,7 +259,7 @@
             "transform",
             function(i) { return "translate(" + xInset + "," + yLocation(i.description) + ")"; }
           )
-          .attr("onclick", function(i) { return 'showDetails("' + i.name + '");'; })
+          .attr("onclick", function(i) { return 'showJobDetails("' + i.name + '");'; })
         ;
 
         // Exit bars selection
@@ -297,7 +295,8 @@
         inner.exit().remove();
       }
 
-    function initChart() {
+
+      function initChart() {
         var data = {};
 
         for (var key in workTypeDescriptions) {
@@ -307,6 +306,9 @@
         drawChart(data);
       }
 
+
+      var eventSource;
+
       function registerForEvents() {
         eventSource = new EventSource("./events");
 
@@ -322,7 +324,11 @@
         );
       }
 
-      function showDetails(workType) {
+
+      var itemTypeEventListener;
+      var itemTypeEventListenerWorkType;
+
+      function showJobDetails(workType) {
         var debuggingContainer = document.getElementById("debug");
 
         if (debug) {
@@ -370,59 +376,67 @@
             eventDebug.innerHTML = e.data;
           }
 
-          // Reset the rows; we're going to refill the table below
-          detailsBody.innerHTML = "";
-
           var jobItems = JSON.parse(e.data);
 
-          function addCellToRow(row, tag, text) {
-            var cell = document.createElement(tag);
-            var content = document.createTextNode(text);
-            cell.appendChild(content);
-            row.appendChild(cell);
-          }
+          drawJobDetails(jobItems, detailsTable, detailsCaption, detailsHeader, detailsBody);
+        }
 
-          for (var i in jobItems) {
-            var jobItem = jobItems[i];  // OMG JavaScript is so stupid.
+        eventSource.addEventListener(workType, itemTypeEventListener)
+      }
 
-            // Unhide the table
-            detailsTable.style.display = "block";
-    
-            var attributes = keysInKindOfKnownOrder(jobItemAttributeDescriptions, jobItem);
 
-            // Add the table headers if they aren't already there
-            if (detailsHeader.innerHTML == "") {
-              var row = document.createElement("tr");
+      function drawJobDetails(jobItems, detailsTable, detailsCaption, detailsHeader, detailsBody) {
+        // Reset the rows; we're going to refill the table below
+        detailsBody.innerHTML = "";
 
-              for (var i in attributes) {
-                var attribute = attributes[i];  // OMG JavaScript, wow you so dumb
-                attributeDescription = valueOrKey(jobItemAttributeDescriptions, attribute)
+        for (var i in jobItems) {
+          var jobItem = jobItems[i];  // OMG JavaScript is so stupid.
 
-                addCellToRow(row, "th", attributeDescription)
-              }
+          // Unhide the table
+          detailsTable.style.display = "block";
+  
+          var attributes = keysInKindOfKnownOrder(jobAttributeDescriptions, jobItem);
 
-              detailsHeader.appendChild(row);
-            }
-
-            // Add a table row for this job item
+          // Add the table headers if they aren't already there
+          if (detailsHeader.innerHTML == "") {
             var row = document.createElement("tr");
 
             for (var i in attributes) {
-              var attribute = attributes[i];  // OMG JavaScript the lameness
+              var attribute = attributes[i];  // OMG JavaScript, wow you so dumb
+              attributeDescription = valueOrKey(jobAttributeDescriptions, attribute)
 
-              var value = jobItem[attribute]
-              if (value === null) { value = ""; }
-
-              addCellToRow(row, "td", value)
+              addCellToRow(row, "th", attributeDescription)
             }
 
-            detailsBody.appendChild(row);
+            detailsHeader.appendChild(row);
           }
+
+          // Add a table row for this job item
+          var row = document.createElement("tr");
+
+          for (var i in attributes) {
+            var attribute = attributes[i];  // OMG JavaScript the lameness
+
+            var value = jobItem[attribute]
+            if (value === null) { value = ""; }
+
+            addCellToRow(row, "td", value)
+          }
+
+          detailsBody.appendChild(row);
         }
+      }
 
-        eventSource.addEventListener(workType, itemTypeEventListener)
+
+      function addCellToRow(row, tag, text) {
+        var cell = document.createElement(tag);
+        var content = document.createTextNode(text);
+
+        cell.appendChild(content);
+        row.appendChild(cell);
       }
 
+
       window.onload = function() {
         initChart();
         registerForEvents();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140307/d5ef23fe/attachment-0001.html>


More information about the calendarserver-changes mailing list