Author:   Lars Michelsen <[email protected]>
Date:     Fri Sep 23 18:43:15 2011 +0200
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Fri Sep 23 18:43:15 2011 +0200

Fixed object adding with new addmodify dialog

---

 share/frontend/nagvis-js/js/edit.js               |   60 +++++++++------------
 share/server/core/classes/WuiViewMapAddModify.php |   13 ++++-
 share/server/core/mapcfg/default.php              |   36 ++++++++----
 3 files changed, 61 insertions(+), 48 deletions(-)

diff --git a/share/frontend/nagvis-js/js/edit.js 
b/share/frontend/nagvis-js/js/edit.js
index fd4b334..bfd06df 100644
--- a/share/frontend/nagvis-js/js/edit.js
+++ b/share/frontend/nagvis-js/js/edit.js
@@ -377,11 +377,11 @@ function addObject(e, objType, viewType, numLeft, action) 
{
     addAction   = action;
 
     if(document.body)
-    document.body.style.cursor = 'crosshair';
+        document.body.style.cursor = 'crosshair';
 
     var event = !e ? window.event : e;
     if(event.stopPropagation)
-    event.stopPropagation();
+        event.stopPropagation();
     event.cancelBubble = true;
     return false;
 }
@@ -390,11 +390,11 @@ function getEventMousePos(e) {
     var event = !e ? window.event : e;
 
     if (event.pageX || event.pageY) {
-    posx = event.pageX;
-    posy = event.pageY;
+        posx = event.pageX;
+        posy = event.pageY;
     } else if (event.clientX || event.clientY) {
-    posx = event.clientX;
-    posy = event.clientY;
+        posx = event.clientX;
+        posy = event.clientY;
     }
 
     // FIXME: Check the clicked area. Only handle clicks on the map!
@@ -404,10 +404,10 @@ function getEventMousePos(e) {
 
     // When a grid is enabled align the dragged object in the nearest grid
     if(oViewProperties.grid_show === 1) {
-    var a = coordsToGrid(posx, posy);
-    posx = a[0];
-    posy = a[1];
-    a = null;
+        var a = coordsToGrid(posx, posy);
+        posx = a[0];
+        posy = a[1];
+        a = null;
     }
 
     return [ posx, posy ];
@@ -415,7 +415,7 @@ function getEventMousePos(e) {
 
 function addClick(e) {
     if(!adding())
-    return;
+        return;
 
     var pos = getEventMousePos(e);
     addX.push(pos[0]);
@@ -425,46 +425,38 @@ function addClick(e) {
 
     // Draw a line to illustrate the progress of drawing the current line
     if(addViewType === 'line' || addObjType === 'textbox') {
-    addShape = new jsGraphics('map');
+        addShape = new jsGraphics('map');
 
-    addShape.setColor('#06B606');
-    addShape.setStroke(1);
+        addShape.setColor('#06B606');
+        addShape.setStroke(1);
 
-    addFollow = true;
+        addFollow = true;
     }
 
     if(addNumLeft > 0)
-    return;
+        return;
 
     //
     // If this is reached all object coords have been collected
     //
 
     if(document.body)
-    document.body.style.cursor = 'default';
+        document.body.style.cursor = 'default';
 
     var sUrl = '';
-    if(addAction == 'add' || addAction == 'clone') {
-    sUrl = oGeneralProperties.path_server + '?mod=Map&act=addModify&do=add'
-           + '&show=' + oPageProperties.map_name
-           + '&type=' + addObjType
-           + '&x=' + addX.join(',')
-           + '&y=' + addY.join(',')
-           + '&viewType=' + addViewType;
+    if(addAction == 'add' || addAction == 'clone')
+        sUrl = oGeneralProperties.path_server + '?mod=Map&act=addModify'
+               + '&show=' + oPageProperties.map_name
+               + '&type=' + addObjType
+               + '&x=' + addX.join(',')
+               + '&y=' + addY.join(',')
+               + '&view_type=' + addViewType;
 
     if(addAction == 'clone' && objid !== -1)
-        sUrl += '&clone='+objid;
-    } else if(addAction == 'modify' && objid !== -1) {
-    sUrl = oGeneralProperties.path_server+'?mod=Map&act=addModify&do=modify'
-           + '&show=' + oPageProperties.map_name
-           + '&type=' + addObjType
-           + '&id=' + objid
-           + '&x=' + addX.join(',')
-           + '&y=' + addY.join(',');
-    }
+        sUrl += '&clone_id='+objid;
 
     if(sUrl === '')
-    return false;
+        return false;
 
     // FIXME: Language string
     showFrontendDialog(sUrl, 'Properties');
diff --git a/share/server/core/classes/WuiViewMapAddModify.php 
b/share/server/core/classes/WuiViewMapAddModify.php
index 22301b0..46fab1d 100644
--- a/share/server/core/classes/WuiViewMapAddModify.php
+++ b/share/server/core/classes/WuiViewMapAddModify.php
@@ -215,7 +215,7 @@ class WuiViewMapAddModify {
                     // Handle case that e.g. host_names can not be fetched 
from backend by
                     // showing error text instead of fields
                     try {
-                        $options = $func($this->CORE, $this->MAPCFG, $objId);
+                        $options = $func($this->CORE, $this->MAPCFG, $objId, 
$this->attrs);
 
                         // When this is an associative array use labels 
instead of real values
                         // Change other arrays to associative ones for easier 
handling afterwards
@@ -255,9 +255,18 @@ class WuiViewMapAddModify {
 
             $ret .= '</td></tr>';
 
-            if(isset($this->errors[$propname]))
+            if(isset($this->errors[$propname])) {
                 foreach($this->errors[$propname] AS $err)
                     $ret .= '<tr><td colspan=3 class=err><div>' . $err . 
'</div></td></tr>';
+                unset($this->errors[$propname]);
+            }
+        }
+
+        // Errors left?
+        if(count($this->errors) > 0) {
+            foreach($this->errors AS $attr => $errors)
+            foreach($errors AS $err)
+                $ret .= '<tr><td colspan=3 class=err><div>'.$attr.': ' . $err 
. '</div></td></tr>';
         }
 
         return $ret;
diff --git a/share/server/core/mapcfg/default.php 
b/share/server/core/mapcfg/default.php
index 205e62c..5a64993 100644
--- a/share/server/core/mapcfg/default.php
+++ b/share/server/core/mapcfg/default.php
@@ -61,18 +61,30 @@ function listViewTypes($CORE) {
     return Array('icon', 'line');
 }
 
-function getObjectNames($type, $CORE, $MAPCFG, $objId) {
-    $backendId = $MAPCFG->getValue($objId, 'backend_id');
+function getObjectNames($type, $CORE, $MAPCFG, $objId, $attrs) {
+    if(isset($attrs['backend_id']) && $attrs['backend_id'] != '')
+        $backendId = $attrs['backend_id'];
+    else
+        $backendId = $MAPCFG->getValue($objId, 'backend_id');
 
     // Initialize the backend
     $BACKEND = new CoreBackendMgmt($CORE);
     $BACKEND->checkBackendExists($backendId, true);
     $BACKEND->checkBackendFeature($backendId, 'getObjects', true);
 
-    $name1 = ($type === 'service' ? $MAPCFG->getValue($objId, 'host_name') : 
'');
+    $name1 = '';
+    if($type === 'service') {
+        if(isset($attrs['host_name']) && $attrs['host_name'] != '')
+            $name1 = $attrs['host_name'];
+        else
+            $name1 = $MAPCFG->getValue($objId, 'host_name');
+
+        if($name1 == '')
+            return Array();
+    }
 
     // Read all objects of the requested type from the backend
-    $aRet = Array('');
+    $aRet = Array();
     $objs = $BACKEND->getBackend($backendId)->getObjects($type, $name1, '');
     foreach($objs AS $obj) {
         if($type !== 'service')
@@ -84,20 +96,20 @@ function getObjectNames($type, $CORE, $MAPCFG, $objId) {
     return $aRet;
 }
 
-function listHostNames($CORE, $MAPCFG, $objId) {
-    return getObjectNames('host', $CORE, $MAPCFG, $objId);
+function listHostNames($CORE, $MAPCFG, $objId, $attrs) {
+    return getObjectNames('host', $CORE, $MAPCFG, $objId, $attrs);
 }
 
-function listHostgroupNames($CORE, $MAPCFG, $objId) {
-    return getObjectNames('hostgroup', $CORE, $MAPCFG, $objId);
+function listHostgroupNames($CORE, $MAPCFG, $objId, $attrs) {
+    return getObjectNames('hostgroup', $CORE, $MAPCFG, $objId, $attrs);
 }
 
-function listServiceNames($CORE, $MAPCFG, $objId) {
-    return getObjectNames('service', $CORE, $MAPCFG, $objId);
+function listServiceNames($CORE, $MAPCFG, $objId, $attrs) {
+    return getObjectNames('service', $CORE, $MAPCFG, $objId, $attrs);
 }
 
-function listServicegroupNames($CORE, $MAPCFG, $objId) {
-    return getObjectNames('servicegroup', $CORE, $MAPCFG, $objId);
+function listServicegroupNames($CORE, $MAPCFG, $objId, $attrs) {
+    return getObjectNames('servicegroup', $CORE, $MAPCFG, $objId, $attrs);
 }
 
 function listTemplateNames($CORE) {


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to