[Svn] r4243 - in branches/devel-addressbook/program: include js steps/addressbook

trac at roundcube.net trac at roundcube.net
Sun Nov 21 17:47:21 CET 2010


Author: thomasb
Date: 2010-11-21 10:47:21 -0600 (Sun, 21 Nov 2010)
New Revision: 4243

Modified:
   branches/devel-addressbook/program/include/rcube_addressbook.php
   branches/devel-addressbook/program/include/rcube_contacts.php
   branches/devel-addressbook/program/js/app.js
   branches/devel-addressbook/program/steps/addressbook/func.inc
Log:
Allow address sources to limit/extend the contact coltypes

Modified: branches/devel-addressbook/program/include/rcube_addressbook.php
===================================================================
--- branches/devel-addressbook/program/include/rcube_addressbook.php	2010-11-21 14:49:03 UTC (rev 4242)
+++ branches/devel-addressbook/program/include/rcube_addressbook.php	2010-11-21 16:47:21 UTC (rev 4243)
@@ -5,7 +5,7 @@
  | program/include/rcube_addressbook.php                                 |
  |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2006-2009, Roundcube Dev. - Switzerland                 |
+ | Copyright (C) 2006-2010, Roundcube Dev. - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -27,13 +27,14 @@
  */
 abstract class rcube_addressbook
 {
-    /** public properties */
-    var $primary_key;
-    var $groups = false;
-    var $readonly = true;
-    var $ready = false;
-    var $list_page = 1;
-    var $page_size = 10;
+    /** public properties (mandatory) */
+    public $primary_key;
+    public $groups = false;
+    public $readonly = true;
+    public $ready = false;
+    public $list_page = 1;
+    public $page_size = 10;
+    public $coltypes = array('name' => array('limit'=>1), 'firstname' => array('limit'=>1), 'surname' => array('limit'=>1), 'email' => array('limit'=>1));
 
     /**
      * Save a search string for future listings

Modified: branches/devel-addressbook/program/include/rcube_contacts.php
===================================================================
--- branches/devel-addressbook/program/include/rcube_contacts.php	2010-11-21 14:49:03 UTC (rev 4242)
+++ branches/devel-addressbook/program/include/rcube_contacts.php	2010-11-21 16:47:21 UTC (rev 4243)
@@ -47,13 +47,16 @@
     private $table_cols = array('name', 'email', 'firstname', 'surname', 'vcard');
 
     // public properties
-    var $primary_key = 'contact_id';
-    var $readonly = false;
-    var $groups = true;
-    var $list_page = 1;
-    var $page_size = 10;
-    var $group_id = 0;
-    var $ready = false;
+    public $primary_key = 'contact_id';
+    public $readonly = false;
+    public $groups = true;
+    public $list_page = 1;
+    public $page_size = 10;
+    public $group_id = 0;
+    public $ready = false;
+    public $coltypes = array('name', 'firstname', 'surname', 'middlename', 'prefix', 'suffix', 'nickname',
+      'jobtitle', 'organization', 'department', 'gender', 'maidenname', 'email', 'phone', 'address',
+      'birthday', 'website', 'im', 'notes');
 
 
     /**

Modified: branches/devel-addressbook/program/js/app.js
===================================================================
--- branches/devel-addressbook/program/js/app.js	2010-11-21 14:49:03 UTC (rev 4242)
+++ branches/devel-addressbook/program/js/app.js	2010-11-21 16:47:21 UTC (rev 4243)
@@ -4028,19 +4028,20 @@
           this.init_edit_field(col, input);
         }
         else if (colprop.type == 'composite') {
-          var childcol, cp;
-          for (var j=0; j < colprop.childs.length; j++) {
-              childcol = colprop.childs[j];
-              cp = this.env.coltypes[childcol];
-              input = $('<input>')
-                .addClass('ff_'+childcol)
-                .attr('type', 'text')
-                .attr('name', '_'+childcol+'[]')
-                .attr('size', cp.size)
-                .appendTo(cell);
-              cell.append(" ");
-              this.init_edit_field(childcol, input);
-            }
+          var childcol, cp, first;
+          for (var childcol in colprop.childs) {
+            cp = colprop.childs[childcol];
+            input = $('<input>')
+              .addClass('ff_'+childcol)
+              .attr('type', 'text')
+              .attr('name', '_'+childcol+'[]')
+              .attr('size', cp.size)
+              .appendTo(cell);
+            cell.append(" ");
+            this.init_edit_field(childcol, input);
+            if (!first) first = input;
+          }
+          input = first;  // set focus to the first of this composite fields
         }
         else if (colprop.type == 'select') {
           input = $('<select>')

Modified: branches/devel-addressbook/program/steps/addressbook/func.inc
===================================================================
--- branches/devel-addressbook/program/steps/addressbook/func.inc	2010-11-21 14:49:03 UTC (rev 4242)
+++ branches/devel-addressbook/program/steps/addressbook/func.inc	2010-11-21 16:47:21 UTC (rev 4243)
@@ -56,7 +56,7 @@
 }
 
 
-// TODO: let the $CONTACT object define the list of possible coltypes
+// general definition of contact coltypes
 $CONTACT_COLTYPES = array(
   'name'         => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('name')),
   'firstname'    => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('firstname')),
@@ -72,12 +72,13 @@
   'maidenname'   => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('maidenname')),
   'email'        => array('type' => 'text', 'size' => 40, 'label' => rcube_label('email'), 'subtypes' => array('home','work','other')),
   'phone'        => array('type' => 'text', 'size' => 40, 'label' => rcube_label('phone'), 'subtypes' => array('home','home2','work','work2','mobile','main','homefax','workfax','car','pager','video','assistant','other')),
-  'address'      => array('type' => 'composite', 'label' => rcube_label('address'), 'subtypes' => array('home','work','other'), 'childs' => array('street','locality','zipcode','region','country')),
-    'street'     => array('type' => 'text', 'size' => 40, 'label' => rcube_label('street'), 'composite' => true),
-    'locality'   => array('type' => 'text', 'size' => 28, 'label' => rcube_label('locality'), 'composite' => true),
-    'zipcode'    => array('type' => 'text', 'size' => 8, 'label' => rcube_label('zipcode'), 'composite' => true),
-    'region'     => array('type' => 'text', 'size' => 12, 'label' => rcube_label('region'), 'composite' => true),
-    'country'    => array('type' => 'text', 'size' => 40, 'label' => rcube_label('country'), 'composite' => true),
+  'address'      => array('type' => 'composite', 'label' => rcube_label('address'), 'subtypes' => array('home','work','other'), 'childs' => array(
+    'street'     => array('type' => 'text', 'size' => 40, 'label' => rcube_label('street')),
+    'locality'   => array('type' => 'text', 'size' => 28, 'label' => rcube_label('locality')),
+    'zipcode'    => array('type' => 'text', 'size' => 8, 'label' => rcube_label('zipcode')),
+    'region'     => array('type' => 'text', 'size' => 12, 'label' => rcube_label('region')),
+    'country'    => array('type' => 'text', 'size' => 40, 'label' => rcube_label('country')),
+  )),
   'birthday'     => array('type' => 'date', 'size' => 12, 'label' => rcube_label('birthday'), 'limit' => 1, 'render_func' => 'rcmail_format_date_col'),
   'website'      => array('type' => 'text', 'size' => 40, 'label' => rcube_label('website'), 'subtypes' => array('home','work','blog','other')),
   'im'           => array('type' => 'text', 'size' => 40, 'label' => rcube_label('instantmessenger'), 'subtypes' => array('aim','icq','msn','yahoo','jabber','other')),
@@ -85,6 +86,17 @@
   // TODO: define fields for vcards GEO, PHOTO, KEY, X-ANNIVERSARY, X-ASSISTANT, X-MANAGER
 );
 
+// reduce/extend $CONTACT_COLTYPES with specification from the current $CONTACT object
+if (is_array($CONTACTS->coltypes)) {
+    // remove cols not listed by the backend class
+    $contact_cols = $CONTACTS->coltypes[0] ? array_flip($CONTACTS->coltypes) : $CONTACTS->coltypes;
+    $CONTACT_COLTYPES = array_intersect_key($CONTACT_COLTYPES, $contact_cols);
+    // add associative coltypes definition
+    if (!$CONTACTS->coltypes[0]) {
+        foreach ($CONTACTS->coltypes as $col => $colprop)
+            $CONTACT_COLTYPES[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], $colprop) : $colprop;
+    }
+}
 
 
 function rcmail_directory_list($attrib)
@@ -281,6 +293,7 @@
     
     // get default coltypes
     $coltypes = $GLOBALS['CONTACT_COLTYPES'];
+    $coltype_lables = array();
     
     foreach ($coltypes as $col => $prop) {
         if ($prop['subtypes']) {
@@ -288,6 +301,10 @@
             $select_subtype->add($prop['subtypes']);
             $coltypes[$col]['subtypes_select'] = $select_subtype->show();
         }
+        if ($prop['childs']) {
+            foreach ($prop['childs'] as $childcol => $cp)
+                $coltype_lables[$childcol] = array('label' => $cp['label']);
+        }
     }
 
     foreach ($form as $section => $fieldset) {
@@ -315,6 +332,10 @@
             foreach ($field_blocks as $blockname => $colnames) {
                 $fields = '';
                 foreach ($colnames as $col) {
+                    // skip cols unknown to the backend
+                    if (!$coltypes[$col])
+                        continue;
+
                     if ($RCMAIL->action == 'show') {
                         if (!empty($record[$col]))
                             $fields .= html::span('namefield ' . $col, Q($record[$col])) . " ";
@@ -342,6 +363,10 @@
         $content = '';
         if (is_array($fieldset['content'])) {
             foreach ($fieldset['content'] as $col => $colprop) {
+                // skip cols unknown to the backend
+                if (!$coltypes[$col])
+                    continue;
+                
                 // remove subtype part of col name
                 list($field, $subtype) = explode(':', $col);
                 if (!$subtype)
@@ -404,12 +429,11 @@
 
                     // render composite field
                     if ($colprop['type'] == 'composite') {
-                        $composite = '';
-                        foreach ($colprop['childs'] as $j => $childcol) {
+                        $composite = ''; $j = 0;
+                        foreach ($colprop['childs'] as $childcol => $cp) {
                             $childvalue = $val[$childcol] ? $val[$childcol] : $val[$j];
 
                             if ($edit_mode) {
-                                $cp = $coltypes[$childcol];
                                 if ($colprop['subtypes']) $cp['array'] = true;
                                 $composite .= rcmail_get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " ";
                             }
@@ -417,6 +441,7 @@
                                 $childval = $cp['render_func'] ? call_user_func($cp['render_func'], $childvalue, $childcol) : Q($childvalue);
                                 $composite .= html::span('data ' . $childcol, $childval) . " ";
                             }
+                            $j++;
                         }
 
                         $coltypes[$field] += (array)$colprop;
@@ -487,7 +512,7 @@
 
     if ($edit_mode) {
       $RCMAIL->output->set_env('contactdata', $formdata);
-      $RCMAIL->output->set_env('coltypes', $coltypes);
+      $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_lables);
       $RCMAIL->output->set_env('delbutton', $del_button);
       $RCMAIL->output->add_label('delete');
     }

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list