0012938: add a flag to select a preferred address
authorMichael Spahn <m.spahn@metaways.de>
Tue, 28 Mar 2017 17:17:30 +0000 (19:17 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 4 Apr 2017 18:11:01 +0000 (20:11 +0200)
https://forge.tine20.org/view.php?id=12938

Change-Id: Iea93ab4269f19d9fd49ef053272f785b950fe2e4
Reviewed-on: http://gerrit.tine20.com/customers/4453
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Addressbook/Export/Doc.php
tine20/Addressbook/Export/templates/addressbook_contact_letter.docx
tine20/Addressbook/Model/Contact.php
tine20/Addressbook/Setup/Update/Release10.php
tine20/Addressbook/Setup/setup.xml
tine20/Addressbook/js/ContactEditDialog.js
tine20/Addressbook/js/ContactGrid.js
tine20/Addressbook/js/Model.js

index a3bc686..c31661f 100644 (file)
@@ -28,16 +28,18 @@ class Addressbook_Export_Doc extends Tinebase_Export_Richtext_Doc
     public function processIteration($_records)
     {
         $record = $_records->getFirstRecord();
-        
+
         $converter = Tinebase_Convert_Factory::factory($record);
         $resolved = $converter->fromTine20Model($record);
-        
+
         $this->_docTemplate->setValue('salutation_letter', $this->_getSalutation($resolved));
         $this->_docTemplate->setValue('salutation_resolved', $this->_getShortSalutation($resolved));
-        
+
+        $this->_setAddressBlock($resolved);
+
         parent::processIteration($_records);
     }
-    
+
     /**
      * returns a formal salutation
      *
@@ -47,7 +49,7 @@ class Addressbook_Export_Doc extends Tinebase_Export_Richtext_Doc
     protected function _getSalutation($resolved)
     {
         $i18n = $this->_translate->getAdapter();
-    
+
         if ($resolved['salutation'] == 'MR') {
             $ret = $i18n->_('Dear Mister');
         } elseif ($resolved['salutation'] == 'MRS') {
@@ -57,7 +59,7 @@ class Addressbook_Export_Doc extends Tinebase_Export_Richtext_Doc
         }
         return $ret . ' ' . $resolved['n_given'] . ' ' . $resolved['n_family'];
     }
-    
+
     /**
      * returns a short salutation
      *
@@ -67,7 +69,7 @@ class Addressbook_Export_Doc extends Tinebase_Export_Richtext_Doc
     protected function _getShortSalutation($resolved)
     {
         $i18n = $this->_translate->getAdapter();
-    
+
         if ($resolved['salutation'] == 'MR') {
             $ret = $i18n->_('Mister');
         } elseif ($resolved['salutation'] == 'MRS') {
@@ -77,4 +79,39 @@ class Addressbook_Export_Doc extends Tinebase_Export_Richtext_Doc
         }
         return $ret . ' ' . $resolved['n_given'] . ' ' . $resolved['n_family'];
     }
+
+    /**
+     * Renders either private or business address blocked according the preferred address setting
+     *
+     * The markers to replace are:
+     *  ${company#1}
+     *  ${firstname#1} ${lastname#1}
+     *  ${street#1}
+     *  ${postalcode#1} ${locality#1}
+     *
+     * @param $resolved
+     */
+    protected function _setAddressBlock($resolved)
+    {
+        switch ($resolved['preferred_address']) {
+            // Private
+            case "1":
+                $this->_docTemplate->setValue('company', '');
+                $this->_docTemplate->setValue('firstname', $resolved['n_given']);
+                $this->_docTemplate->setValue('lastname', $resolved['n_family']);
+                $this->_docTemplate->setValue('street', $resolved['adr_two_street']);
+                $this->_docTemplate->setValue('postalcode', $resolved['adr_two_postalcode']);
+                $this->_docTemplate->setValue('locality', $resolved['adr_two_locality']);
+                break;
+            // Business
+            case "0":
+            default:
+                $this->_docTemplate->setValue('company', $resolved['org_name']);
+                $this->_docTemplate->setValue('firstname', $resolved['n_given']);
+                $this->_docTemplate->setValue('lastname', $resolved['n_family']);
+                $this->_docTemplate->setValue('street', $resolved['adr_one_street']);
+                $this->_docTemplate->setValue('postalcode', $resolved['adr_one_postalcode']);
+                $this->_docTemplate->setValue('locality', $resolved['adr_one_locality']);
+        }
+    }
 }
index 70442f4..9ef79af 100644 (file)
Binary files a/tine20/Addressbook/Export/templates/addressbook_contact_letter.docx and b/tine20/Addressbook/Export/templates/addressbook_contact_letter.docx differ
index 37afd5f..92165e0 100644 (file)
@@ -62,6 +62,7 @@
  * @property    string $type                       type of contact
  * @property    string $url                        url of the contact
  * @property    string $url_home                   private url of the contact
+ * @property    integer $preferred_address         defines which is the preferred address of a contact, 0: business, 1: private
  */
 class Addressbook_Model_Contact extends Tinebase_Record_Abstract
 {
@@ -215,6 +216,7 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
         'tel_prefer_normalized'         => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'tz'                            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'geo'                           => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+        'preferred_address'             => array(Zend_Filter_Input::ALLOW_EMPTY => true),
     // modlog fields
         'created_by'                    => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'creation_time'                 => array(Zend_Filter_Input::ALLOW_EMPTY => true),
index 8fc8090..a93a4e0 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Tine 2.0
  *
@@ -36,4 +37,24 @@ class Addressbook_Setup_Update_Release10 extends Setup_Update_Abstract
         $this->setTableVersion('addressbook', 22);
         $this->setApplicationVersion('Addressbook', '10.2');
     }
+
+    /**
+     * Adds a flag to toggle between private and business as preferred address
+     *
+     * @return void
+     */
+    public function update_2()
+    {
+        $declaration = new Setup_Backend_Schema_Field_Xml('
+            <field>
+                <name>preferred_address</name>
+                <type>integer</type>
+                <notnull>false</notnull>
+            </field>');
+
+        $this->_backend->addCol('addressbook', $declaration);
+
+        $this->setTableVersion('addressbook', 23);
+        $this->setApplicationVersion('Addressbook', '10.3');
+    }
 }
index 74fc0da..2efe194 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Addressbook</name>
-    <version>10.2</version>
+    <version>10.3</version>
     <order>10</order>
     <depends>
         <application>Admin</application>
@@ -11,7 +11,7 @@
             <name>addressbook</name>
             <engine>InnoDB</engine>
             <charset>utf8</charset>
-            <version>22</version>
+            <version>23</version>
             <declaration>
                 <field>
                     <name>id</name>
                     <notnull>true</notnull>
                 </field>
                 <field>
+                    <name>preferred_address</name>
+                    <type>integer</type>
+                    <notnull>false</notnull>
+                </field>
+                <field>
                     <name>adr_one_countryname</name>
                     <type>text</type>
                     <length>64</length>
index 22eb444..ff50a7d 100644 (file)
@@ -35,6 +35,9 @@ Tine.Addressbook.ContactEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog,
     multipleEdit: true,
     displayNotes: true,
 
+    preferredAddressBusinessCheckbox: null,
+    preferredAddressPrivateCheckbox: null,
+
     getFormItems: function () {
         if (Tine.Tinebase.configManager.get('mapPanel') && Tine.widgets.MapPanel) {
             this.mapPanel = new Tine.Addressbook.MapPanel({
@@ -54,6 +57,37 @@ Tine.Addressbook.ContactEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog,
             });
         }
 
+
+        this.preferredAddressBusinessCheckbox = new Ext.form.Checkbox({
+            checked: this.record.get('preferred_address') === "0",
+            hideLabel: false,
+            fieldLabel: i18n._('Preferred Address'),
+            listeners: {
+                'check': function(checkbox, value) {
+                    if (value) {
+                        this.preferredAddressPrivateCheckbox.setValue(false);
+                        this.record.set('preferred_address', 0);
+                    }
+                },
+                scope: this
+            }
+        });
+
+        this.preferredAddressPrivateCheckbox = new Ext.form.Checkbox({
+            checked: this.record.get('preferred_address') === "1",
+            hideLabel: false,
+            fieldLabel: i18n._('Preferred Address'),
+            listeners: {
+                'check': function(checkbox, value) {
+                    if (value) {
+                        this.preferredAddressBusinessCheckbox.setValue(false);
+                        this.record.set('preferred_address', 1);
+                    }
+                },
+                scope: this
+            }
+        });
+
         return {
             xtype: 'tabpanel',
             border: false,
@@ -278,7 +312,7 @@ Tine.Addressbook.ContactEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog,
                         region: 'south',
                         border: false,
                         deferredRender: false,
-                        height: 124,
+                        height: 160,
                         split: true,
                         activeTab: 0,
                         defaults: {
@@ -316,7 +350,7 @@ Tine.Addressbook.ContactEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog,
                                 fieldLabel: this.app.i18n._('Country'),
                                 name: 'adr_one_countryname',
                                 maxLength: 64
-                            }]]
+                            }], [this.preferredAddressBusinessCheckbox]]
                         }, {
                             title: this.app.i18n._('Private Address'),
                             xtype: 'columnform',
@@ -345,7 +379,7 @@ Tine.Addressbook.ContactEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog,
                                 fieldLabel: this.app.i18n._('Country'),
                                 name: 'adr_two_countryname',
                                 maxLength: 64
-                            }]]
+                            }], [this.preferredAddressPrivateCheckbox]]
                         }]
                     }]
                 }, {
index 6f97b8b..5e91896 100644 (file)
@@ -268,6 +268,24 @@ Tine.Addressbook.ContactGridPanel.countryRenderer = function(data) {
 };
 
 /**
+ * Column renderer adb preferred_address field
+ * @param value
+ * @return {*}
+ */
+Tine.Addressbook.ContactGridPanel.preferredAddressRenderer = function(value) {
+    var i18n = Tine.Tinebase.appMgr.get('Addressbook').i18n;
+
+    switch (value) {
+        case '0':
+            return i18n._('Business');
+        case '1':
+            return i18n._('Private');
+        default:
+            return i18n._('Not set');
+    }
+};
+
+/**
  * Statically constructs the columns used to represent a contact. Reused by ListMemberGridPanel + ListMemberRoleGridPanel
  */
 Tine.Addressbook.ContactGridPanel.getBaseColumns = function(i18n) {
@@ -303,6 +321,7 @@ Tine.Addressbook.ContactGridPanel.getBaseColumns = function(i18n) {
         { id: 'adr_two_region', header: i18n._('Region (private)'), dataIndex: 'adr_two_region' },
         { id: 'adr_two_postalcode', header: i18n._('Postalcode (private)'), dataIndex: 'adr_two_postalcode' },
         { id: 'adr_two_countryname', header: i18n._('Country (private)'), dataIndex: 'adr_two_countryname', renderer: Tine.Addressbook.ContactGridPanel.countryRenderer },
+        { id: 'preferred_address', header: i18n._('Preferred Address'), dataIndex: 'preferred_address', renderer: Tine.Addressbook.ContactGridPanel.preferredAddressRenderer },
         { id: 'email', header: i18n._('Email'), dataIndex: 'email', width: 150, hidden: false },
         { id: 'tel_work', header: i18n._('Phone'), dataIndex: 'tel_work', hidden: false },
         { id: 'tel_cell', header: i18n._('Mobile'), dataIndex: 'tel_cell', hidden: false },
index 41edaa0..1e9bac5 100644 (file)
@@ -48,6 +48,7 @@ Tine.Addressbook.Model.ContactArray = Tine.Tinebase.Model.genericFields.concat([
     {name: 'adr_two_countryname', label: 'Country (Private Address)', group: 'Private Address' }, //_('Country (Private Address)')
     {name: 'adr_two_lon', group: 'Private Address', omitDuplicateResolving: true},
     {name: 'adr_two_lat', group: 'Private Address', omitDuplicateResolving: true},
+    {name: 'preferred_address', group: 'Preferred Address', omitDuplicateResolving: true}, //_('Preferred Address')
     {name: 'tel_work', label: 'Phone', group: 'Company Communication' }, //_('Phone') _('Company Communication')
     {name: 'tel_cell', label: 'Mobile', group: 'Company Communication' }, //_('Mobile')
     {name: 'tel_fax', label: 'Fax', group: 'Company Communication' }, //_('Fax')