r3765 pix: add new image from Tango
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 7 Jun 2010 22:26:08 +0000 (22:26 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 7 Jun 2010 22:26:08 +0000 (22:26 +0000)
save8021QPorts(): add "duplicate" mode handling
renderObject8021QPorts(): add "form duplicator" form
renderTrunkPortControls(): fix call to printOpFormIntro()

inc/interface.php
inc/ophandlers.php
pix/tango-edit-copy-32x32.png [new file with mode: 0644]

index 795b35c45322f27f46d5d8c64c414f0b977c7b48..2ba5a646ed276b7c0753cb667a8b94261fd65aed 100644 (file)
@@ -299,6 +299,9 @@ $image['DQUEUE failed']['height'] = 32;
 $image['DQUEUE disabled']['path'] = 'pix/tango-emblem-readonly-32x32.png';
 $image['DQUEUE disabled']['width'] = 32;
 $image['DQUEUE disabled']['height'] = 32;
+$image['COPY']['path'] = 'pix/tango-edit-copy-32x32.png';
+$image['COPY']['width'] = 32;
+$image['COPY']['height'] = 32;
 
 // This may be populated later onsite, report rendering function will use it.
 // See the $systemreport for structure.
@@ -6844,7 +6847,7 @@ function renderObject8021QPorts ($object_id)
        echo '<tr><th>port</th><th>interface</th><th>link</th><th width="25%">last&nbsp;saved&nbsp;config</th>';
        echo $req_port_name == '' ? '<th width="25%">new&nbsp;config</th></tr>' : '<th>(zooming)</th></tr>';
        if ($req_port_name == '');
-               printOpFormIntro ('save8021QConfig', array ('mutex_rev' => $vswitch['mutex_rev']));
+               printOpFormIntro ('save8021QConfig', array ('mutex_rev' => $vswitch['mutex_rev'], 'form_mode' => 'save'));
        $object = spotEntity ('object', $object_id);
        amplifyCell ($object);
        $sockets = array();
@@ -6996,10 +6999,29 @@ function renderObject8021QPorts ($object_id)
                        getImageHREF ('SAVE', 'save configuration', TRUE) .
                        '</td></tr></form>';
        echo '</table>';
+       if ($req_port_name == '');
+               echo '</form>';
        echo '</td>';
        // configuration of currently selected port, if any
        if (!array_key_exists ($req_port_name, $desired_config))
-               echo '<td colspan=2>&nbsp;</td>';
+       {
+               echo '<td>';
+               startPortlet ('port duplicator');
+               echo '<table border=0 align=center>';
+               printOpFormIntro ('save8021QConfig', array ('mutex_rev' => $vswitch['mutex_rev'], 'form_mode' => 'duplicate'));
+               $port_options = array();
+               foreach ($desired_config as $pn => $portinfo)
+                       if ($portinfo['vst_role'] == 'trunk' or $portinfo['vst_role'] == 'access')
+                               $port_options[$pn] = same8021QConfigs ($desired_config[$pn], $cached_config[$pn]) ?
+                                       $pn : "${pn} (*)";
+               echo '<tr><td>' . getSelect ($port_options, array ('name' => 'from_port')) . '</td></tr>';
+               echo '<tr><td>&darr; &darr; &darr;</td></tr>';
+               echo '<tr><td>' . getSelect ($port_options, array ('name' => 'to_ports[]', 'size' => getConfigVar ('MAXSELSIZE'), 'multiple' => 1)) . '</td></tr>';
+               echo '<tr><td>' . getImageHREF ('COPY', 'duplicate', TRUE) . '</td></tr>';
+               echo '</form></table>';
+               finishPortlet();
+               echo '</td>';
+       }
        else
                renderTrunkPortControls
                (
@@ -7024,8 +7046,9 @@ function renderTrunkPortControls ($vswitch, $vdom, $port_name, $vlanport)
                'nports' => 1,
                'pn_0' => $port_name,
                'pm_0' => 'trunk',
+               'form_mode' => 'save',
        );
-       printOpFormIntro ('save', $formextra);
+       printOpFormIntro ('save8021QConfig', $formextra);
        echo '<td width="35%">';
        echo '<table border=0 cellspacing=0 cellpadding=3 align=center>';
        echo '<tr><th colspan=2>allowed</th></tr>';
index fd6a9e5d505b72967880be0a9b1be786c819553f..3df96d8ccbce3bada7731532fc96a8dbedb600d9 100644 (file)
@@ -2263,15 +2263,11 @@ $msgcode['save8021QPorts']['ERR2'] = 109;
 function save8021QPorts ()
 {
        global $sic, $dbxlink;
-       assertUIntArg ('nports');
        assertUIntArg ('mutex_rev', TRUE); // counts from 0
-       if ($sic['nports'] == 1)
-       {
-               assertStringArg ('pn_0');
-               $extra = array ('port_name' => $sic['pn_0']);
-       }
-       else
-               $extra = array();
+       assertStringArg ('form_mode');
+       if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate')
+               throw new InvalidRequestArgException ('form_mode', $sic['form_mode']);
+       $extra = array();
        $dbxlink->beginTransaction();
        try
        {
@@ -2279,38 +2275,60 @@ function save8021QPorts ()
                        throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object');
                if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
                        throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form data');
+               $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired'));
                $changes = array();
-               for ($i = 0; $i < $sic['nports']; $i++)
+               switch ($sic['form_mode'])
                {
-                       assertStringArg ('pn_' . $i);
-                       assertStringArg ('pm_' . $i);
-                       // An access port only generates form input for its native VLAN,
-                       // which we derive allowed VLAN list from.
-                       $native = isset ($sic['pnv_' . $i]) ? $sic['pnv_' . $i] : 0;
-                       switch ($sic["pm_${i}"])
+               case 'save':
+                       assertUIntArg ('nports');
+                       if ($sic['nports'] == 1)
                        {
-                       case 'trunk':
+                               assertStringArg ('pn_0');
+                               $extra = array ('port_name' => $sic['pn_0']);
+                       }
+                       for ($i = 0; $i < $sic['nports']; $i++)
+                       {
+                               assertStringArg ('pn_' . $i);
+                               assertStringArg ('pm_' . $i);
+                               // An access port only generates form input for its native VLAN,
+                               // which we derive allowed VLAN list from.
+                               $native = isset ($sic['pnv_' . $i]) ? $sic['pnv_' . $i] : 0;
+                               switch ($sic["pm_${i}"])
+                               {
+                               case 'trunk':
 #                              assertArrayArg ('pav_' . $i);
-                               $allowed = isset ($sic['pav_' . $i]) ? $sic['pav_' . $i] : array();
-                               break;
-                       case 'access':
-                               if ($native == 'same')
-                                       continue 2;
-                               assertUIntArg ('pnv_' . $i);
-                               $allowed = array ($native);
-                               break;
-                       default:
-                               throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode');
+                                       $allowed = isset ($sic['pav_' . $i]) ? $sic['pav_' . $i] : array();
+                                       break;
+                               case 'access':
+                                       if ($native == 'same')
+                                               continue 2;
+                                       assertUIntArg ('pnv_' . $i);
+                                       $allowed = array ($native);
+                                       break;
+                               default:
+                                       throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode');
+                               }
+                               $changes[$sic['pn_' . $i]] = array
+                               (
+                                       'mode' => $sic['pm_' . $i],
+                                       'allowed' => $allowed,
+                                       'native' => $native,
+                               );
                        }
-                       $changes[$sic['pn_' . $i]] = array
-                       (
-                               'mode' => $sic['pm_' . $i],
-                               'allowed' => $allowed,
-                               'native' => $native,
-                       );
+                       break;
+               case 'duplicate':
+                       assertStringArg ('from_port');
+#                      assertArrayArg ('to_ports');
+                       if (!array_key_exists ($sic['from_port'], $before))
+                               throw new InvalidArgException ('from_port', $sic['from_port'], 'this port does not exist');
+                       foreach ($sic['to_ports'] as $tpn)
+                               if (!array_key_exists ($tpn, $before))
+                                       throw new InvalidArgException ('to_ports[]', $tpn, 'this port does not exist');
+                               elseif ($tpn != $sic['from_port'])
+                                       $changes[$tpn] = $before[$sic['from_port']];
+                       break;
                }
                $domain_vlanlist = getDomainVLANs ($vswitch['domain_id']);
-               $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired'));
                $changes = filter8021QChangeRequests
                (
                        $domain_vlanlist,
diff --git a/pix/tango-edit-copy-32x32.png b/pix/tango-edit-copy-32x32.png
new file mode 100644 (file)
index 0000000..3348ee0
Binary files /dev/null and b/pix/tango-edit-copy-32x32.png differ