Index: trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 7795)
+++ trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 7861)
@@ -594,4 +594,7 @@
             //necessário para atulizar a atividade de composta pela tarefa aqui sendo atualizada
             if(isset($criteria['historic']['startTime']) || isset($criteria['historic']['endTime'])){
+                /*
+                 * Verify current task is built-in activity
+                 * */
                 $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'task', $uri['id']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));
                 if(!empty($taskToActivity)){
@@ -599,13 +602,20 @@
                     $isAllDay = 1;
 
+                    /*
+                     * Get all task in activity
+                     * */
+                    $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'activity', $taskToActivity[0]['activity']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));
+
                     if(!empty($activity)){
                         $start = $params['startTime'];
                         $end = $params['endTime'];
                         foreach($taskToActivity as $t){
-                         if($t['task']['id'] != $params['id']){
-                            $start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start;
-                            $end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end;
-                            $isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0;
-                         }
+
+
+                            if($t['task']['id'] != $params['id']){
+                                $start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start;
+                                $end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end;
+                                $isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0;
+                            }
                         }
 
@@ -631,5 +641,7 @@
                 }
             }
-
+            /*
+             * Clean historic not used
+             * */
             unset($criteria['historic']['endTime']);
             unset($criteria['historic']['rangeEnd']);
@@ -841,17 +853,32 @@
     }
 
+    public function getCalendarTask( $task ){
+
+        $sql = 'select co.calendar_id as "calendar" from calendar_to_calendar_object as "co", calendar_signature as "cs" where cs.user_uidnumber = '. Config::me('uidNumber')
+            .' AND cs.is_owner = 1 AND cs.calendar_id = co.calendar_id AND co.calendar_object_id = '. $task;
+
+
+        $returns = Controller::service('PostgreSQL')->execResultSql($sql);
+
+        return $returns[0]['calendar'];
+    }
+
     //TODO: Remover apos suporte a deepness na api 
     public function deepnessFindTask(&$uri, &$result, &$criteria, $original) {
-        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) 
-           foreach($result as &$value)
+        if (isset($criteria['deepness']) && $criteria['deepness'] != 0){
+
+            foreach($result as &$value){
+
                 $value['task'] = Controller::read(array('concept' => 'schedulable', 'id' => $value['task']));
-           
-        
-        return $result;
+                $value['task']['calendar'] = self::getCalendarTask( $value['task']['id'] );
+            }
+
+            return $result;
+        }
     }
 
     //TODO: Remover apos suporte a deepness na api 
     public function deepnessFindHistoric(&$uri, &$result, &$criteria, $original) {
-        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) {
+        if (isset($criteria['deepness']) && $criteria['deepness'] != 0) {
             foreach($result as &$v){
                 $v['user'] = Controller::read(array('concept' => 'user', 'id' => $v['user']));
@@ -883,21 +910,34 @@
                 .'calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", '
                 .'calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence", '
-                .'calendar_object.tzid as "timezone" '
-                .'FROM calendar_object '
-                .'WHERE ( calendar_object.id = '. $criteria['schedulable'] .')';
+                .'calendar_object.tzid as "timezone", calendar_to_calendar_object.calendar_id as "calendar" '
+                .'FROM calendar_object, calendar_to_calendar_object '
+                .'WHERE ( calendar_object.id = '. $criteria['schedulable'] .' AND calendar_to_calendar_object.calendar_object_id = calendar_object.id)';
 
             $params = Controller::service('PostgreSQL')->execResultSql($sql);
+
+            foreach( $params as &$event ){
+
+
+                if(isset( $event['repeat'] ) && isset( $event['repeat']['id'] ) ){
+                    $occurrences = Controller::service('PostgreSQL')->execResultSql('SELECT DISTINCT occurrence FROM calendar_object as "c", calendar_repeat_occurrence as "o", calendar_repeat as "r" WHERE r.object_id = '. $event['id'] .' AND o.repeat_id = r.id ' );
+
+                    if($occurrences){
+                        $event['occurrences'] = array();
+
+                        foreach($occurrences as $o)
+                            $event['occurrences'][] = $o['occurrence'];
+                    }else
+                        unset( $event['occurrences'] );
+                }
+            }
 
             $params = self::deepnessFindEvent($uri, $params, $criteria, $original);
             return false;
         }
-
-
-
     }
 
     //TODO: Remover apos suporte a deepness na api 
     public function deepnessFindEvent(&$uri, &$result, &$criteria, $original) {
-        if ((isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) ) {
+        if ((isset($criteria['deepness']) && $criteria['deepness'] != 0) ) {
 
             $date = new DateTime('now', new DateTimeZone('UTC'));
@@ -988,5 +1028,5 @@
     public static function deepnessReadParticipant( &$uri , &$result , &$criteria , $original ){
 	
-       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0)
+       if(isset($criteria['deepness']) && $criteria['deepness'] != 0)
        {
             if(isset($result['id']) && isset($result['user']))
Index: trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 7790)
+++ trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 7861)
@@ -201,6 +201,10 @@
 
             Calendar.rerenderView(true);
-            if(updateActivity)
+            if(updateActivity){
+
+                DataLayer.remove('taskToActivity', false);
                 refreshTaskActivity();
+            }
+
         });
     }
Index: trunk/prototype/modules/calendar/js/activity.helpers.js
===================================================================
--- trunk/prototype/modules/calendar/js/activity.helpers.js	(revision 7680)
+++ trunk/prototype/modules/calendar/js/activity.helpers.js	(revision 7861)
@@ -259,7 +259,5 @@
                     ['=', 'type', '2'], 
                     ['>=','startTime', $.now()], 
-                    ['in', 'calendar', 
-                        [$('div.new-activity-win.active select[name="groupFilter"]').val()]
-                    ]
+                    ['in', 'calendar', [$('div.new-activity-win.active select[name="groupFilter"]').val()]]
                 ], criteria: {filterTasks: true, deepness: 2}
         };
@@ -412,5 +410,9 @@
     updateActivity = false;
 
-    var objActivity = DataLayer.get('schedulable:activity', UI.dialogs.addActivity.find('input[name="idActivity"]').val());
+    var idTask = UI.dialogs.addActivity.find('input[name="idActivity"]').val();
+
+    getSchedulable( idTask );
+
+    var objActivity = DataLayer.get('schedulable:activity', idTask );
     var blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8');
     var blkAuto = UI.dialogs.addActivity.find('#group_addactivity_details1');
@@ -671,6 +673,9 @@
             text: false
         }).click(function () {
-	    var task = DataLayer.get('schedulable:task', $(this).parents('li').find('input[name="idtask[]"]').val());
-	    taskDetails(task, true, '',true, null, true);           
+
+            var idTask = $(this).parents('li').find('input[name="idtask[]"]').val()
+            getSchedulable(idTask);
+            var task = DataLayer.get('schedulable:task', idTask);
+            taskDetails(task, true, '',true, null, true);
         })
         .addClass('tiny disable ui-button-disabled ui-state-disabled')
