fixed: show no slices when user has no slices
[plewww.git] / planetlab / tags / tags.php
index 8b768d7..75b89dd 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 // Require login
 require_once 'plc_login.php';
 
@@ -15,9 +13,9 @@ include 'plc_header.php';
 
 // Common functions
 require_once 'plc_functions.php';
-require_once 'plc_minitabs.php';
-require_once 'plc_tables.php';
-require_once 'plc_forms.php';
+require_once 'linetabs.php';
+require_once 'table.php';
+require_once 'form.php';
 
 // -------------------- 
 // recognized URL arguments
@@ -26,17 +24,15 @@ $pattern=$_GET['pattern'];
 // --- decoration
 $title="Tag Types";
 $tabs=array();
-$tabs['New Tag Type']=array('url'=>l_tag_add(),'bubble'=>"Create a new tag type");
-$tabs['All Nodes']=array('url'=>l_nodes(),'bubble'=>"Nodes from all peers");
-$tabs['Local Nodes']=array('url'=>l_nodes(),'values'=>array('peerscope'=>'local'),'bubble'=>"All local nodes");
-//$tabs['Interfaces']=l_interfaces();
-$tabs['All Slices']=array('url'=>l_slices(),'bubble'=>"Slices from all peers");
+$tabs []= tab_tags();
+$tabs []= tab_nodes_local();
+$tabs []= tab_slices();
 
 // -------------------- 
 drupal_set_title($title);
-plc_tabs($tabs);
+plekit_linetabs($tabs);
 
-$tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "min_role_id" );
+$tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "roles");
 
 $tag_type_filter=NULL;
 if ($pattern) 
@@ -46,38 +42,64 @@ if ($pattern)
 $tag_types= $api->GetTagTypes($tag_type_filter, $tag_type_columns);
   
 $headers=array();
+$notes=array();
 // delete button
-if (plc_is_admin()) $headers[' ']="none";
-$headers["Id"]="int";
 $headers['Name']="string";
 $headers['Description']="string";
-$headers['Min role']="string";
 $headers['Category']="string";
+$headers['Roles']="string";
+
+// xxx ref count would be helpful but seem too expensive to compute at this stage 
+// the individual tag page show those ref counts per type
+
+$headers["Id"]="int";
+if (plc_is_admin()) $headers[plc_delete_icon()]="none";
 
-plc_table_start("tags",$headers,1);
+$form=new PlekitForm(l_actions(),NULL);
+$form->start();
 
-$roles_hash=plc_role_global_hash($api);
+$table = new PlekitTable("tags",$headers,0,array('notes'=>$notes));
+$table->start();
+
+$description_width=40;
 
 foreach( $tag_types as $tag_type ) {
-  $role_name=$roles_hash[$tag_type['min_role_id']];
 
-  plc_table_row_start();
-  $id=$tag_type['tag_type_id'];
+  $table->row_start();
+  $tag_type_id=$tag_type['tag_type_id'];
+  $table->cell(href(l_tag($tag_type_id),$tag_type['tagname']));
+  $table->cell(wordwrap($tag_type['description'],$description_width,"<br/>"));
+  $table->cell($tag_type['category']);
+  $table->cell(plc_vertical_table ($tag_type['roles']));
+  $table->cell($tag_type_id);
   if (plc_is_admin()) 
-    plc_table_cell(plc_delete_link_button ('tag_action.php?del_type='. $id,
-                                          $tag_type['tagname']));
-  plc_table_cell($id);
-  plc_table_cell(href(l_tag_update($id),$tag_type['tagname']));
-  plc_table_cell(wordwrap($tag_type['description'],40,"<br/>"));
-  plc_table_cell($role_name);
-  plc_table_cell($tag_type['category']);
-  plc_table_row_end();
+    $table->cell ($form->checkbox_html('tag_type_ids[]',$tag_type_id));
+  $table->row_end();
 }
-$footers=array();
-if (plc_is_admin()) 
-  $footers[]=plc_table_td_text(plc_form_simple_button(l_tag_add(),"Add a Tag Type","GET"),6,"right");
 
-plc_table_end("tags",array('footers'=>$footers));
+if (plc_is_admin()) {
+  $table->tfoot_start();
+
+  $table->row_start();
+  $table->cell($form->submit_html ("delete-tag-types","Remove tags"),
+              array('hfill'=>true,'align'=>'right'));
+  $table->row_end();
+
+  // an inline area to add a tag type
+  $table->row_start();
+  
+  $table->cell($form->text_html('tagname',''));
+  $table->cell($form->textarea_html('description','',$description_width,2));
+  $table->cell($form->text_html('category',''));
+  $table->cell("<span class='note_roles'>add roles later</span>");
+  $table->cell($form->submit_html("add-tag-type","Add"),2);
+  $table->row_end();
+ }
+
+$table->end();
+$form->end();
+
+//plekit_linetabs ($tabs,"bottom");
 
 // Print footer
 include 'plc_footer.php';