WEB UI -- Simplified listener mechanism in theme.js to match that of prefs.js
 - minor cleanup of app.js

Change-Id: I1a05c5cb43c994937747ef69841d24a863128f4d
diff --git a/web/gui/src/main/webapp/app/view/app/app.js b/web/gui/src/main/webapp/app/view/app/app.js
index 83ab06e..3bb5858 100644
--- a/web/gui/src/main/webapp/app/view/app/app.js
+++ b/web/gui/src/main/webapp/app/view/app/app.js
@@ -212,7 +212,8 @@
          'WebSocketService', 'FnService', 'KeyService', 'PanelService',
          'IconService', 'UrlFnService', 'DialogService', 'TableBuilderService',
 
-    function (_$log_, _$scope_, $http, $timeout, _wss_, _fs_, _ks_, _ps_, _is_, ufs, ds, tbs) {
+    function (_$log_, _$scope_, $http, $timeout, _wss_, _fs_, _ks_, _ps_, _is_,
+              ufs, ds, tbs) {
         $log = _$log_;
         $scope = _$scope_;
         wss = _wss_;
@@ -333,21 +334,23 @@
         $scope.$on('FileChanged', function () {
             var formData = new FormData(),
                 url;
+
             if ($scope.appFile) {
                 formData.append('file', $scope.appFile);
-                url = fileUploadUrl + (activateImmediately || '');
+                url = fileUploadUrl + activateImmediately;
+
                 $http.post(ufs.rsUrl(url), formData, {
                     transformRequest: angular.identity,
                     headers: {
                         'Content-Type': undefined
                     }
                 })
-                    .finally(function () {
-                        activateImmediately = null;
-                        $scope.sortCallback($scope.sortParams);
-                        document.getElementById('inputFileForm').reset();
-                        $timeout(function () { wss.sendEvent(detailsReq); }, 250);
-                    });
+                .finally(function () {
+                    activateImmediately = '';
+                    $scope.sortCallback($scope.sortParams);
+                    document.getElementById('inputFileForm').reset();
+                    $timeout(function () { wss.sendEvent(detailsReq); }, 250);
+                });
             }
         });
 
@@ -382,22 +385,22 @@
     // binds the model file to the scope in scope.appFile
     // sends upload request to the server
     .directive('fileModel', ['$parse',
-            function ($parse) {
-        return {
-            restrict: 'A',
-            link: function (scope, elem, attrs) {
-                var model = $parse(attrs.fileModel),
-                    modelSetter = model.assign;
+        function ($parse) {
+            return {
+                restrict: 'A',
+                link: function (scope, elem, attrs) {
+                    var model = $parse(attrs.fileModel),
+                        modelSetter = model.assign;
 
-                elem.bind('change', function () {
-                    scope.$apply(function () {
-                        modelSetter(scope, elem[0].files[0]);
+                    elem.bind('change', function () {
+                        scope.$apply(function () {
+                            modelSetter(scope, elem[0].files[0]);
+                        });
+                        scope.$emit('FileChanged');
                     });
-                    scope.$emit('FileChanged');
-                });
-            }
-        };
-    }])
+                }
+            };
+        }])
 
     .directive("filedrop", function ($parse, $document) {
         return {
diff --git a/web/gui/src/main/webapp/app/view/topo/topo.js b/web/gui/src/main/webapp/app/view/topo/topo.js
index fafbf3f..b45205b 100644
--- a/web/gui/src/main/webapp/app/view/topo/topo.js
+++ b/web/gui/src/main/webapp/app/view/topo/topo.js
@@ -37,7 +37,7 @@
     var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer;
 
     // Internal state
-    var zoomer, actionMap, themeListener;
+    var zoomer, actionMap;
 
     // --- Short Cut Keys ------------------------------------------------
 
@@ -433,15 +433,17 @@
         return promise;
     }
 
+    function mapReshader() {
+        $log.debug('... Re-shading map ...')
+        ms.reshade(shading());
+    }
+
     // set up theme listener to re-shade the map when required.
     function mapShader(on) {
         if (on) {
-            themeListener = th.addListener(function () {
-                ms.reshade(shading());
-            });
+            th.addListener(mapReshader);
         } else {
-            th.removeListener(themeListener);
-            themeListener = null;
+            th.removeListener(mapReshader);
         }
     }
 
diff --git a/web/gui/src/main/webapp/app/view/topo/topoForce.js b/web/gui/src/main/webapp/app/view/topo/topoForce.js
index 6af88a3..93e8ddc 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoForce.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoForce.js
@@ -1040,6 +1040,11 @@
         };
     }
 
+    function updateLinksAndNodes() {
+        updateLinks();
+        updateNodes();
+    }
+    
     angular.module('ovTopo')
     .factory('TopoForceService',
         ['$log', '$timeout', 'FnService', 'SvgUtilService',
@@ -1067,10 +1072,7 @@
             fltr = _fltr_;
             tls = _tls_;
 
-            var themeListener = ts.addListener(function () {
-                updateLinks();
-                updateNodes();
-            });
+            ts.addListener(updateLinksAndNodes);
 
             // forceG is the SVG group to display the force layout in
             // uplink is the api from the main topo source file
@@ -1138,8 +1140,7 @@
                 td3.destroyD3();
                 tms.destroyModel();
                 // note: no need to destroy overlay service
-                ts.removeListener(themeListener);
-                themeListener = null;
+                ts.removeListener(updateLinksAndNodes);
 
                 // clean up the DOM
                 svg.selectAll('g').remove();
diff --git a/web/gui/src/main/webapp/app/view/topo/topoInst.js b/web/gui/src/main/webapp/app/view/topo/topoInst.js
index 1d0cbed..22e2b47 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoInst.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoInst.js
@@ -43,12 +43,9 @@
     var onosInstances,
         onosOrder,
         oiShowMaster,
-        oiBox,
-        themeListener;
+        oiBox;
 
 
-    // ==========================
-
     function addInstance(data) {
         var id = data.id;
 
@@ -273,12 +270,11 @@
         oiShowMaster = false;
 
         // we want to update the instances, each time the theme changes
-        themeListener = ts.addListener(updateInstances);
+        ts.addListener(updateInstances);
     }
 
     function destroyInst() {
-        ts.removeListener(themeListener);
-        themeListener = null;
+        ts.removeListener(updateInstances);
 
         ps.destroyPanel(idIns);
         oiBox = null;