0009842: CRM relation fixes
authorAlexander Stintzing <a.stintzing@metaways.de>
Fri, 11 Apr 2014 12:16:25 +0000 (14:16 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 16 Apr 2014 12:00:40 +0000 (14:00 +0200)
Crm Lead has a constraints config which prevents from
adding more products, contacts and tasks to one lead.

Also the relation picker gridpanel does count the relations
residing in the other panels (products, contacts, tasks)

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

Change-Id: I4bc8bbd997801cbb7aef9dd0fa716781032d1206
Reviewed-on: http://gerrit.tine20.com/customers/520
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Crm/Model/Lead.php
tine20/Tinebase/js/widgets/relation/GenericPickerGridPanel.js

index 64e49e7..92c835a 100644 (file)
@@ -116,13 +116,13 @@ class Crm_Model_Lead extends Tinebase_Record_Abstract
      */
     protected static $_relatableConfig = array(
         array('relatedApp' => 'Addressbook', 'relatedModel' => 'Contact', 'config' => array(
-            array('type' => 'RESPONSIBLE', 'degree' => 'parent', 'text' => 'Responsible', 'max' => '1:0'), // _('Responsible')
-            array('type' => 'CUSTOMER', 'degree' => 'parent', 'text' => 'Customer', 'max' => '1:0'),  // _('Customer')
+            array('type' => 'RESPONSIBLE', 'degree' => 'parent', 'text' => 'Responsible', 'max' => '0:0'), // _('Responsible')
+            array('type' => 'CUSTOMER', 'degree' => 'parent', 'text' => 'Customer', 'max' => '0:0'),  // _('Customer')
             ),
             'default' => array('type' => 'CUSTOMER', 'own_degree' => 'parent')
         ),
         array('relatedApp' => 'Tasks', 'relatedModel' => 'Task', 'config' => array(
-            array('type' => 'TASK', 'degree' => 'sibling', 'text' => 'Task', 'max' => '1:0'), // _('Task')
+            array('type' => 'TASK', 'degree' => 'sibling', 'text' => 'Task', 'max' => '0:1'), // _('Task')
             ),
         )
     );
index a4bb4be..bf54dee 100644 (file)
@@ -219,7 +219,15 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
      * @param {Number} count
      */
     updateTitle: function(count) {
-        count = Ext.isNumber(count) ? count : this.store.getCount();
+        if (! Ext.isNumber(count)) {
+            count = 0;
+            this.store.each(function(record){
+                if (this.ignoreRelatedModels.indexOf(record.get('related_model')) == -1) {
+                    count++;
+                }
+            }, this);
+        }
+        
         this.setTitle(this.i18nTitle + ' (' + count + ')');
     },
     
@@ -1110,12 +1118,11 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
         var interceptor = ticketFn();
         var relations = record.get('relations');
         if (relations && relations.length > 0) {
-            this.updateTitle(relations.length);
             var relationRecords = [];
             
             Ext.each(relations, function(relation) {
-                if(this.ignoreRelatedModels) {
-                    if(relation.hasOwnProperty('related_model') && this.ignoreRelatedModels.indexOf(relation.related_model) == -1) {
+                if (this.ignoreRelatedModels) {
+                    if (relation.hasOwnProperty('related_model') && this.ignoreRelatedModels.indexOf(relation.related_model) == -1) {
                         relationRecords.push(new Tine.Tinebase.Model.Relation(relation, relation.id));
                     }
                 } else {
@@ -1126,7 +1133,7 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
             
             // sort by creation time
             this.store.sort('creation_time', 'DESC');
-            
+            this.updateTitle();
         } else {
             this.updateTitle(0);
         }