ContainerOwner strategy always add container owner if exists
authorsstamer <s.stamer@metaways.de>
Tue, 26 Jan 2016 15:18:19 +0000 (16:18 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 11 Feb 2016 09:25:14 +0000 (10:25 +0100)
Change-Id: I26074e938c7ee3d6c0fab871b0934fc36e08cfea
Reviewed-on: http://gerrit.tine20.com/customers/2626
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Calendar/Frontend/Json.php
tine20/Calendar/js/Model.js

index 7104b38..931c03d 100644 (file)
@@ -111,6 +111,7 @@ class Calendar_Frontend_Json extends Tinebase_Frontend_Json_Abstract
         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);
index 8c39eab..8a91b02 100644 (file)
@@ -184,7 +184,7 @@ Tine.Calendar.Model.Event.getDefaultData = function() {
         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'),
@@ -200,7 +200,7 @@ Tine.Calendar.Model.Event.getDefaultData = function() {
     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(),
@@ -251,24 +251,38 @@ Tine.Calendar.Model.Event.getDefaultAttendee = function(organizer) {
             
         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;
     }