0011108: show contact/user email in user grids
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 30 Mar 2016 11:27:58 +0000 (13:27 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 30 Mar 2016 13:07:53 +0000 (15:07 +0200)
* show email address in attendee and grants grids
* show email address in contact search combo
* adds getTitle() to contact model
* adds feature switch

https://forge.tine20.org/view.php?id=11108

Change-Id: Ibf5ff24b7c73bc20c2538fbe152d29dccf9c574c
Reviewed-on: http://gerrit.tine20.com/customers/2976
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Addressbook/js/Model.js
tine20/Addressbook/js/SearchCombo.js
tine20/Calendar/js/AttendeeGridPanel.js
tine20/Tinebase/Config.php
tine20/Tinebase/Model/User.php
tine20/Tinebase/js/common.js
tine20/Tinebase/js/widgets/account/PickerGridPanel.js

index 3fcc0fd..8c12dfb 100644 (file)
@@ -110,14 +110,32 @@ Tine.Addressbook.Model.Contact = Tine.Tinebase.data.Record.create(Tine.Addressbo
     },
     
     /**
-     * returns true prefered email if available
+     * returns true preferred email if available
      * @return {String}
+     *
+     * TODO fix typo (prefered -> preferred)
      */
-    getPreferedEmail: function(prefered) {
-        var prefered = prefered || 'email',
-            other = prefered == 'email' ? 'email_home' : 'email';
+    getPreferedEmail: function(preferred) {
+        var preferred = preferred || 'email',
+            other = preferred == 'email' ? 'email_home' : 'email';
             
-        return (this.get(prefered) || this.get(other));
+        return (this.get(preferred) || this.get(other));
+    },
+
+    getTitle: function() {
+        var result = this.get('n_fn');
+
+        var tinebaseApp = new Tine.Tinebase.Application({
+            appName: 'Tinebase'
+        });
+        if (tinebaseApp.featureEnabled('featureShowAccountEmail')) {
+            var email = this.getPreferedEmail();
+            if (email !== '') {
+                result += ' (' + email + ')';
+            }
+        }
+
+        return result;
     }
 });
 
@@ -261,14 +279,14 @@ Tine.Addressbook.Model.EmailAddress = Tine.Tinebase.data.Record.create([
     containersName: 'Addressbooks',
     copyOmitFields: ['group_id'],
 
-    getPreferedEmail: function(prefered) {
+    getPreferedEmail: function(preferred) {
         var emails = this.get("emails");
         if (!this.get("email")) {
             return  this.get("emails");
         } else {
-            var prefered = prefered || 'email',
-            other = prefered == 'email' ? 'email_home' : 'email';
-            return (this.get(prefered) || this.get(other));
+            var preferred = preferred || 'email',
+            other = preferred == 'email' ? 'email_home' : 'email';
+            return (this.get(preferred) || this.get(other));
         }
     }
 });
index ba3f63a..58c3c9e 100644 (file)
@@ -136,10 +136,21 @@ Tine.Addressbook.SearchCombo = Ext.extend(Tine.Tinebase.widgets.form.RecordPicke
     setValue: function (value) {
         if (this.useAccountRecord) {
             if (value) {
-                if(value.accountId) {
+                var tinebaseApp = new Tine.Tinebase.Application({
+                    appName: 'Tinebase'
+                });
+                var showMail = tinebaseApp.featureEnabled('featureShowAccountEmail');
+
+                if (value.accountId) {
                     // account object
                     this.accountId = value.accountId;
                     value = value.accountDisplayName;
+                    if (showContactMail) {
+                        var email = value.accountEmailAddress;
+                        if (email !== '') {
+                            value += ' (' + email + ')';
+                        }
+                    }
                 } else if (typeof(value.get) == 'function') {
                     // account record
                     this.accountId = value.get('id');
index 1ae6ca0..242f693 100644 (file)
@@ -553,24 +553,56 @@ Tine.Calendar.AttendeeGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
             return this.app.i18n._(this.addNewAttendeeText);
         }
     },
-    
+
+    /**
+     * render attender user name
+     *
+     * @param name
+     * @returns {*}
+     */
     renderAttenderUserName: function(name) {
         name = name || "";
+        var result = "",
+            email = "";
+
         if (typeof name.get == 'function' && name.get('n_fileas')) {
-            return Ext.util.Format.htmlEncode(name.get('n_fileas'));
-        }
-        if (name.n_fileas) {
-            return Ext.util.Format.htmlEncode(name.n_fileas);
+            result = name.get('n_fileas');
+        } else if (name.n_fileas) {
+            result = name.n_fileas;
+        } else if (name.accountDisplayName) {
+            result = name.accountDisplayName;
+        } else if (Ext.isString(name) && ! name.match('^[0-9a-f-]{40,}$') && ! parseInt(name, 10)) {
+            // how to detect hash/string ids
+            result = name;
         }
-        if (name.accountDisplayName) {
-            return Ext.util.Format.htmlEncode(name.accountDisplayName);
+
+        // add email address if available
+        // need to create a "dummy" app to call featureEnabled()
+        // TODO: should be improved
+        var tinebaseApp = new Tine.Tinebase.Application({
+            appName: 'Tinebase'
+        });
+        if (tinebaseApp.featureEnabled('featureShowAccountEmail')) {
+            if (typeof name.getPreferedEmail == 'function') {
+                email = name.getPreferedEmail();
+            } else if (name.email) {
+                email = name.email;
+            } else if (name.accountEmailAddress) {
+                email = name.accountEmailAddress;
+            }
+            if (email !== '') {
+                result += ' (' + email + ')';
+            }
         }
-        // how to detect hash/string ids
-        if (Ext.isString(name) && ! name.match('^[0-9a-f-]{40,}$') && ! parseInt(name, 10)) {
-            return Ext.util.Format.htmlEncode(name);
+
+        if (result === '') {
+            result = Tine.Tinebase.appMgr.get('Calendar').i18n._('No Information')
+        } else {
+            result = Ext.util.Format.htmlEncode(result)
         }
+
         // NOTE: this fn gets also called from other scopes
-        return Tine.Tinebase.appMgr.get('Calendar').i18n._('No Information');
+        return result;
     },
     
     renderAttenderGroupmemberName: function(name) {
index 258d140..bb5bce0 100644 (file)
@@ -91,6 +91,13 @@ class Tinebase_Config extends Tinebase_Config_Abstract
     const FEATURE_SHOW_ADVANCED_SEARCH = 'featureShowAdvancedSearch';
 
     /**
+     * FEATURE_SHOW_ACCOUNT_EMAIL
+     *
+     * @var string
+     */
+    const FEATURE_SHOW_ACCOUNT_EMAIL = 'featureShowAccountEmail';
+
+    /**
      * user defined page title postfix for browser page title
      * 
      * @var string
@@ -461,9 +468,15 @@ class Tinebase_Config extends Tinebase_Config_Abstract
                     'description'   => 'Show toggle button to switch on or off the advanced search for the quickfilter',
                     //_('Show toggle button to switch on or off the advanced search for the quickfilter')
                 ),
+                self::FEATURE_SHOW_ACCOUNT_EMAIL => array(
+                    'label'         => 'Show Account Email Address', //_('Show Account Email Address')
+                    'description'   => 'Show email address in account picker and attendee grids',
+                    //_('Show email address in account picker and attendee grids')
+                ),
             ),
             'default'               => array(
                 self::FEATURE_SHOW_ADVANCED_SEARCH => false,
+                self::FEATURE_SHOW_ACCOUNT_EMAIL => false,
             ),
         ),
         self::CRONUSERID => array(
index 9d844a4..2407cd5 100644 (file)
@@ -117,6 +117,7 @@ class Tinebase_Model_User extends Tinebase_Record_Abstract
         'accountDisplayName'    => array('presence' => 'required'),
         'accountLastName'       => array('presence' => 'required'),
         'accountFirstName'      => array('allowEmpty' => true),
+        'accountEmailAddress'   => array('allowEmpty' => true),
         'accountFullName'       => array('presence' => 'required'),
         'contact_id'            => array('allowEmpty' => true),
         // @todo do we need this information in this model?
index de3389e..9468fd0 100644 (file)
@@ -518,11 +518,22 @@ Tine.Tinebase.common = {
         if (! accountObject) {
             return '';
         }
-        var type, iconCls, displayName;
+        var type, iconCls, displayName, email;
         
         if (accountObject.accountDisplayName) {
             type = 'user';
             displayName = accountObject.accountDisplayName;
+
+            // need to create a "dummy" app to call featureEnabled()
+            // TODO: should be improved
+            var tinebaseApp = new Tine.Tinebase.Application({
+                appName: 'Tinebase'
+            });
+            if (tinebaseApp.featureEnabled('featureShowAccountEmail') && accountObject.accountEmailAddress) {
+                // add email address if available
+                email = accountObject.accountEmailAddress;
+                displayName += ' (' + email + ')';
+            }
         } else if (accountObject.name) {
             type = 'group';
             displayName = accountObject.name;
index a70f9a4..638877c 100644 (file)
@@ -263,7 +263,6 @@ Tine.widgets.account.PickerGridPanel = Ext.extend(Tine.widgets.grid.PickerGridPa
                 sortable: true
             },
             columns:  [
-                //{id: 'type', header: '',        dataIndex: this.recordPrefix + 'type', width: 35, renderer: Tine.Tinebase.common.accountTypeRenderer},
                 {id: 'name', header: _('Name'), dataIndex: this.recordPrefix + 'name', renderer: Tine.Tinebase.common.accountRenderer}
             ].concat(this.configColumns)
         });