make 'mac' field on an interface editable.
[plewww.git] / planetlab / nodes / interface.php
index a922a73..5a8af9b 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+// $Id$ 
+
 // Require login
 require_once 'plc_login.php';
 
@@ -31,10 +33,12 @@ if ( isset ($_GET['id'])) {
   $interfaces=$api->GetInterfaces(array('interface_id'=>$interface_id));
   $interface=$interfaces[0];
   $node_id=$interface['node_id'];
+  $title=('Updating interface ' . $interface['ip']);
  } else if (isset ($_GET['node_id'])) {
   $mode='add';
   $interface=array();
   $node_id=$_GET['node_id'];
+  $title=('Adding interface');
  } 
 // check
 if ( ! $node_id) {
@@ -44,7 +48,8 @@ if ( ! $node_id) {
  }
 
 $tabs=array();
-$tabs[] = array('label'=>'Back to node', 'url'=>l_node($node_id),
+$tabs[] = array('label'=>'Back to node', 'url'=>l_node($node_id), 
+               'values' => array('show_details'=>False,'show_interfaces'=>True),
                'bubble'=>'Cancel pending changes');
 plekit_linetabs($tabs);
 
@@ -58,13 +63,19 @@ $site_id=$node['site_id'];
 
 $can_update= plc_is_admin() || ( plc_in_site ($site_id) && ( plc_is_pi() || plc_is_tech()));
 
-drupal_set_title("Interface on " . $node['hostname']);
+drupal_set_title($title . " on " . $node['hostname']);
 
 // include javacsript helpers
-drupal_set_title ('
+require_once 'prototype.php';
+drupal_set_html_head ('
 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
 ');
 
+$toggle = new PlekitToggle ('interface',"Details",
+                           array('bubble'=>'Display and modify details for that interface',
+                                 'visible'=>get_arg('show_details',true)));
+$toggle->start();
+
 $details=new PlekitDetails($can_update);
 
 // xxx hardwire network type for now
@@ -74,20 +85,8 @@ $form=$details->form_start(l_actions(),$form_variables);
 
 $details->start();
 
-//>>> GetNetworkMethods()
-//[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown']
-function method_selectors ($api, $method) {
-  $builtin_methods=array("static"=>"Static", "dhcp"=>"DHCP", "proxy"=>"Proxy",  
-                        "tap"=>"TUN/TAP", "ipmi"=>"IPMI");
-  $selectors=array();
-  foreach ($builtin_methods as $value=>$display) {
-    $selector=array('display'=>$display, 'value'=>$value);
-    if ($value == $method) $selector['selected']=true;
-    $selectors []= $selector;
-  }
-  return $selectors;
-}
-$method_select = $form->select_html ("method",method_selectors($api,$interface['method']),
+$method_select = $form->select_html ("method",
+                                    interface_method_selectors($api,$interface['method'],false),
                                     array('id'=>'method','onChange'=>'updateMethodFields()'));
 $details->th_td("Method",$method_select,"method",array('input_type'=>'select','value'=>$interface['method']));
 
@@ -112,9 +111,11 @@ $details->th_td("DNS 2",$interface['dns2'],"dns2",array('width'=>15,
 $details->space();
 $details->th_td("BW limit (bps)",$interface['bwlimit'],"bwlimit",array('width'=>11));
 $details->th_td("Hostname",$interface['hostname'],"hostname");
-# should the user be allowed to change this ?
-$mac=$interface['mac'];
-if ($mac) $details->th_td("MAC address",$mac);
+$details->th_td("Mac address",$interface['mac'],"mac", array('onChange'=>'macChecker("mac", true)'));
+
+# xxx should the user be allowed to change this ?
+//$mac=$interface['mac'];
+//if ($mac) $details->th_td("MAC address",$mac);
 
 // the buttons
 $update_button = $form->submit_html ("update-interface","Update",
@@ -132,13 +133,15 @@ switch ($mode) {
 
 $details->end();
 $form->end();
+$toggle->end();
 
 // no tags if the interface has not been created yet
 if ($mode == 'add') return;
 
 
 //////////////////////////////////////// tags
-$toggle=new PlekitToggle ('tags','Tags',array('trigger-tagname'=>'h2'));
+$toggle=new PlekitToggle ('tags','Tags',
+                         array('visible'=>get_arg('show_tags',false)));
 $toggle->start();
 
 $form = new PlekitForm (l_actions(),array('interface_id'=>$interface_id));
@@ -173,7 +176,7 @@ if ($can_update) {
   $table->row_start();
   $table->cell($form->submit_html("delete-interface-tags","Remove Tags"),
               // use the whole columns and right adjust
-              $table->columns(), "right");
+              array('hfill'=>true,'align'=>'right'));
   $table->row_end();
 
   // set tag area
@@ -185,6 +188,7 @@ if ($can_update) {
   $selector=array_map("tag_selector",$all_tags);
   $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
   $table->cell($form->text_html("value","",array('width'=>8)));
+  //cell-xxx
   $table->cell($form->submit_html("set-tag-on-interface","Set Tag"),2,"left");
   $table->row_end();
  }