Fix handling of 'display' field for PlTableEditor.
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 26 Jun 2011 22:22:54 +0000 (00:22 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 26 Jun 2011 22:22:54 +0000 (00:22 +0200)
Now split into two subfields:
* display_list controls the display in list mode
* display_item controls the display in 'item' mode

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/pltableeditor.php
templates/table-editor.tpl

index 208a92d..89c0b14 100644 (file)
@@ -95,7 +95,10 @@ class PLTableEditor
         while ($a = $r->next()) {
             // desc will be the title of the column
             $a['desc'] = $a['Field'];
-            $a['display'] = true;
+            // display_list decides whether to display the field in 'list' mode
+            $a['display_list'] = true;
+            // display_item decides whether a field is displayed in 'item edition' mode
+            $a['display_item'] = true;
 
             if (substr($a['Type'],0,8) == 'varchar(') {
                 // limit editing box size
@@ -181,10 +184,11 @@ class PLTableEditor
     }
 
     // change display of a field
-    public function describe($name, $desc, $display)
+    public function describe($name, $desc, $display_list, $display_item=true)
     {
         $this->vars[$name]['desc'] = $desc;
-        $this->vars[$name]['display'] = $display;
+        $this->vars[$name]['display_list'] = $display_list;
+        $this->vars[$name]['display_item'] = $display_item;
     }
 
     // add a join table, when deleting a row corresponding entries will be deleted in these tables
@@ -361,7 +365,7 @@ class PLTableEditor
                     } elseif ($descr['Type'] == 'ip_address') {
                         $val = ip2long($val);
                     }
-                } elseif ($descr['display']) {
+                } elseif ($descr['display_item']) {
                     $cancel = true;
                     $page->trigError("Il manque le champ ".$field);
                 }
@@ -458,7 +462,7 @@ class PLTableEditor
             $it = XDB::iterator("SELECT t.* {$optional_fields} FROM {$this->table} AS t {$optional_joints} WHERE " . $this->get_where_clause() . " $sort");
             $this->nbfields = 0;
             foreach ($this->vars as $field => $descr)
-                if ($descr['display']) $this->nbfields++;
+                if ($descr['display_list']) $this->nbfields++;
             $page->assign('list', $it);
         }
         $page->assign('t', $this);
index f89e021..80b6caa 100644 (file)
@@ -33,7 +33,7 @@
 </script>
 <table class="bicol">
 <tr>
-  {foreach from=$t->vars item=myval key=myvar}{if $myval.display}
+  {foreach from=$t->vars item=myval key=myvar}{if $myval.display_list}
     <th style="cursor:pointer" onclick="redirect('{$t->pl}/sort{if $t->sortfield eq $myvar && !$t->sortdesc}desc{/if}/{$myvar}')">{$myval.desc}{if $t->sortfield eq $myvar}{if $t->sortdesc}{icon name="bullet_arrow_down"}{else}{icon name="bullet_arrow_up"}{/if}{/if}</th>
   {/if}{/foreach}
   {if !$hideactions}
@@ -54,7 +54,7 @@
 {/if}
 {iterate from=$list item=myrow}
 <tr class="{cycle values="pair,impair"}">
-{foreach from=$t->vars item=myval}{if $myval.display}
+{foreach from=$t->vars item=myval}{if $myval.display_list}
   <td>
     {assign var="myfield" value=$myval.Field}
     {if $myfield eq $t->idfield}
         {/if}
       </th>
     </tr>
-    {foreach from=$t->vars item=myval}{assign var="myfield" value=$myval.Field}{if (($myfield neq $t->idfield) or ($t->idfield_editable)) and $myval.display}
+    {foreach from=$t->vars item=myval}{assign var="myfield" value=$myval.Field}{if (($myfield neq $t->idfield) or ($t->idfield_editable)) and $myval.display_item}
     <tr class="{cycle values="pair,impair"}">
       <td>
         <strong>{$myval.desc}</strong>