ckp
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 12 Feb 2009 12:08:25 +0000 (12:08 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 12 Feb 2009 12:08:25 +0000 (12:08 +0000)
planetlab/events/events_choser.php
planetlab/includes/plc_details.php
planetlab/includes/plc_forms.php
planetlab/nodes/interface.js
planetlab/nodes/interface.php
planetlab/persons/person.php
planetlab/prototype/prototype-1.6.0.3.js
planetlab/tags/tag.php

index cd908a2..08cc193 100644 (file)
@@ -52,15 +52,15 @@ $details->start();
 $details->tr ($form->submit_html('submit','Show Events'),'center');
 $details->space();
 
-$details->th_td ( $form->radio_html ('events','type','Event',true) . "Events",
+$details->th_td ( $form->radio_html ('type','Event',array('id'=>'events','checked'=>true)) . "Events",
                 $form->text_html('event','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'events.checked=true')));
-$details->th_td ( $form->radio_html ('sites','type','Site',false) . "Sites",
+$details->th_td ( $form->radio_html ('type','Site',array('id'=>'sites')) . "Sites",
                 $form->text_html('site','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'sites.checked=true')));
-$details->th_td ( $form->radio_html ('persons','type','Person',false) . "Persons",
+$details->th_td ( $form->radio_html ('type','Person',array('id'=>'persons')) . "Persons",
                 $form->text_html('person','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'persons.checked=true')));
-$details->th_td ( $form->radio_html ('nodes','type','Node',false) . "Nodes",
+$details->th_td ( $form->radio_html ('type','Node',array('id'=>'nodes')) . "Nodes",
                 $form->text_html('node','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'nodes.checked=true')));
-$details->th_td ( $form->radio_html ('slices','type','Slice',false) . "Slices",
+$details->th_td ( $form->radio_html ('type','Slice',array('id'=>'slices')) . "Slices",
                 $form->text_html('slice','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'slices.checked=true')));
 
 $details->space();
index c03f756..684adf5 100644 (file)
@@ -108,10 +108,13 @@ class PlcDetails {
     print $this->th_td_html ($title,$value,$form_varname,$options);
   }
   function th_td_html ($title,$value,$form_varname="",$options=NULL) {
+    if (!$options) $options = array();
     if ( ! ($this->editable && $form_varname) ) {
+      // xxx hack: if input_type is select, look for the 'value' option to display current value
+      if ($options['input_type'] == "select") 
+       $value=$options['value'];
       return "<tr><th>$title</th><td>$value</td></tr>";
     } else {
-      if (!$options) $options = array();
       // use options if provided, otherwise the latest set_ function 
       if (array_key_exists('input_type',$options)) $input_type=$options['input_type'];
       else $input_type=$this->input_type;
@@ -123,7 +126,7 @@ class PlcDetails {
       $html="";
       $html .= "<tr><th><label for=$form_varname>$title</label></th>";
       $html .= "<td>";
-      // hack: if input_type is select : user provides the input field verbatim
+      // xxx hack: if input_type is select : user provides the input field verbatim
       if ( $input_type == "select" ) {
        $html .= $value;
       } else if ($input_type == "textarea") {
@@ -135,11 +138,8 @@ class PlcDetails {
        // set id too 
        $html .= "<input type='$input_type' name='$form_varname' id='$form_varname' value='$value'";
        if ($width) $html .= " size=$width";
-       $cbs=array('onFocus','onSelect', 'onChange', 'onKeyup', 'onMouseup');
-       foreach ($cbs as $cb) {
-         if ($options[$cb])
-           $html .= " $cb='" . $options[$cb] . "'";
-       }
+       // handle event callbacks
+       $html .= PlcForm::attributes($options);
        $html .= "/>";
       }
       $html .= "</td></tr>";
index 49086b6..8a2bfce 100644 (file)
@@ -43,45 +43,43 @@ class PlcForm {
   function end() { print $this->end_html(); }
   function end_html() { return "</form>"; }
 
-  static function hidden_html ($key,$value) {
-    return "<input type=hidden name='$key' value='$value'/>";  
-  }
-  static function checkbox_html ($name,$value,$selected=false) {
-    if ($selected) $xtra=" selected=selected";
-    return "<input type=checkbox name='$name' value='$value'$xtra/>";
-  }
-  static function submit_html ($name,$display) {
-    return "<input type=submit name='$name' value='$display'/>";
-  }
-  static function file_html ($name,$size) {
-    return "<input type=file name='$name' size=$size/>";
-  }
-  static function label_html ($name,$display) {
-    return "<label for=$name>$display </label>";
-  }
-  static function radio_html  ($id, $name, $value, $checked) {
-    $html="<input type='radio' id='$id' name='$name' value='$value'";
-    if ($checked) $html .= " checked='checked'";
-    $html .="/>";
+  static function attributes ($options) {
+    $html="";
+    $names=array('id','size','selected', 'checked',
+                'onfocus','onselect', 'onchange', 
+                'onkeyup', 'onmouseup', 'onclick', 'onsubmit');
+    if ($options['selected']) $options['selected']='selected';
+    if ($options['checked']) $options['checked']='checked';
+    if ($options) foreach ($options as $key=>$value) {
+       if (in_array(strtolower($key),$names)) 
+         $html .= " $key='$value'";
+      }
     return $html;
   }
+
   // options
   // (*) width to set the text size
   // (*) callbacks, e.g. onFocus=>'your javascript code'
-  static function text_html ($name,$value,$options=NULL) {
-    $default_options = array('width'=>20);
+  static function input_html ($type,$name,$value,$options=NULL) {
     if ( ! $options) $options=array();
-    $options = array_merge($default_options,$options);
-    $html="<input type=text name='$name' value='$value'";
-    $html .= " size=" . $options['width'];
-    $cbs=array('onFocus','onSelect', 'onChange');
-    foreach ($cbs as $cb) {
-      if ($options[$cb])
-       $html .= " $cb='" . $options[$cb] . "'";
-    }
+    $html="<input";
+    $html="<input type='$type' name='$name' value='$value'";
+    $html .= PlcForm::attributes ($options);
     $html .= "/>";
     return $html;
   }
+
+  static function text_html ($name,$value, $options=NULL) {    return PlcForm::input_html('text', $name, $value, $options); }
+  static function hidden_html ($name,$value, $options=NULL) {  return PlcForm::input_html('hidden', $name, $value, $options); }
+  static function checkbox_html ($name,$value,$options=NULL) { return PlcForm::input_html('checkbox', $name, $value, $options); }
+  static function submit_html ($name,$value,$options=NULL) {   return PlcForm::input_html('submit', $name, $value, $options); }
+  static function button_html ($name,$value,$options=NULL) {   return PlcForm::input_html('button', $name, $value, $options); }
+  static function radio_html ($name,$value,$options=NULL) {    return PlcForm::input_html('radio', $name, $value, $options); }
+  static function file_html ($name,$value,$options=NULL) {     return PlcForm::input_html('file', $name, $value, $options); }
+
+  static function label_html ($name,$display) {
+    return "<label for=$name>$display</label>";
+  }
   static function textarea_html ($name,$value,$cols,$rows) {
     return "<textarea name='$name' cols=$cols rows=$rows>$value</textarea>";
   }
index 1669779..08bc28d 100644 (file)
@@ -104,7 +104,16 @@ function networkHelper () {
 }
 
 /* check one */
-function subnetChecker (args) {
+function subnetChecker (id, optional) {
+  var error= subnetCheckerSilent([id,optional]);
+  if (error) {
+    Form.Element.focus($(id));
+    alert(error);
+  }
+}
+
+function subnetCheckerSilent (args) {
+  
   id=args[0];
   optional=args[1];
 
@@ -124,13 +133,13 @@ function subnetChecker (args) {
   return "";
 }
 
-function formSubmit () {
+function interfaceSubmit () {
+  alert ('submitting');
   // get error strings, and remove the empty ones
   // dns2 is optional
-  var errors=['gateway','dns1'].zip ([true,true,false],subnetChecker).reject( function (s) {return s.length==0;} );
+  var errors=['gateway','dns1','dns2'].zip ([true,true,false],subnetCheckerSilent).reject( function (s) {return s.length==0;} );
   if ( ! errors.length)
     $('ip').up('form').submit();
   else
     alert(errors.join("\n"));
 }
-  
index 3b9fd90..0554939 100644 (file)
@@ -67,8 +67,10 @@ drupal_set_title ('
 
 $details=new PlcDetails($can_update);
 
-// hardwire network type
-$form=$details->form_start(l_actions(),array('node_id'=>$node_id,'type'=>"ipv4"));
+// xxx hardwire network type for now
+$form_variables = array('node_id'=>$node_id,'type'=>"ipv4");
+if ($mode == "update") $form_variables['interface_id']=$interface_id;
+$form=$details->form_start(l_actions(),$form_variables);
 
 $details->start();
 
@@ -87,25 +89,26 @@ function method_selectors ($api, $method) {
 }
 $method_select = $form->select_html ("method",method_selectors($api,$interface['method']),
                                     array('id'=>'method','onChange'=>'updateMethodFields()'));
-$details->th_td("Method",$method_select,"method",array('input_type'=>'select'));
+$details->th_td("Method",$method_select,"method",array('input_type'=>'select','value'=>$interface['method']));
 
 // dont display the 'type' selector as it contains only ipv4
 //>>> GetNetworkTypes()
 //[u'ipv4']
 
-$ip_options=array('width'=>15);
-$ip_options_plus=array_merge($ip_options,array('onKeyup'=>'networkHelper()',
-                                              'onChange'=>'networkHelper()',
-                                              ));
-$ip_options_tmp=array_merge($ip_options,array('onKeyup'=>'subnetChecker("dns1")'));
-
-$details->th_td("IP",$interface['ip'],"ip",$ip_options_plus);
-$details->th_td("Netmask",$interface['netmask'],"netmask",$ip_options_plus);
-$details->th_td("Network",$interface['network'],"network",$ip_options);
-$details->th_td("Broadcast",$interface['broadcast'],"broadcast",$ip_options);
-$details->th_td("Gateway",$interface['gateway'],"gateway",$ip_options);
-$details->th_td("DNS 1",$interface['dns1'],"dns1",$ip_options_tmp);
-$details->th_td("DNS 2",$interface['dns2'],"dns2",$ip_options);
+$details->th_td("IP",$interface['ip'],"ip",array('width'=>15,
+                                                'onKeyup'=>'networkHelper()',
+                                                'onChange'=>'networkHelper()'));
+$details->th_td("Netmask",$interface['netmask'],"netmask",array('width'=>15,
+                                                               'onKeyup'=>'networkHelper()',
+                                                               'onChange'=>'networkHelper()'));
+$details->th_td("Network",$interface['network'],"network",array('width'=>15));
+$details->th_td("Broadcast",$interface['broadcast'],"broadcast",array('width'=>15));
+$details->th_td("Gateway",$interface['gateway'],"gateway",array('width'=>15,
+                                                               'onChange'=>'subnetChecker("gateway",false)'));
+$details->th_td("DNS 1",$interface['dns1'],"dns1",array('width'=>15,
+                                                               'onChange'=>'subnetChecker("dns1",false)'));
+$details->th_td("DNS 2",$interface['dns2'],"dns2",array('width'=>15,
+                                                               'onChange'=>'subnetChecker("dns2",true)'));
 $details->space();
 $details->th_td("BW limit (bps)",$interface['bwlimit'],"bwlimit",array('width'=>11));
 $details->th_td("Hostname",$interface['hostname'],"hostname");
@@ -114,15 +117,16 @@ $mac=$interface['mac'];
 if ($mac) $details->th_td("MAC address",$mac);
 
 // the buttons
-$update_button = $form->submit_html ("update-interface","Update");
-$add_button = $form->submit_html ("add-interface","Add as new");
-$dbg="<input type=button onclick='formSubmit()' value='dbg'>";
+$update_button = $form->submit_html ("update-interface","Update",
+                                    array('onSubmit'=>'interfaceSubmit()'));
+$add_button = $form->submit_html ("add-interface","Add as new",
+                                 array('onSubmit'=>'interfaceSubmit()'));
 switch ($mode) {
  case 'add':
    $details->tr($add_button,"right");
    break;
  case 'update':
-   $details->tr($update_button . $add_button . $dbg,"right");
+   $details->tr($update_button . "&nbsp" . $add_button,"right");
    break;
  }
 
index 6b3f659..126dee9 100644 (file)
@@ -229,7 +229,7 @@ if ($can_manage_keys) {
   }
   $table->row_start();
   $table->cell($form->label_html("key","Upload new key")
-              . $form->file_html("key",60)
+              . $form->file_html("key","upload",array('size'=>60))
               . $form->submit_html("upload-key","Upload key"),
               $table->columns(),"right");
   $table->row_end();
index dfe8ab4..afb3c95 100644 (file)
@@ -495,7 +495,7 @@ Object.extend(String.prototype, {
   isJSON: function() {
     var str = this;
     if (str.blank()) return false;
-    str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
+    str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');  /* " for fooling emacs*/
     return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
   },
 
@@ -4317,4 +4317,4 @@ Object.extend(Element.ClassNames.prototype, Enumerable);
 
 /*--------------------------------------------------------------------------*/
 
-Element.addMethods();
\ No newline at end of file
+Element.addMethods();
index 2112202..7d20f19 100644 (file)
@@ -63,15 +63,12 @@ $details->th_td("Name",$tagname,"tagname");
 $details->th_td("Category",$category,"category");
 $details->th_td("Description",$description,"description");
 
-// xxx misses in PlcDetails
 if ($can_update) {
-//tmp
 // select the option corresponding with min_role_id
   $selectors = $details->form()->role_selectors($api,"",$min_role_id);
   $select_field = $details->form()->select_html("min_role_id",$selectors);
-  $save_i=$details->set_input_type("select");
-  $details->th_td("Min role",$select_field,"min_role_id");
-  $details->set_input_type($save_i);
+  // xxx would need to turn role_id into role name
+  $details->th_td("Min role",$select_field,"min_role_id",array('input_type'=>'select','value'=>$min_role_id));
  } else {
   $details->th_td("Min role",$min_role_id);
  }