r1238 + applied and tested Aaron's attributes form patch with some mods
authorDenis Ovsienko <infrastation@yandex.ru>
Wed, 24 Oct 2007 06:10:07 +0000 (06:10 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Wed, 24 Oct 2007 06:10:07 +0000 (06:10 +0000)
ChangeLog
inc/interface.php
inc/navigation.php
inc/ophandlers.php

index e3da9ec78a78a42cc04d3c181594618ae707f659..2dd4c166c3cf338f11af9ce22a4eaaaf8d3b9d78 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 0.14.7
        bugfix: provide better SQL dumps for new installations
        bugfix: gateways/switchvlans minor updates
+       update: better attributes edit form by Aaron Dummer
        new feature: cisco 2900 series support for gateways/switchvlans
 0.14.6 2007-10-15
        new feature: browser-side validation for a new IPv4 network
index 340cdfe89abb3fe683f6be89d29ead193aee2842..c2f28320d2113f2a9b9eba2e372f3ec501d3a367 100644 (file)
@@ -385,14 +385,17 @@ function renderEditObjectForm ($object_id)
        global $root;
        echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
        echo "<tr><th>&nbsp;</th><th>Attribute</th><th>Value</th><th>&nbsp;</th></tr>\n";
+       echo "<form method=post action='${root}process.php'>\n";
+       echo "<input type=hidden name=page value=${pageno}>\n";
+       echo "<input type=hidden name=tab value=${tabno}>\n";
+       echo "<input type=hidden name=op value=upd>\n";
+       echo "<input type=hidden name=object_id value=${object_id}>\n";
+       echo '<input type=hidden name=num_attrs value=' . count($values) . ">\n";
+
+       $i = 0;
        foreach ($values as $record)
        {
-               echo "<form method=post action='${root}process.php'>";
-               echo "<input type=hidden name=page value=${pageno}>";
-               echo "<input type=hidden name=tab value=${tabno}>";
-               echo "<input type=hidden name=op value=upd>";
-               echo "<input type=hidden name=object_id value=${object_id}>";
-               echo "<input type=hidden name=attr_id value=${record['id']}>";
+               echo "<input type=hidden name=${i}_attr_id value=${record['id']}>";
                echo "<tr><td><a href=${root}process.php?page=${pageno}&tab=${tabno}&op=del&object_id=${object_id}&attr_id=${record['id']}>";
                printImageHREF ('delete', 'Delete value');
                echo "</a></td>";
@@ -402,18 +405,19 @@ function renderEditObjectForm ($object_id)
                        case 'uint':
                        case 'float':
                        case 'string':
-                               echo "<input type=text name=value value='${record['value']}'>";
+                               echo "<input type=text name=${i}_value value='${record['value']}'>";
                                break;
                        case 'dict':
                                $chapter = readChapter ($record['chapter_name']);
                                $chapter[] = array ('dict_key' => 0, 'dict_value' => '-- NOT SET --');
-                               printSelect ($chapter, 'value', $record['key']);
+                               printSelect ($chapter, "${i}_value", $record['key']);
                                break;
                }
-               echo "</td>";
-               echo "<td><input type=submit value='OK'></td></tr>\n";
-               echo "</form>";
+               echo "</td></tr>\n";
+               $i++;
        }
+       echo "<tr><td colspan=3><input type=submit value='Update'></td></tr>\n";
+       echo "</form>";
        echo "</table>\n";
        finishPortlet();
        echo '</td>';
index f745baabcca387bfc1d4e9d6d2a0d658df7745af..cbadcd52a9acbcab5e7f3bd71868e99410f00187 100644 (file)
@@ -77,7 +77,7 @@ $ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObjec
 $ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
 $ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
 $ophandler['object']['edit']['del'] = 'resetAttrValue';
-$ophandler['object']['edit']['upd'] = 'updateAttrValue';
+$ophandler['object']['edit']['upd'] = 'updateAttrValues';
 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
index f3aa7c6098c047d61d1ef72ab4a585639f278c09..81ffcfdb13149cc3758fc47e597eca8a0b65ef92 100644 (file)
@@ -791,19 +791,58 @@ function resetAttrValue ()
                return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Reset failed!");
 }
 
-function updateAttrValue ()
+function updateAttrValues ()
 {
        global $root, $pageno, $tabno;
-       assertUIntArg ('attr_id');
        assertUIntArg ('object_id');
-       // The value could be uint/float, but we don't know ATM. Let SQL
-       // server check this and complain.
-       assertStringArg ('value');
        $object_id = $_REQUEST['object_id'];
-       if (commitUpdateAttrValue ($object_id, $_REQUEST['attr_id'], $_REQUEST['value']) === TRUE)
-               return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Update succeeded.');
-       else
+       $oldvalues = getAttrValues ($object_id);
+
+       assertUIntArg ('num_attrs');
+       $num_attrs = $_REQUEST['num_attrs'];
+       $result = array();
+
+       for ($i = 0; $i < $num_attrs; $i++)
+       {
+               assertUIntArg ("${i}_attr_id");
+               $attr_id = $_REQUEST["${i}_attr_id"];
+
+               // Field is empty, delete attribute and move on.
+               if (empty($_REQUEST["${i}_value"]))
+               {
+                       commitResetAttrValue ($object_id, $attr_id);
+                       continue;
+               }
+
+               // The value could be uint/float, but we don't know ATM. Let SQL
+               // server check this and complain.
+               assertStringArg ("${i}_value");
+               $value = $_REQUEST["${i}_value"];
+               switch ($oldvalues[$attr_id]['type'])
+               {
+                       case 'uint':
+                       case 'float':
+                       case 'string':
+                               $oldvalue = $oldvalues[$attr_id]['value'];
+                               break;
+                       case 'dict':
+                               $oldvalue = $oldvalues[$attr_id]['key'];
+                               break;
+                       default:
+                               showError ('Internal structure error in updateAttrValues()');
+                               die;
+               }
+               if ($value == $oldvalue)
+                       continue;
+
+               // Note if the queries succeed or not, it determines which page they see.
+               $result[] = commitUpdateAttrValue ($object_id, $attr_id, $value);
+       }
+
+       if (in_array(false, $result))
                return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Update failed!");
+
+       return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Update succeeded.');
 }
 
 function useupPort ()