0010042: Show Organizer in Task-Grid of a Lead
authorAlexander Stintzing <a.stintzing@metaways.de>
Tue, 8 Jul 2014 14:08:25 +0000 (16:08 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 10 Sep 2014 11:09:24 +0000 (13:09 +0200)
The organizer should be shown in the task gridpanel of the lead-edit-dialog

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

Change-Id: I7e61af0728c2b2b5ef7e9432aa630d4de16b9ce3
Reviewed-on: http://gerrit.tine20.com/customers/837
Tested-by: Jenkins CI (http://ci.tine20.com/)
Tested-by: sstamer <s.stamer@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Crm/JsonTest.php
tine20/Crm/Frontend/Json.php
tine20/Crm/js/Task.js

index a4a0da5..773e32e 100644 (file)
@@ -164,6 +164,14 @@ class Crm_JsonTest extends Crm_AbstractTest
         $getLead = $this->_instance->getLead($savedLead['id']);
         $searchLeads = $this->_instance->searchLeads($this->_getLeadFilter(), '');
         
+        // test manual resolving of organizer in related_record and set it back for following tests
+        for ($i = 0; $i < count($getLead['relations']); $i++) {
+            if (isset($getLead['relations'][$i]['related_record']['organizer'])) {
+                $this->assertTrue(is_array($getLead['relations'][$i]['related_record']['organizer']));
+                $getLead['relations'][$i]['related_record']['organizer'] = $getLead['relations'][$i]['related_record']['organizer']['accountId'];
+            }
+        }
+        
         // assertions
         $this->assertEquals($getLead, $savedLead);
         $this->assertEquals($getLead['notes'][0]['note'], 'phpunit test note');
index 91c8740..df31532 100644 (file)
@@ -68,7 +68,28 @@ class Crm_Frontend_Json extends Tinebase_Frontend_Json_Abstract
      */
     public function getLead($id)
     {
-        return $this->_get($id, $this->_controller);
+        $organizerIds = array();
+        $lead = $this->_get($id, $this->_controller);
+        
+        foreach($lead['relations'] as $relation) {
+            if ($relation['related_model'] == 'Tasks_Model_Task') {
+                $organizerIds[] = $relation['related_record']['organizer'];
+            }
+        }
+        
+        $be = new Tinebase_User_Sql();
+        $organizers = $be->getMultiple($organizerIds);
+
+        for ($i = 0; $i < count($lead['relations']); $i++) {
+            if ($lead['relations'][$i]['related_model'] == 'Tasks_Model_Task') {
+                $organizer = $organizers->getById($lead['relations'][$i]['related_record']['organizer']);
+                if ($organizer) {
+                    $lead['relations'][$i]['related_record']['organizer'] = $organizer->toArray();
+                }
+            }
+        }
+        
+        return $lead;
     }
 
     /**
index 6df53cd..39a2785 100644 (file)
@@ -70,7 +70,7 @@ Tine.Crm.Task.GridPanel = Ext.extend(Ext.ux.grid.QuickaddGridPanel, {
 
     /**
      * record class
-     * @cfg {Tine.Addressbook.Model.Contact} recordClass
+     * @cfg {Tine.Tasks.Model.Task} recordClass
      */
     recordClass: null,
     
@@ -85,7 +85,7 @@ Tine.Crm.Task.GridPanel = Ext.extend(Ext.ux.grid.QuickaddGridPanel, {
         this.recordClass = Tine.Tasks.Model.Task;
         
         this.storeFields = Tine.Tasks.Model.TaskArray;
-        this.storeFields.push({name: 'relation'});   // the relation object           
+        this.storeFields.push({name: 'relation'});   // the relation object
         this.storeFields.push({name: 'relation_type'});
         
         // create delegates
@@ -118,6 +118,8 @@ Tine.Crm.Task.GridPanel = Ext.extend(Ext.ux.grid.QuickaddGridPanel, {
             }
         });
         
+        this.on('afteredit', this.onAfterEdit);
+        
         this.on('newentry', function(taskData){
             var newTask = taskData;
             newTask.relation_type = 'task';
@@ -127,8 +129,20 @@ Tine.Crm.Task.GridPanel = Ext.extend(Ext.ux.grid.QuickaddGridPanel, {
             while (this.record.data.relations.length > i && this.record.data.relations[i].type != 'responsible') {
                 i++;
             }
-            if (this.record.data.relations[i] && this.record.data.relations[i].type == 'responsible' && this.record.data.relations[i].related_record.account_id != '') {
-                newTask.organizer = this.record.data.relations[i].related_record.account_id;
+            if (! newTask.organizer) {
+                if (this.record.data.relations[i] && this.record.data.relations[i].type == 'responsible' && this.record.data.relations[i].related_record.account_id != '') {
+                    newTask.organizer = Tine.Tinebase.registry.get('currentAccount');
+                }
+            } else {
+                var contactRecord = this.organizerQuickAdd.selectedRecord;
+                
+                if (contactRecord) {
+                    var organizer = {
+                        accountId: contactRecord.get('account_id'),
+                        accountDisplayName: contactRecord.get('n_fileas')
+                    };
+                    newTask.organizer = organizer;
+                }
             }
             
             // add new task to store
@@ -154,10 +168,47 @@ Tine.Crm.Task.GridPanel = Ext.extend(Ext.ux.grid.QuickaddGridPanel, {
     },
     
     /**
+     * is called on after edit to set related records
+     * @param {} o
+     */
+    onAfterEdit: function(o) {
+        if (o.field == 'organizer') {
+            var contactRecord = this.organizerEditor.selectedRecord;
+            
+            if (contactRecord) {
+                var organizer = {
+                    accountId: contactRecord.get('account_id'),
+                    accountDisplayName: contactRecord.get('n_fileas')
+                };
+                
+                o.record.set('organizer', organizer);
+            } else {
+                if (o.originalValue.accountId == o.value) {
+                    o.record.set('organizer', o.originalValue);
+                }
+            }
+        }
+    },
+    
+    
+    /**
      * @return Ext.grid.ColumnModel
      * @private
      */
     getColumnModel: function() {
+        
+        this.organizerQuickAdd = Tine.widgets.form.RecordPickerManager.get('Addressbook', 'Contact', {
+            userOnly: true,
+            useAccountRecord: true,
+            scope: this
+        });
+        
+        this.organizerEditor = Tine.widgets.form.RecordPickerManager.get('Addressbook', 'Contact', {
+            userOnly: true,
+            useAccountRecord: true,
+            scope: this
+        });
+        
         return new Ext.grid.ColumnModel({
             defaults: {
                 sortable: true
@@ -229,6 +280,15 @@ Tine.Crm.Task.GridPanel = Ext.extend(Ext.ux.grid.QuickaddGridPanel, {
                         keyFieldName: 'taskStatus',
                         value: 'NEEDS-ACTION'
                     })
+                }, {
+                    id: 'organizer',
+                    header: this.app.i18n._("Organizer"),
+                    width: 45,
+                    dataIndex: 'organizer',
+                    hidden: true,
+                    renderer: Tine.Tinebase.common.usernameRenderer,
+                    quickaddField: this.organizerQuickAdd,
+                    editor: this.organizerEditor
                 }
             ]}
         );