Merge branch 'pu/2013.03/fileattach' into pu/2013.03/modelconfig-hr
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 4 Jul 2013 08:36:59 +0000 (10:36 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 4 Jul 2013 08:36:59 +0000 (10:36 +0200)
Conflicts:
tine20/Addressbook/js/Model.js
tine20/Crm/js/Model.js
tine20/Tinebase/Convert/Json.php
tine20/Tinebase/js/widgets/dialog/EditDialog.js

1  2 
tine20/Addressbook/js/Model.js
tine20/Crm/js/LeadEditDialog.js
tine20/Crm/js/Model.js
tine20/Tinebase/Controller/Record/Abstract.php
tine20/Tinebase/Convert/Json.php
tine20/Tinebase/Frontend/Json/Abstract.php
tine20/Tinebase/Tinebase.jsb2
tine20/Tinebase/js/Models.js
tine20/Tinebase/js/widgets/dialog/EditDialog.js

@@@ -73,7 -73,8 +73,8 @@@ Tine.Addressbook.Model.ContactArray = T
      {name: 'tags'},
      {name: 'notes', omitDuplicateResolving: true},
      {name: 'relations', omitDuplicateResolving: true},
 -    {name: 'customfields', isMetaField: true},
 +    {name: 'customfields', omitDuplicateResolving: true},
+     {name: 'attachments', omitDuplicateResolving: true},
      {name: 'type', omitDuplicateResolving: true}
  ]);
  
Simple merge
@@@ -40,7 -40,8 +40,8 @@@ Tine.Crm.Model.Lead = Tine.Tinebase.dat
          {name: 'products'},
          {name: 'tags'},
          {name: 'notes'},
-         {name: 'customfields', omitDuplicateResolving: true}
 -        {name: 'attachments'},
 -        {name: 'customfields', isMetaField: true}
++        {name: 'customfields', omitDuplicateResolving: true},
++        {name: 'attachments'}
      ]), {
      appName: 'Crm',
      modelName: 'Lead',
@@@ -45,17 -45,10 +45,17 @@@ class Tinebase_Convert_Json implements 
          $records = new Tinebase_Record_RecordSet(get_class($_record), array($_record));
          
          Tinebase_Frontend_Json_Abstract::resolveContainerTagsUsers($records);
-         $this->_resolveMultipleIdFields($records);
 +        
 +        // use modern record resolving, if the model was configured using Tinebase_ModelConfiguration
 +        // at first, resolve all single record fields
 +        $this->_resolveSingleRecordFields($records);
 +        // next step, resolve all multiple records fields
 +        $this->_resolveMultipleRecordFields($records);
 +        
 +        // resolve the traditional way, if model hasn't been configured with Tinebase_ModelConfiguration
+         self::resolveMultipleIdFields($records);
          
          $_record = $records->getFirstRecord();
 -        
          $_record->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
          $_record->bypassFilters = true;
          
      }
  
      /**
 -     * resolves multiple records
++<<<<<<< HEAD
 +     * resolves single record fields (Tinebase_ModelConfiguration._recordsFields)
       * 
 -     * @param Tinebase_Record_RecordSet $records the records
 +     * @param Tinebase_Record_RecordSet $_records the records
 +     */
 +    protected function _resolveSingleRecordFields(Tinebase_Record_RecordSet $_records)
 +    {
 +        $ownRecordClass = $_records->getRecordClassName();
 +        
 +        if (! $cfg = $ownRecordClass::getConfiguration()) {
 +            return;
 +        }
 +        $resolveFields = $cfg->recordFields;
 +        if ($resolveFields && is_array($resolveFields)) {
 +            // don't search twice if the same recordClass gets resolved on multiple fields
 +            foreach ($resolveFields as $fieldKey => $fieldConfig) {
 +                $resolveRecords[$fieldConfig['config']['recordClassName']][] = $fieldKey;
 +            }
 +            
 +            foreach ($resolveRecords as $foreignRecordClassName => $fields) {
 +                $foreignIds = array();
 +                $fields = (array) $fields;
 +                
 +                foreach($fields as $field) {
 +                    $foreignIds = array_unique(array_merge($foreignIds, $_records->{$field}));
 +                }
 +                
 +                if (! Tinebase_Core::getUser()->hasRight(substr($foreignRecordClassName, 0, strpos($foreignRecordClassName, "_")), Tinebase_Acl_Rights_Abstract::RUN)) {
 +                    continue;
 +                }
 +                
 +                $cfg = $resolveFields[$fields[0]];
 +                
 +                if ($cfg['type'] == 'user') {
 +                    $foreignRecords = Tinebase_User::getInstance()->getUsers();
 +                } elseif ($cfg['type'] == 'container') {
 +                    $foreignRecords = new Tinebase_Record_RecordSet('Tinebase_Model_Container');
 +                    $foreignRecords->addRecord(Tinebase_Container::getInstance()->get($_id));
 +                // TODO: resolve recursive records of records better in controller
 +                // TODO: resolve containers
 +                } else {
 +                    $controller = array_key_exists('controllerClassName', $cfg['config']) ? $cfg['config']['controllerClassName']::getInstance() : Tinebase_Core::getApplicationInstance($foreignRecordClassName);
 +                    $foreignRecords = $controller->getMultiple($foreignIds);
 +                }
 +                
 +                $foreignRecords->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
 +                $foreignRecords->convertDates = true;
 +                Tinebase_Frontend_Json_Abstract::resolveContainerTagsUsers($foreignRecords);
 +                $fr = $foreignRecords->getFirstRecord();
 +                if ($fr && $fr->has('notes')) {
 +                    Tinebase_Notes::getInstance()->getMultipleNotesOfRecords($foreignRecords);
 +                }
 +                
 +                if ($foreignRecords->count()) {
 +                    foreach ($_records as $record) {
 +                        foreach ($fields as $field) {
 +                            $idx = $foreignRecords->getIndexById($record->{$field});
 +                            if (isset($idx) && $idx !== FALSE) {
 +                                $record->{$field} = $foreignRecords[$idx];
 +                            }
 +                        }
 +                    }
 +                }
 +            }
 +        }
 +    }
 +    
 +    /**
 +     * resolves multiple records (fallback)
 +     * 
 +     * @deprecated use Tinebase_ModelConfiguration to configure your models, so this won't be used anymore 
 +     * @param Tinebase_Record_RecordSet $_records the records
+      * @param array $resolveFields
       */
-     protected function _resolveMultipleIdFields(Tinebase_Record_RecordSet $_records)
+     public static function resolveMultipleIdFields($records, $resolveFields = NULL)
      {
-         $ownRecordClass = $_records->getRecordClassName();
-         if (! $resolveFields = $ownRecordClass::getResolveForeignIdFields()) {
+         if (! $records instanceof Tinebase_Record_RecordSet) {
              return;
          }
          
          if (count($_records) == 0) {
              return array();
          }
 -
 +        
          Tinebase_Frontend_Json_Abstract::resolveContainerTagsUsers($_records);
--
-         $this->_resolveMultipleIdFields($_records);
++        
+         self::resolveMultipleIdFields($_records);
 -
 +        $this->_resolveSingleRecordFields($_records);
 +        $this->_resolveMultipleRecordFields($_records);
++        
          $_records->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
          $_records->convertDates = true;
  
Simple merge
Simple merge
@@@ -826,20 -808,19 +848,30 @@@ Tine.widgets.dialog.EditDialog = Ext.ex
       * creates the relations panel, if relations are defined
       */
      initRelationsPanel: function() {
 -        if (! this.relationsPanel && ! this.hideRelationsPanel && this.recordClass && this.recordClass.hasField('relations')) {
 -            this.relationsPanel = new Tine.widgets.relation.GenericPickerGridPanel({ anchor: '100% 100%', editDialog: this }); 
 -            this.items.items.push(this.relationsPanel);
 +        if (! this.hideRelationsPanel && this.recordClass && this.recordClass.hasField('relations')) {
 +            // init relations panel before onRecordLoad
 +            if (! this.relationsPanel) {
 +                this.relationsPanel = new Tine.widgets.relation.GenericPickerGridPanel({ anchor: '100% 100%', editDialog: this });
 +            }
 +            // interrupt process flow until dialog is rendered
 +            if (! this.rendered) {
 +                this.initRelationsPanel.defer(250, this);
 +                return;
 +            }
 +            // add relations panel if this is rendered
 +            if (this.items.items[0]) {
 +                this.items.items[0].add(this.relationsPanel);
 +            }
          }
+     },
+     
+     /**
+      * creates attachments panel
+      */
+     initAttachmentsPanel: function() {
+         if (! this.attachmentsPanel && ! this.hideAttachmentsPanel && this.recordClass && this.recordClass.hasField('attachments')) {
+             this.attachmentsPanel = new Tine.widgets.dialog.AttachmentsGridPanel({ anchor: '100% 100%', editDialog: this }); 
+             this.items.items.push(this.attachmentsPanel);
+         }
      }
  });