Merge branch '2013.10' into 2014.11
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 11 Feb 2016 09:33:09 +0000 (10:33 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 11 Feb 2016 09:33:09 +0000 (10:33 +0100)
1  2 
tine20/Calendar/Frontend/Json.php
tine20/Calendar/js/Model.js
tine20/Filemanager/js/NodeGridPanel.js

@@@ -111,159 -111,17 +111,160 @@@ class Calendar_Frontend_Json extends Ti
          try {
              $defaultCalendarArray = Tinebase_Container::getInstance()->getContainerById($defaultCalendarId)->toArray();
              $defaultCalendarArray['account_grants'] = Tinebase_Container::getInstance()->getGrantsOfAccount(Tinebase_Core::getUser(), $defaultCalendarId)->toArray();
+             $defaultCalendarArray['ownerContact'] = Addressbook_Controller_Contact::getInstance()->getContactByUserId($defaultCalendarArray['owner_id'])->toArray();
          } catch (Exception $e) {
              // remove default cal pref
              Tinebase_Core::getPreference('Calendar')->deleteUserPref(Calendar_Preference::DEFAULTCALENDAR);
              $defaultCalendarArray = array();
          }
          
 -        return array(
 -            // registry setting is called defaultContainer to be compatible to the other apps
 -            'defaultContainer' => $defaultCalendarArray
 +        $importDefinitions = $this->_getImportDefinitions();
 +        
 +        $registryData = array(
 +            'defaultContainer'          => $defaultCalendarArray,
 +            'defaultImportDefinition'   => $importDefinitions['default'],
 +            'importDefinitions'         => $importDefinitions
 +        );
 +        
 +        return $registryData;
 +    }
 +    
 +    /**
 +     * get default addressbook
 +     * 
 +     * @return array
 +     */
 +    public function getDefaultCalendar() 
 +   {
 +        $defaultCalendar = Calendar_Controller_Event::getInstance()->getDefaultCalendar();
 +        $defaultCalendarArray = $defaultCalendar->toArray();
 +        $defaultCalendarArray['account_grants'] = Tinebase_Container::getInstance()->getGrantsOfAccount(Tinebase_Core::getUser(), $defaultCalendar->getId())->toArray();
 +        Tinebase_Core::getLogger()->notice(print_r($defaultCalendar, true));
 +        return $defaultCalendarArray;
 +    }
 +    
 +    /**
 +     * import contacts
 +     * 
 +     * @param string $tempFileId to import
 +     * @param string $definitionId
 +     * @param array $importOptions
 +     * @param array $clientRecordData
 +     * @return array
 +     */
 +    public function importEvents($tempFileId, $definitionId, $importOptions, $clientRecordData = array())
 +    {
 +        return $this->_import($tempFileId, $definitionId, $importOptions, $clientRecordData);
 +    }
 +    
 +    /**
 +     * creates a scheduled import
 +     * 
 +     * @param string $remoteUrl
 +     * @param string $interval
 +     * @param string $importOptions
 +     * @return array
 +     */
 +    public function importRemoteEvents($remoteUrl, $interval, $importOptions)
 +    {
 +        // Determine which plugin should be used to import
 +        switch ($importOptions['sourceType']) {
 +            case 'remote_caldav':
 +                $plugin = 'Calendar_Import_CalDAV';
 +                break;
 +            default:
 +                $plugin = 'Calendar_Import_Ical';
 +        }
 +
 +        $credentialCache = Tinebase_Auth_CredentialCache::getInstance();
 +        $credentials = $credentialCache->cacheCredentials(
 +            $importOptions['username'],
 +            $importOptions['password'],
 +            null,
 +            /* persist */       true,
 +            /* valid until */   Tinebase_DateTime::now()->addYear(100)
          );
 +
 +        $record = Tinebase_Controller_ScheduledImport::getInstance()->createRemoteImportEvent(array(
 +            'source'            => $remoteUrl,
 +            'interval'          => $interval,
 +            'options'           => array_replace($importOptions, array(
 +                'plugin' => $plugin,
 +                'importFileByScheduler' => $importOptions['sourceType'] != 'remote_caldav',
 +                'cid' => $credentials->getId(),
 +                'ckey' => $credentials->key
 +            )),
 +            'model'             => 'Calendar_Model_Event',
 +            'user_id'           => Tinebase_Core::getUser()->getId(),
 +            'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(),
 +        ));
 +
 +        $result = $this->_recordToJson($record);
 +        Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'container_id:'  .  print_r($result['container_id'], true));
 +
 +        return $result;
 +    }
 +    
 +    /**
 +     * get addressbook import definitions
 +     * 
 +     * @return array
 +     * 
 +     * @todo generalize this
 +     */
 +    protected function _getImportDefinitions()
 +    {
 +        $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(
 +            array('field' => 'application_id',  'operator' => 'equals', 'value' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()),
 +            array('field' => 'type',            'operator' => 'equals', 'value' => 'import'),
 +        ));
 +        
 +        $definitionConverter = new Tinebase_Convert_ImportExportDefinition_Json();
 +        
 +        try {
 +            $importDefinitions = Tinebase_ImportExportDefinition::getInstance()->search($filter);
 +            $defaultDefinition = $this->_getDefaultImportDefinition($importDefinitions);
 +            $result = array(
 +                'results'               => $definitionConverter->fromTine20RecordSet($importDefinitions),
 +                'totalcount'            => count($importDefinitions),
 +                'default'               => ($defaultDefinition) ? $definitionConverter->fromTine20Model($defaultDefinition) : array(),
 +            );
 +        } catch (Exception $e) {
 +            Tinebase_Exception::log($e);
 +            $result = array(
 +                array(
 +                    'results'               => array(),
 +                    'totalcount'            => 0,
 +                    'default'               => array(),
 +                )
 +            );
 +        }
 +        
 +        return $result;
 +    }
 +    
 +    /**
 +     * get default definition
 +     * 
 +     * @param Tinebase_Record_RecordSet $_importDefinitions
 +     * @return Tinebase_Model_ImportExportDefinition
 +     * 
 +     * @todo generalize this
 +     */
 +    protected function _getDefaultImportDefinition($_importDefinitions)
 +    {
 +        try {
 +            $defaultDefinition = Tinebase_ImportExportDefinition::getInstance()->getByName('cal_import_ical');
 +        } catch (Tinebase_Exception_NotFound $tenf) {
 +            if (count($_importDefinitions) > 0) {
 +                $defaultDefinition = $_importDefinitions->getFirstRecord();
 +            } else {
 +                Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No import definitions found for Calendar');
 +                $defaultDefinition = NULL;
 +            }
 +        }
 +        
 +        return $defaultDefinition;
      }
      
      /**
          
          $iMIPMessage->preconditionsChecked = FALSE;
          $iMIPFrontend->prepareComponent($iMIPMessage);
 -        $iMIPMessage->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
 +        $iMIPMessage->setTimezone(Tinebase_Core::getUserTimezone());
          return $iMIPMessage->toArray();
      }
      
@@@ -43,7 -43,6 +43,7 @@@ Tine.Calendar.Model.Event = Tine.Tineba
      // scheduleable interface fields
      { name: 'dtstart', type: 'date', dateFormat: Date.patterns.ISO8601Long },
      { name: 'recurid' },
 +    { name: 'base_event_id' },
      // scheduleable interface fields with multiple appearance
      { name: 'exdate' },
      //{ name: 'exrule' },
@@@ -185,7 -184,7 +185,7 @@@ Tine.Calendar.Model.Event.getDefaultDat
          transp: 'OPAQUE',
          editGrant: true,
          organizer: organizer,
-         attendee: Tine.Calendar.Model.Event.getDefaultAttendee(organizer) /*[
+         attendee: Tine.Calendar.Model.Event.getDefaultAttendee(organizer, container) /*[
              Ext.apply(Tine.Calendar.Model.Attender.getDefaultData(), {
                  user_type: 'user',
                  user_id: Tine.Tinebase.registry.get('userContact'),
      return data;
  };
  
- Tine.Calendar.Model.Event.getDefaultAttendee = function(organizer) {
+ Tine.Calendar.Model.Event.getDefaultAttendee = function(organizer, container) {
      var app = Tine.Tinebase.appMgr.get('Calendar'),
          mainScreen = app.getMainScreen(),
          centerPanel = mainScreen.getCenterPanel(),
              
          case 'calendarOwner':
              var addedOwnerIds = [];
-             Ext.each(filteredContainers, function(container){
-                 if (container.ownerContact) {
+             
+             Ext.each(filteredContainers, function(filteredContainer){
+                 if (filteredContainer.ownerContact && filteredContainer.type && filteredContainer.type == 'personal') {
                      var attendeeData = Ext.apply(Tine.Calendar.Model.Attender.getDefaultData(), {
                          user_type: 'user',
-                         user_id: container.ownerContact
+                         user_id: filteredContainer.ownerContact
                      });
                      
                      if (attendeeData.user_id.id == organizer.id){
                          attendeeData.status = 'ACCEPTED';
                      }
-                     if (addedOwnerIds.indexOf(container.ownerContact.id) < 0) {
+                     
+                     if (addedOwnerIds.indexOf(filteredContainer.ownerContact.id) < 0) {
                          defaultAttendee.push(attendeeData);
-                         addedOwnerIds.push(container.ownerContact.id);
+                         addedOwnerIds.push(filteredContainer.ownerContact.id);
                      }
                  }
              }, this);
              
+             if (container.ownerContact && addedOwnerIds.indexOf(container.ownerContact.id) < 0) {
+                 var attendeeData = Ext.apply(Tine.Calendar.Model.Attender.getDefaultData(), {
+                     user_type: 'user',
+                     user_id: container.ownerContact
+                 });
+                 
+                 if (container.ownerContact.id == organizer.id){
+                     attendeeData.status = 'ACCEPTED';
+                 }
+                 
+                 defaultAttendee.push(attendeeData);
+                 addedOwnerIds.push(container.ownerContact.id);
+             }
              break;
      }
      
@@@ -34,6 -34,13 +34,6 @@@ Tine.Filemanager.NodeGridPanel = Ext.ex
      filesProperty: 'files',
      
      /**
 -     * @cfg showTopToolbar
 -     * @type Boolean
 -     * TODO     think about that -> when we deactivate the top toolbar, we lose the dropzone for files!
 -     */
 -    //showTopToolbar: null,
 -    
 -    /**
       * config values
       * @private
       */
              Ext.MessageBox.show({
                  title: selections[0].data.type == 'folder' ? this.app.i18n._('Folder has been published successfully') : this.app.i18n._('File has been published successfully'), 
                  msg: String.format(this.app.i18n._("Url: {0}") + '<br />' + this.app.i18n._("Valid Until: {1}"), record.get('url'), record.get('expiry_time')), 
-                 width:900,
+                 minWidth: 900,
                  buttons: Ext.Msg.OK,
                  icon: Ext.MessageBox.INFO,
                  scope: this
          var app = this.app,
              nodeName = Tine.Filemanager.Model.Node.getContainerName();
          
 -        Ext.MessageBox.prompt(_('New Folder'), _('Please enter the name of the new folder:'), function(_btn, _text) {
 +        Ext.MessageBox.prompt(this.app.i18n._('New Folder'), this.app.i18n._('Please enter the name of the new folder:'), function(_btn, _text) {
              var currentFolderNode = app.getMainScreen().getCenterPanel().currentFolderNode;
              if(currentFolderNode && _btn == 'ok') {
                  if (! _text) {
 -                    Ext.Msg.alert(String.format(_('No {0} added'), nodeName), String.format(_('You have to supply a {0} name!'), nodeName));
 +                    Ext.Msg.alert(String.format(this.app.i18n._('No {0} added'), nodeName), String.format(this.app.i18n._('You have to supply a {0} name!'), nodeName));
                      return;
                  }
                  
      onUploadFail: function () {
          Ext.MessageBox.alert(
              _('Upload Failed'), 
 -            _('Could not upload file. Filesize could be too big. Please notify your Administrator. Max upload size: ') 
 -            + Tine.Tinebase.common.byteRenderer(Tine.Tinebase.registry.get('maxFileUploadSize')) 
 +            _('Could not upload file. Filesize could be too big. Please notify your Administrator.') 
          ).setIcon(Ext.MessageBox.ERROR);
          
          var app = Tine.Tinebase.appMgr.get('Filemanager'),