Changeset 4243 in subversion


Ignore:
Timestamp:
Nov 21, 2010 11:47:21 AM (3 years ago)
Author:
thomasb
Message:

Allow address sources to limit/extend the contact coltypes

Location:
branches/devel-addressbook/program
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-addressbook/program/include/rcube_addressbook.php

    r4227 r4243  
    66 |                                                                       | 
    77 | This file is part of the Roundcube Webmail client                     | 
    8  | Copyright (C) 2006-2009, Roundcube Dev. - Switzerland                 | 
     8 | Copyright (C) 2006-2010, Roundcube Dev. - Switzerland                 | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    2828abstract class rcube_addressbook 
    2929{ 
    30     /** public properties */ 
    31     var $primary_key; 
    32     var $groups = false; 
    33     var $readonly = true; 
    34     var $ready = false; 
    35     var $list_page = 1; 
    36     var $page_size = 10; 
     30    /** public properties (mandatory) */ 
     31    public $primary_key; 
     32    public $groups = false; 
     33    public $readonly = true; 
     34    public $ready = false; 
     35    public $list_page = 1; 
     36    public $page_size = 10; 
     37    public $coltypes = array('name' => array('limit'=>1), 'firstname' => array('limit'=>1), 'surname' => array('limit'=>1), 'email' => array('limit'=>1)); 
    3738 
    3839    /** 
  • branches/devel-addressbook/program/include/rcube_contacts.php

    r4240 r4243  
    4848 
    4949    // public properties 
    50     var $primary_key = 'contact_id'; 
    51     var $readonly = false; 
    52     var $groups = true; 
    53     var $list_page = 1; 
    54     var $page_size = 10; 
    55     var $group_id = 0; 
    56     var $ready = false; 
     50    public $primary_key = 'contact_id'; 
     51    public $readonly = false; 
     52    public $groups = true; 
     53    public $list_page = 1; 
     54    public $page_size = 10; 
     55    public $group_id = 0; 
     56    public $ready = false; 
     57    public $coltypes = array('name', 'firstname', 'surname', 'middlename', 'prefix', 'suffix', 'nickname', 
     58      'jobtitle', 'organization', 'department', 'gender', 'maidenname', 'email', 'phone', 'address', 
     59      'birthday', 'website', 'im', 'notes'); 
    5760 
    5861 
  • branches/devel-addressbook/program/js/app.js

    r4242 r4243  
    40294029        } 
    40304030        else if (colprop.type == 'composite') { 
    4031           var childcol, cp; 
    4032           for (var j=0; j < colprop.childs.length; j++) { 
    4033               childcol = colprop.childs[j]; 
    4034               cp = this.env.coltypes[childcol]; 
    4035               input = $('<input>') 
    4036                 .addClass('ff_'+childcol) 
    4037                 .attr('type', 'text') 
    4038                 .attr('name', '_'+childcol+'[]') 
    4039                 .attr('size', cp.size) 
    4040                 .appendTo(cell); 
    4041               cell.append(" "); 
    4042               this.init_edit_field(childcol, input); 
    4043             } 
     4031          var childcol, cp, first; 
     4032          for (var childcol in colprop.childs) { 
     4033            cp = colprop.childs[childcol]; 
     4034            input = $('<input>') 
     4035              .addClass('ff_'+childcol) 
     4036              .attr('type', 'text') 
     4037              .attr('name', '_'+childcol+'[]') 
     4038              .attr('size', cp.size) 
     4039              .appendTo(cell); 
     4040            cell.append(" "); 
     4041            this.init_edit_field(childcol, input); 
     4042            if (!first) first = input; 
     4043          } 
     4044          input = first;  // set focus to the first of this composite fields 
    40444045        } 
    40454046        else if (colprop.type == 'select') { 
  • branches/devel-addressbook/program/steps/addressbook/func.inc

    r4242 r4243  
    5757 
    5858 
    59 // TODO: let the $CONTACT object define the list of possible coltypes 
     59// general definition of contact coltypes 
    6060$CONTACT_COLTYPES = array( 
    6161  'name'         => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('name')), 
     
    7373  'email'        => array('type' => 'text', 'size' => 40, 'label' => rcube_label('email'), 'subtypes' => array('home','work','other')), 
    7474  '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')), 
    75   'address'      => array('type' => 'composite', 'label' => rcube_label('address'), 'subtypes' => array('home','work','other'), 'childs' => array('street','locality','zipcode','region','country')), 
    76     'street'     => array('type' => 'text', 'size' => 40, 'label' => rcube_label('street'), 'composite' => true), 
    77     'locality'   => array('type' => 'text', 'size' => 28, 'label' => rcube_label('locality'), 'composite' => true), 
    78     'zipcode'    => array('type' => 'text', 'size' => 8, 'label' => rcube_label('zipcode'), 'composite' => true), 
    79     'region'     => array('type' => 'text', 'size' => 12, 'label' => rcube_label('region'), 'composite' => true), 
    80     'country'    => array('type' => 'text', 'size' => 40, 'label' => rcube_label('country'), 'composite' => true), 
     75  'address'      => array('type' => 'composite', 'label' => rcube_label('address'), 'subtypes' => array('home','work','other'), 'childs' => array( 
     76    'street'     => array('type' => 'text', 'size' => 40, 'label' => rcube_label('street')), 
     77    'locality'   => array('type' => 'text', 'size' => 28, 'label' => rcube_label('locality')), 
     78    'zipcode'    => array('type' => 'text', 'size' => 8, 'label' => rcube_label('zipcode')), 
     79    'region'     => array('type' => 'text', 'size' => 12, 'label' => rcube_label('region')), 
     80    'country'    => array('type' => 'text', 'size' => 40, 'label' => rcube_label('country')), 
     81  )), 
    8182  'birthday'     => array('type' => 'date', 'size' => 12, 'label' => rcube_label('birthday'), 'limit' => 1, 'render_func' => 'rcmail_format_date_col'), 
    8283  'website'      => array('type' => 'text', 'size' => 40, 'label' => rcube_label('website'), 'subtypes' => array('home','work','blog','other')), 
     
    8687); 
    8788 
     89// reduce/extend $CONTACT_COLTYPES with specification from the current $CONTACT object 
     90if (is_array($CONTACTS->coltypes)) { 
     91    // remove cols not listed by the backend class 
     92    $contact_cols = $CONTACTS->coltypes[0] ? array_flip($CONTACTS->coltypes) : $CONTACTS->coltypes; 
     93    $CONTACT_COLTYPES = array_intersect_key($CONTACT_COLTYPES, $contact_cols); 
     94    // add associative coltypes definition 
     95    if (!$CONTACTS->coltypes[0]) { 
     96        foreach ($CONTACTS->coltypes as $col => $colprop) 
     97            $CONTACT_COLTYPES[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], $colprop) : $colprop; 
     98    } 
     99} 
    88100 
    89101 
     
    282294    // get default coltypes 
    283295    $coltypes = $GLOBALS['CONTACT_COLTYPES']; 
     296    $coltype_lables = array(); 
    284297     
    285298    foreach ($coltypes as $col => $prop) { 
     
    288301            $select_subtype->add($prop['subtypes']); 
    289302            $coltypes[$col]['subtypes_select'] = $select_subtype->show(); 
     303        } 
     304        if ($prop['childs']) { 
     305            foreach ($prop['childs'] as $childcol => $cp) 
     306                $coltype_lables[$childcol] = array('label' => $cp['label']); 
    290307        } 
    291308    } 
     
    316333                $fields = ''; 
    317334                foreach ($colnames as $col) { 
     335                    // skip cols unknown to the backend 
     336                    if (!$coltypes[$col]) 
     337                        continue; 
     338 
    318339                    if ($RCMAIL->action == 'show') { 
    319340                        if (!empty($record[$col])) 
     
    343364        if (is_array($fieldset['content'])) { 
    344365            foreach ($fieldset['content'] as $col => $colprop) { 
     366                // skip cols unknown to the backend 
     367                if (!$coltypes[$col]) 
     368                    continue; 
     369                 
    345370                // remove subtype part of col name 
    346371                list($field, $subtype) = explode(':', $col); 
     
    405430                    // render composite field 
    406431                    if ($colprop['type'] == 'composite') { 
    407                         $composite = ''; 
    408                         foreach ($colprop['childs'] as $j => $childcol) { 
     432                        $composite = ''; $j = 0; 
     433                        foreach ($colprop['childs'] as $childcol => $cp) { 
    409434                            $childvalue = $val[$childcol] ? $val[$childcol] : $val[$j]; 
    410435 
    411436                            if ($edit_mode) { 
    412                                 $cp = $coltypes[$childcol]; 
    413437                                if ($colprop['subtypes']) $cp['array'] = true; 
    414438                                $composite .= rcmail_get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " "; 
     
    418442                                $composite .= html::span('data ' . $childcol, $childval) . " "; 
    419443                            } 
     444                            $j++; 
    420445                        } 
    421446 
     
    488513    if ($edit_mode) { 
    489514      $RCMAIL->output->set_env('contactdata', $formdata); 
    490       $RCMAIL->output->set_env('coltypes', $coltypes); 
     515      $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_lables); 
    491516      $RCMAIL->output->set_env('delbutton', $del_button); 
    492517      $RCMAIL->output->add_label('delete'); 
Note: See TracChangeset for help on using the changeset viewer.