0011286: allow contacts without org/family name
authorCornelius Weiß <mail@corneliusweiss.de>
Tue, 1 Sep 2015 07:06:33 +0000 (09:06 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 29 Sep 2015 12:16:44 +0000 (14:16 +0200)
https://forge.tine20.org/view.php?id=11286

Change-Id: I14088d435298e0c30cf1cdbdb6088f8851e96faa
Reviewed-on: http://gerrit.tine20.com/customers/2223
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/JsonTest.php
tine20/Addressbook/Model/Contact.php
tine20/Addressbook/css/Addressbook.css
tine20/Addressbook/js/ContactEditDialog.js
tine20/Addressbook/js/ContactGrid.js
tine20/Addressbook/js/SearchCombo.js

index aaf4cb1..383350b 100644 (file)
@@ -387,14 +387,12 @@ class Addressbook_JsonTest extends TestCase
         // check invalid data
         
         $changes = array(
-            array('name' => 'n_family', 'value' => ''),
-            array('name' => 'n_given',  'value' => ''),
-            array('name' => 'org_name', 'value' => '')
+            array('name' => 'type', 'value' => 'Z'),
         );
         $result = $json->updateMultipleRecords('Addressbook', 'Contact', $changes, $filter);
-        
-        $this->assertEquals($result['failcount'], 3, 'failcount does not show the correct number');
-        $this->assertEquals($result['totalcount'], 0, 'totalcount does not show the correct number');
+
+        $this->assertEquals(3, $result['failcount'], 'failcount does not show the correct number');
+        $this->assertEquals(0, $result['totalcount'], 'totalcount does not show the correct number');
     }
     
     /**
index b6371cf..eb55010 100644 (file)
@@ -175,8 +175,8 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
         'url'                   => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'url_home'              => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'n_family'              => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'n_fileas'              => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
-        'n_fn'                  => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
+        'n_fileas'              => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+        'n_fn'                  => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'n_given'               => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'n_middle'              => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'n_prefix'              => array(Zend_Filter_Input::ALLOW_EMPTY => true),
@@ -341,49 +341,6 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
     }
 
     /**
-     * additional validation
-     *
-     * @param $_throwExceptionOnInvalidData
-     * @return bool
-     * @throws Tinebase_Exception_Record_Validation
-     * @see Tinebase_Record_Abstract::isValid()
-     */
-    function isValid($_throwExceptionOnInvalidData = false) {
-        
-        if ((!$this->__get('org_name')) && (!$this->__get('n_family'))) {
-            array_push($this->_validationErrors, array('id' => 'org_name', 'msg' => 'either "org_name" or "n_family" must be given!'));
-            array_push($this->_validationErrors, array('id' => 'n_family', 'msg' => 'either "org_name" or "n_family" must be given!'));
-            
-            $valid = false;
-        } else {
-            $valid = true;
-        }
-        
-        $parentException = false;
-        $parentValid = false;
-        
-        try {
-            $parentValid = parent::isValid($_throwExceptionOnInvalidData);
-        } catch (Tinebase_Exception_Record_Validation $e) {
-            $parentException = $e;
-        }
-        
-        if ($_throwExceptionOnInvalidData && (!$valid || !$parentValid)) {
-            
-            if(!$valid) {
-                $message = 'either "org_name" or "n_family" must be given!';
-            }
-            
-            if($parentException) $message .= ', ' . $parentException->getMessage();
-            $e = new Tinebase_Exception_Record_Validation($message);
-            if(!$valid) Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ":\n" . print_r($this->_validationErrors,true). $e);
-            throw $e;
-        }
-        
-        return $parentValid && $valid;
-    }    
-
-    /**
      * fills a contact from json data
      *
      * @param array $_data record data
index 6eab058..123e370 100644 (file)
@@ -37,4 +37,9 @@
     background-image:url(../../images/oxygen/16x16/actions/user.png) !important;
     background-repeat: no-repeat;
     background-position: 2px 2px;
+}
+
+.renderer_displayNameRenderer_noName {
+    font-style: italic;
+    /*color: #808080;*/
 }
\ No newline at end of file
index 6dd9f27..3e81e14 100644 (file)
@@ -419,51 +419,6 @@ Tine.Addressbook.ContactEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog,
     },
 
     /**
-     * checks if form data is valid
-     *
-     * @return {Boolean}
-     */
-    isValid: function () {
-        var form = this.getForm();
-        var isValid = true;
-
-        // you need to fill in one of: n_given n_family org_name
-        // @todo required fields should depend on salutation ('company' -> org_name, etc.)
-        //       and not required fields should be disabled (n_given, n_family, etc.)
-        if (form.findField('n_family').getValue() === '' && form.findField('org_name').getValue() === '') {
-            var invalidString = String.format(this.app.i18n._('Either {0} or {1} must be given'), this.app.i18n._('Last Name'), this.app.i18n._('Company'));
-
-            form.findField('n_family').markInvalid(invalidString);
-            form.findField('org_name').markInvalid(invalidString);
-
-            isValid = false;
-        }
-        else {
-            form.findField('n_family').clearInvalid();
-            form.findField('org_name').clearInvalid();
-        }
-
-        return isValid && Tine.Addressbook.ContactEditDialog.superclass.isValid.apply(this, arguments);
-    },
-
-    /**
-     * overwrites the isValid method on multipleEdit
-     */
-    isMultipleValid: function() {
-        var isValid = true;
-        if (((this.getForm().findField('n_family').getValue() === '') && (this.getForm().findField('n_family').edited))
-            && ((this.getForm().findField('org_name').getValue() === '') && (this.getForm().findField('org_name').edited))) {
-            var invalidString = String.format(this.app.i18n._('Either {0} or {1} must be given'), this.app.i18n._('Last Name'), this.app.i18n._('Company'));
-            this.getForm().findField('n_family').markInvalid(invalidString);
-            this.getForm().findField('org_name').markInvalid(invalidString);
-
-            isValid = false;
-        }
-
-        return isValid;
-    },
-
-    /**
      * export pdf handler
      */
     onExportContact: function () {
index 20612de..935141e 100644 (file)
@@ -112,8 +112,8 @@ Tine.Addressbook.ContactGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
             { id: 'n_middle', header: this.app.i18n._('Middle Name'), dataIndex: 'n_middle', width: 80 },
             { id: 'n_family', header: this.app.i18n._('Last Name'), dataIndex: 'n_family' },
             { id: 'n_given', header: this.app.i18n._('First Name'), dataIndex: 'n_given', width: 80 },
-            { id: 'n_fn', header: this.app.i18n._('Full Name'), dataIndex: 'n_fn' },
-            { id: 'n_fileas', header: this.app.i18n._('Display Name'), dataIndex: 'n_fileas', hidden: false},
+            { id: 'n_fn', header: this.app.i18n._('Full Name'), dataIndex: 'n_fn', renderer: this.displayNameRenderer },
+            { id: 'n_fileas', header: this.app.i18n._('Display Name'), dataIndex: 'n_fileas', hidden: false, renderer: this.displayNameRenderer},
             { id: 'org_name', header: this.app.i18n._('Company'), dataIndex: 'org_name', width: 120, hidden: false },
             { id: 'org_unit', header: this.app.i18n._('Unit'), dataIndex: 'org_unit'  },
             { id: 'title', header: this.app.i18n._('Job Title'), dataIndex: 'title' },
@@ -305,7 +305,12 @@ Tine.Addressbook.ContactGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
         
         return '<div ext:qtip="' + qtipText + '" style="background-position:0px;" class="' + cssClass + '">&#160</div>';
     },
-    
+
+    displayNameRenderer: function(data) {
+        var i18n = Tine.Tinebase.appMgr.get('Addressbook').i18n;
+        return data ? data : ('<div class="renderer_displayNameRenderer_noName">' + i18n._('No name') + '</div>');
+    },
+
     /**
      * returns details panel
      * 
index 5f07f0b..0690428 100644 (file)
@@ -104,7 +104,7 @@ Tine.Addressbook.SearchCombo = Ext.extend(Tine.Tinebase.widgets.form.RecordPicke
                     '<table cellspacing="0" cellpadding="2" border="0" style="font-size: 11px;" width="100%">',
                         '<tr>',
                             '<td style="min-width: 20px;">{[this.getIcon(values)]}</td>',
-                            '<td width="30%"><b>{[this.encode(values.n_fileas)]}</b><br/>{[this.encode(values.org_name)]}</td>',
+                            '<td width="30%"><b>{[this.encode(values.n_fileas, "fileas")]}</b><br/>{[this.encode(values.org_name)]}</td>',
                             '<td width="25%">{[this.encode(values.adr_one_street)]}<br/>',
                                 '{[this.encode(values.adr_one_postalcode)]} {[this.encode(values.adr_one_locality)]}</td>',
                             '<td width="25%">{[this.encode(values.tel_work)]}<br/>{[this.encode(values.tel_cell)]}</td>',
@@ -118,11 +118,13 @@ Tine.Addressbook.SearchCombo = Ext.extend(Tine.Tinebase.widgets.form.RecordPicke
                     getIcon: function(contactData) {
                         return Tine.Addressbook.ContactGridPanel.prototype.contactTypeRenderer.call(this, null, null, contactData);
                     },
-                    encode: function(value) {
-                         if (value) {
+                    encode: function(value, field) {
+                        if (value) {
                             return Ext.util.Format.htmlEncode(value);
                         } else {
-                            return '';
+                            return field == 'fileas' ?
+                                Tine.Addressbook.ContactGridPanel.prototype.displayNameRenderer(value) :
+                                '';
                         }
                     }
                 }