[Svn] r4239 - in branches/devel-addressbook: config program/include program/js program/steps/addressbook skins/default skins/default/templates

trac at roundcube.net trac at roundcube.net
Fri Nov 19 20:12:24 CET 2010


Author: thomasb
Date: 2010-11-19 13:12:24 -0600 (Fri, 19 Nov 2010)
New Revision: 4239

Modified:
   branches/devel-addressbook/config/main.inc.php.dist
   branches/devel-addressbook/program/include/html.php
   branches/devel-addressbook/program/include/main.inc
   branches/devel-addressbook/program/include/rcube_contacts.php
   branches/devel-addressbook/program/include/rcube_vcard.php
   branches/devel-addressbook/program/js/app.js
   branches/devel-addressbook/program/steps/addressbook/edit.inc
   branches/devel-addressbook/program/steps/addressbook/func.inc
   branches/devel-addressbook/program/steps/addressbook/show.inc
   branches/devel-addressbook/skins/default/addressbook.css
   branches/devel-addressbook/skins/default/templates/contactadd.html
   branches/devel-addressbook/skins/default/templates/contactedit.html
Log:
Improve vcard saving; use callback functions to render certain contact fields; add button to delete a contact field

Modified: branches/devel-addressbook/config/main.inc.php.dist
===================================================================
--- branches/devel-addressbook/config/main.inc.php.dist	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/config/main.inc.php.dist	2010-11-19 19:12:24 UTC (rev 4239)
@@ -324,6 +324,9 @@
 // use this format for today's date display (date or strftime format)
 $rcmail_config['date_today'] = 'H:i';
 
+// use this format for date display without time (date or strftime format)
+$rcmail_config['date_format'] = 'Y-m-d';
+
 // store draft message is this mailbox
 // leave blank if draft messages should not be stored
 $rcmail_config['drafts_mbox'] = 'Drafts';

Modified: branches/devel-addressbook/program/include/html.php
===================================================================
--- branches/devel-addressbook/program/include/html.php	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/program/include/html.php	2010-11-19 19:12:24 UTC (rev 4239)
@@ -147,7 +147,7 @@
             $attr = array('href' => $attr);
         }
         return self::tag('a', $attr, $cont, array_merge(self::$common_attrib,
-	    array('href','target','name','onclick','onmouseover','onmouseout','onmousedown','onmouseup')));
+	    array('href','target','name','rel','onclick','onmouseover','onmouseout','onmousedown','onmouseup')));
     }
 
     /**

Modified: branches/devel-addressbook/program/include/main.inc
===================================================================
--- branches/devel-addressbook/program/include/main.inc	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/program/include/main.inc	2010-11-19 19:12:24 UTC (rev 4239)
@@ -824,16 +824,19 @@
   $attrib['name'] = $fname . ($attrib['array'] ? '[]' : '');
   $attrib['class'] = trim($attrib['class'] . ' ff_' . $col);
   
-  if ($type=='checkbox') {
+  if ($type == 'checkbox') {
     $attrib['value'] = '1';
     $input = new html_checkbox($attrib);
   }
-  else if ($type=='textarea') {
+  else if ($type == 'textarea') {
     $attrib['cols'] = $attrib['size'];
     $input = new html_textarea($attrib);
   }
-  else
+  else {
+    if ($attrib['type'] != 'text' && $attrib['type'] != 'hidden')
+        $attrib['type'] = 'text';
     $input = new html_inputfield($attrib);
+  }
 
   // use value from post
   if (isset($_POST[$fname])) {

Modified: branches/devel-addressbook/program/include/rcube_contacts.php
===================================================================
--- branches/devel-addressbook/program/include/rcube_contacts.php	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/program/include/rcube_contacts.php	2010-11-19 19:12:24 UTC (rev 4239)
@@ -500,7 +500,7 @@
         foreach ($save_data as $key => $values) {
             list($field, $section) = explode(':', $key);
             foreach ((array)$values as $value) {
-                if (strlen($value) || is_array($value))
+                if (is_array($value) || strlen($value))
                     $vcard->set($field, $value, strtoupper($section));
             }
         }

Modified: branches/devel-addressbook/program/include/rcube_vcard.php
===================================================================
--- branches/devel-addressbook/program/include/rcube_vcard.php	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/program/include/rcube_vcard.php	2010-11-19 19:12:24 UTC (rev 4239)
@@ -195,10 +195,17 @@
       case 'email':
         if (!$touched['EMAIL']++)
           $this->raw['EMAIL'] = array();
-        $index = count($this->raw['EMAIL']);
-        $this->raw['EMAIL'][$index] = array(0 => $value, 'type' => array_filter(array('INTERNET', $type)));
+        $this->raw['EMAIL'][] = array(0 => $value, 'type' => array_filter(array('INTERNET', $type)));
         break;
 
+      case 'birthday':
+        if ($val = @strtotime($value)) {
+          if (!$touched['BDAY']++)
+            $this->raw['BDAY'] = array();
+          $this->raw['BDAY'][] = array(0 => date('Y-m-d', $val), 'value' => array('date'));
+        }
+        break;
+
       case 'address':
         $value = $value[0] ? $value : array('', '', $value['street'], $value['locality'], $value['region'], $value['zipcode'], $value['country']);
         // fall through

Modified: branches/devel-addressbook/program/js/app.js
===================================================================
--- branches/devel-addressbook/program/js/app.js	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/program/js/app.js	2010-11-19 19:12:24 UTC (rev 4239)
@@ -324,6 +324,8 @@
           for (var col in this.env.coltypes)
             this.init_edit_field(col, null);
 
+          $('.contactfieldgroup .row a.deletebutton').click(function(){ ref.delete_edit_field(this); return false });
+
           $('select.addfieldmenu').change(function(e){
             ref.insert_edit_field($(this).val(), $(this).attr('rel'), this);
             this.selectedIndex = 0;
@@ -4042,6 +4044,14 @@
         }
 
         if (input) {
+          var delbutton = $('<a href="#del"></a>')
+            .addClass('contactfieldbutton deletebutton')
+            .attr('title', this.get_label('delete'))
+            .attr('rel', col)
+            .html(this.env.delbutton)
+            .click(function(){ ref.delete_edit_field(this); return false })
+            .appendTo(cell);
+          
           row.append(label).append(cell).appendTo(appendcontainer);
           input.first().focus();
           
@@ -4054,7 +4064,14 @@
     }
   };
 
+  this.delete_edit_field = function(elem){
+    var col = $(elem).attr('rel');
+    $(elem).parents('div.row').remove();
+    
+    // TODO: enable option in add-field selector or insert it if necessary
+  };
 
+
   /*********************************************************/
   /*********        user settings methods          *********/
   /*********************************************************/

Modified: branches/devel-addressbook/program/steps/addressbook/edit.inc
===================================================================
--- branches/devel-addressbook/program/steps/addressbook/edit.inc	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/program/steps/addressbook/edit.inc	2010-11-19 19:12:24 UTC (rev 4239)
@@ -114,7 +114,7 @@
     unset($attrib['form']);
 
     // return the complete address edit form as table
-    $out = rcmail_contact_form($form, $record);
+    $out = rcmail_contact_form($form, $record, $attrib);
 
     return $form_start . $out . $form_end;
 }

Modified: branches/devel-addressbook/program/steps/addressbook/func.inc
===================================================================
--- branches/devel-addressbook/program/steps/addressbook/func.inc	2010-11-19 13:52:39 UTC (rev 4238)
+++ branches/devel-addressbook/program/steps/addressbook/func.inc	2010-11-19 19:12:24 UTC (rev 4239)
@@ -74,7 +74,7 @@
     '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),
-  'birthday'     => array('type' => 'date', 'size' => 12, 'label' => rcube_label('birthday'), 'limit' => 1),
+  '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')),
   'notes'        => array('type' => 'textarea', 'size' => 40, 'rows' => 15, 'label' => rcube_label('notes'), 'limit' => 1),
@@ -261,7 +261,7 @@
 
 function rcmail_contact_form($form, $record, $attrib = null)
 {
-    global $RCMAIL;
+    global $RCMAIL, $CONFIG;
 
     // Allow plugins to modify contact form content
     $plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
@@ -270,6 +270,7 @@
     $form = $plugin['form'];
     $record = $plugin['record'];
     $formdata = array();
+    $del_button = $attrib['deleteicon'] ? html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))) : rcube_label('delete');
     $out = '';
     
     // get default coltypes
@@ -335,8 +336,7 @@
         $content = '';
         if (is_array($fieldset['content'])) {
             foreach ($fieldset['content'] as $col => $colprop) {
-              #  $colprop['id'] = 'rcmfd_'.$col;
-
+                // remove subtype part of col name
                 list($field, $subtype) = explode(':', $col);
                 if (!$subtype)
                   $subtype = 'home';
@@ -344,9 +344,11 @@
                 $fullkey = $col.':'.$subtype;
                 $label = isset($colprop['label']) ? $colprop['label'] : rcube_label($col);
                 
+                // merge colprop with global coltype configuration
                 if ($coltypes[$field])
                     $colprop += $coltypes[$field];
 
+                // prepare subtype selector in edit mode
                 if ($RCMAIL->action != 'show' && is_array($colprop['subtypes'])) {
                     $select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype'));
                     $select_subtype->add($colprop['subtypes']);
@@ -358,6 +360,7 @@
                     $values = (array)$colprop['value'];
                 }
                 else {
+                    // iterate over possible subtypes and collect values with their subtype
                     if (is_array($colprop['subtypes'])) {
                         $values = $subtypes = array();
                         foreach ($colprop['subtypes'] as $i => $st) {
@@ -384,6 +387,7 @@
                     }
                 }
 
+                // hack: create empty values array to force this field to be displayed
                 if (empty($values) && $colprop['visible'])
                     $values[] = '';
 
@@ -403,13 +407,19 @@
                                 if ($colprop['subtypes']) $cp['array'] = true;
                                 $composite .= rcmail_get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " ";
                             }
-                            else
-                                $composite .= html::span('data ' . $childcol, Q($childvalue)) . " ";
+                            else {
+                                $childval = $cp['render_func'] ? call_user_func($cp['render_func'], $childvalue, $childcol) : Q($childvalue);
+                                $composite .= html::span('data ' . $childcol, $childval) . " ";
+                            }
                         }
 
                         $val = $composite;
                     }
                     else if ($RCMAIL->action != 'show') {
+                        // call callback to render/format value
+                        if ($colprop['render_func'])
+                            $val = call_user_func($colprop['render_func'], $val, $col);
+
                         $coltypes[$field] = array('field' => $field, 'label' => $label) + (array)$colprop;
                         $formdata[$field][] = array('subtype' => $subtype, 'value' => $val);
 
@@ -418,18 +428,26 @@
                         $val = rcmail_get_edit_field($col, $val, $colprop, $colprop['type']);
                         $coltypes[$field]['count']++;
                     }
-                    else if (!$colprop['value'])
+                    else if ($colprop['render_func'])
+                        $val = call_user_func($colprop['render_func'], $val, $col);
+                    else
                         $val = Q($val);
 
+                    // use subtype as label
                     if ($colprop['subtypes'])
                         $label = $subtype;
 
+                    // add delete button/link
+                    if ($RCMAIL->action != 'show' && (!$colprop['visible'] || count($values) > 1))
+                        $val .= html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => rcube_label('delete'), 'rel' => $col), $del_button);
+
+                    // display row with label
                     if ($label) {
                         $rows .= html::div('row',
                             html::div('contactfieldlabel label', $select_subtype ? $select_subtype->show($subtype) : Q($label)) .
                             html::div('contactfieldcontent '.$colprop['type'], $val));
                     }
-                    else
+                    else   // row without label
                         $rows .= html::div('row', html::div('contactfield', $val));
                 }
                 
@@ -439,9 +457,11 @@
                     $select_add->_count++;
                 }
                 
+                // wrap rows in fieldgroup container
                 $content .= html::div('contactfieldgroup contactcontroller' . $col, $rows);
             }
 
+            // also render add-field selector
             if ($RCMAIL->action != 'show' && $select_add->_count)
                 $content .= html::p('ad