Author:   Lars Michelsen <[email protected]>
Date:     Thu Apr  5 15:12:39 2012 +0200
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Thu Apr  5 15:12:39 2012 +0200

Resetting view params works now

---

 share/frontend/nagvis-js/js/nagvis.js    |   17 ++++++++++++-----
 share/server/core/classes/CoreModMap.php |   22 +++++++++++++---------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/share/frontend/nagvis-js/js/nagvis.js 
b/share/frontend/nagvis-js/js/nagvis.js
index 208db35..72e10c8 100644
--- a/share/frontend/nagvis-js/js/nagvis.js
+++ b/share/frontend/nagvis-js/js/nagvis.js
@@ -417,8 +417,9 @@ function getUrlParam(name) {
 /**
  * Function creates a new cleaned up URL
  * - Can add/overwrite parameters
+ * - Can remove parameters by adding "null" values
  */
-function makeuri(addvars) {
+function makeuri(addparams) {
     var tmp = window.location.href.split('?');
     var base = tmp[0];
     tmp = tmp[1].split('#');
@@ -427,15 +428,21 @@ function makeuri(addvars) {
     var params = {};
     var pair = null;
 
-    // Skip unwanted parmas
     for(var i = 0; i < tmp.length; i++) {
         pair = tmp[i].split('=');
+
+        // Skip unwanted params
+        if(addparams[pair[0]] !== undefined && addparams[pair[0]] == null)
+            continue;
+
         params[pair[0]] = pair[1];
     }
 
     // Add new params to the existing params. Overwrite duplicates
-    for (var key in addvars) {
-        params[key] = addvars[key];
+    for (var key in addparams) {
+        if(addparams[key] != null) {
+            params[key] = addparams[key];
+        }
     }
 
     // Build list of key/value pairs
@@ -444,7 +451,7 @@ function makeuri(addvars) {
         aparams.push(key + '=' + params[key]);
     }
 
-    return base + '?' + aparams.join('&')
+    return base + '?' + aparams.join('&');
 }
 
 /**
diff --git a/share/server/core/classes/CoreModMap.php 
b/share/server/core/classes/CoreModMap.php
index 8244fa4..5db5c7f 100644
--- a/share/server/core/classes/CoreModMap.php
+++ b/share/server/core/classes/CoreModMap.php
@@ -186,7 +186,7 @@ class CoreModMap extends CoreModule {
                         'perm_user' => MATCH_BOOLEAN_EMPTY,
                     );
                     $aVals = $this->getCustomOptions($aOpts, Array(), true);
-                    $attrs = 
$this->filterMapAttrs($this->getAllOptions($aOpts));
+                    list($attrs, $attrsFiltered) = 
$this->filterMapAttrs($this->getAllOptions($aOpts));
 
                     // mode is set to view_params if only the "view 
parameters" dialog is handled in this request.
                     // This dialog has less options and is primary saved for 
the user and not for all users in the
@@ -214,7 +214,7 @@ class CoreModMap extends CoreModule {
                     if(isset($aVals['submit']) && $aVals['submit'] != '' && 
!$update) {
                         // The form has been submitted.
                         try {
-                            $success = $this->handleAddModify($mode, $perm, 
$aVals['show'], $attrs);
+                            $success = $this->handleAddModify($mode, $perm, 
$aVals['show'], $attrs, $attrsFiltered);
                         } catch(FieldInputError $e) {
                             $err = $e;
                         }
@@ -330,19 +330,23 @@ class CoreModMap extends CoreModule {
     // Each attribute can have the toggle_* field set. If present
     // use it's value to filter out the attributes
     private function filterMapAttrs($attrs) {
-        $ret = Array();
+        $ret = array();
+        $filtered = array();
         foreach($attrs AS $attr => $val) {
             if(substr($attr, 0, 7) == 'toggle_' || $attr == '_t' || $attr == 
'lang' || $attr == 'update')
                 continue;
-            if(isset($attrs['toggle_'.$attr]) && $attrs['toggle_'.$attr] !== 
'on')
-                continue;
-            $ret[$attr] = $val;
+
+            if(isset($attrs['toggle_'.$attr]) && $attrs['toggle_'.$attr] !== 
'on') {
+                $filtered[$attr] = null;
+            } else {
+                $ret[$attr] = $val;
+            }
         }
-        return $ret;
+        return array($ret, $filtered);
     }
 
     // Validate and process addModify form submissions
-    protected function handleAddModify($mode, $perm, $map, $attrs) {
+    protected function handleAddModify($mode, $perm, $map, $attrs, 
$attrsFiltered) {
         $this->verifyMapExists($map);
         $MAPCFG = new GlobalMapCfg($this->CORE, $map);
 
@@ -366,7 +370,7 @@ class CoreModMap extends CoreModule {
             // 3. Save the changes to the map config (-> Use default code 
below)
             if($mode == 'view_params' && $perm != 1 && $perm != 2) {
                 // This is the 1. case -> redirect the user to a well formated 
url
-                $params = $attrs;
+                $params = array_merge($attrs, $attrsFiltered);
                 unset($params['object_id']);
                 return array(0, $params, '');
             }


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to