Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6974)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6977)
@@ -498,6 +498,37 @@
                 unset($criteria['historic']['due']);
 
+	    //necessário para atulizar a atividade de composta pela tarefa aqui sendo atualizada
+	    if(isset($criteria['historic']['startTime']) || isset($criteria['historic']['endTime'])){
+		$taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'schedulable', $event['id']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));
+
+		if(!empty($taskToActivity)){
+		    $activity = Controller::read(array('concept' => 'schedulable', 'id' => $taskToActivity[0]['activity']), array('startTime', 'endTime', 'rangeStart', 'rangeEnd'));
+		    $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;
+			 }
+		    }
+
+		    $toUpdate = array();
+		    
+		    if($start != $activity['startTime'])
+			$toUpdate['starTime'] = $start;
+		    
+		    if($end != $activity['endTime'])
+			$toUpdate['endTime'] = $end;
+		     
+		    if(!empty($toUpdate))
+			Controller::update(array('concept' => 'schedulable', 'id' => $activity['id']), $toUpdate);		  
+		}
+	    }
+
             unset($criteria['historic']['rangeEnd']);
             unset($criteria['historic']['rangeStart']);
+	    unset($criteria['historic']['class']);
+	    unset($criteria['historic']['type']);
+	    unset($criteria['historic']['allDay']);
             unset($criteria['historic']['id']);            
         }
Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/css/style.css
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/css/style.css	(revision 6974)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/css/style.css	(revision 6977)
@@ -582,25 +582,25 @@
 .div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each:hover { background: #FFF2F2; cursor: pointer;}
 
-.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .date-hour { width: 140px; float: left; height: 20px}
+.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .date-hour {overflow: hidden; width: 140px; float: left; height: 20px}
 .div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .date-hour span { margin: 8px; float: left; }
-.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .user{ width: 150px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .user{overflow: hidden; width: 150px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .user span{ margin: 8px; float: left; }
-.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .attribute{ width: 130px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .attribute{overflow: hidden; width: 130px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .attribute span{ margin: 8px; float: left; }
-.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .beforeValue{ width: 150px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .beforeValue{overflow: hidden; width: 150px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .beforeValue span{ margin: 8px; float: left; }
-.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .afterValue{ width: 150px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .afterValue{overflow: hidden; width: 150px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addtask  #calendar_addtask_details8 .parent .child-bottom .child-bottom-each .afterValue span{ margin: 8px; float: left; }
 
 .div-addtask  #calendar_addtask_details8 .parent .child-top .date-hour { width: 140px; float: left; background: #E8F4FD; height: 20px; text-align: center; }
-.div-addtask  #calendar_addtask_details8 .parent .child-top .date-hour span{ margin: 6px 0; position: absolute; font-weight: bold; color: #2E6E9E; }
+.div-addtask  #calendar_addtask_details8 .parent .child-top .date-hour span{ display: block; padding: 6px; font-weight: bold; color: #2E6E9E; }
 .div-addtask  #calendar_addtask_details8 .parent .child-top .user { width: 150px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E; text-align: center;}
-.div-addtask  #calendar_addtask_details8 .parent .child-top .user span{margin: 6px 0; position: absolute; }
+.div-addtask  #calendar_addtask_details8 .parent .child-top .user span{display: block; padding: 6px;}
 .div-addtask  #calendar_addtask_details8 .parent .child-top .attribute { width: 130px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E;  text-align: center;}
-.div-addtask  #calendar_addtask_details8 .parent .child-top .attribute span{margin: 6px 0; position: absolute; }
+.div-addtask  #calendar_addtask_details8 .parent .child-top .attribute span{display: block; padding: 6px;}
 .div-addtask  #calendar_addtask_details8 .parent .child-top .beforeValue { width: 150px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E;  text-align: center;}
-.div-addtask  #calendar_addtask_details8 .parent .child-top .beforeValue span{margin: 6px 0; position: absolute; }
+.div-addtask  #calendar_addtask_details8 .parent .child-top .beforeValue span{display: block; padding: 6px; }
 .div-addtask  #calendar_addtask_details8 .parent .child-top .afterValue { width: 150px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E;  text-align: center;}
-.div-addtask  #calendar_addtask_details8 .parent .child-top .afterValue span{margin: 6px 0; position: absolute; }
+.div-addtask  #calendar_addtask_details8 .parent .child-top .afterValue span{display: block; padding: 6px; }
 
 /*Atividades*/
@@ -641,27 +641,27 @@
 .div-addactivity  #group_addactivity_details6  .parent .child-bottom .task { height: 25px; text-align: center; background: #FEFEAD; border-bottom: 1px solid #CCC;}
 .div-addactivity  #group_addactivity_details6  .parent .child-bottom .task.left {border-top: 1px solid #CCC;}
-.div-addactivity  #group_addactivity_details6  .parent .child-bottom .task span{ position: absolute; margin-top: 6px;}
-
-.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .date-hour { width: 140px; float: left; height: 20px}
+.div-addactivity  #group_addactivity_details6  .parent .child-bottom .task span{padding: 5px; display: block;}
+
+.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .date-hour {overflow: hidden; width: 140px; float: left; height: 20px}
 .div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .date-hour span { margin: 8px; float: left; }
-.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .user{ width: 145px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .user{overflow: hidden; width: 145px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .user span{ margin: 8px; float: left; }
-.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .attribute{ width: 130px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .attribute{overflow: hidden; width: 130px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .attribute span{ margin: 8px; float: left; }
-.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .beforeValue{ width: 130px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .beforeValue{overflow: hidden; width: 130px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .beforeValue span{ margin: 8px; float: left; }
-.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .afterValue{ width: 145px; float: left;  height: 20px; border-left: 1px solid #CCC; }
+.div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .afterValue{overflow: hidden; width: 129px; float: left;  height: 20px; border-left: 1px solid #CCC; }
 .div-addactivity  #group_addactivity_details6  .parent .child-bottom .child-bottom-each .afterValue span{ margin: 8px; float: left; }
 
 .div-addactivity  #group_addactivity_details6  .parent .child-top .date-hour { width: 140px; float: left; background: #E8F4FD; height: 20px; text-align: center; }
-.div-addactivity  #group_addactivity_details6  .parent .child-top .date-hour span{ margin: 6px 0; position: absolute; font-weight: bold; color: #2E6E9E; }
+.div-addactivity  #group_addactivity_details6  .parent .child-top .date-hour span{ display: block; padding: 6px; font-weight: bold; color: #2E6E9E; }
 .div-addactivity  #group_addactivity_details6  .parent .child-top .user { width: 145px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E; text-align: center;}
-.div-addactivity  #group_addactivity_details6  .parent .child-top .user span{margin: 6px 0; position: absolute; }
+.div-addactivity  #group_addactivity_details6  .parent .child-top .user span{display: block; padding: 6px; }
 .div-addactivity  #group_addactivity_details6  .parent .child-top .attribute { width: 130px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E;  text-align: center;}
-.div-addactivity  #group_addactivity_details6  .parent .child-top .attribute span{margin: 6px 0; position: absolute; }
+.div-addactivity  #group_addactivity_details6  .parent .child-top .attribute span{display: block; padding: 6px; }
 .div-addactivity  #group_addactivity_details6  .parent .child-top .beforeValue { width: 130px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E;  text-align: center;}
-.div-addactivity  #group_addactivity_details6  .parent .child-top .beforeValue span{margin: 6px 0; position: absolute; }
-.div-addactivity  #group_addactivity_details6  .parent .child-top .afterValue { width: 145px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E;  text-align: center;}
-.div-addactivity  #group_addactivity_details6  .parent .child-top .afterValue span{margin: 6px 0; position: absolute; }
+.div-addactivity  #group_addactivity_details6  .parent .child-top .beforeValue span{display: block; padding: 6px; }
+.div-addactivity  #group_addactivity_details6  .parent .child-top .afterValue { width: 129px; float: left; background: #E8F4FD; height: 20px; font-weight: bold; color: #2E6E9E;  text-align: center;}
+.div-addactivity  #group_addactivity_details6  .parent .child-top .afterValue span{display: block; padding: 6px; }
 
 
Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.codecs.js	(revision 6974)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.codecs.js	(revision 6977)
@@ -32,4 +32,6 @@
     }
 }
+
+updateActivity = false;
 
 constantsParticipant = {
@@ -196,4 +198,6 @@
 	DataLayer.commit( false, false, function(){	
             Calendar.rerenderView(true);
+	    if(updateActivity)
+		refreshTaskActivity();
 	});
     }
Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/activity.helpers.js
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/activity.helpers.js	(revision 6974)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/activity.helpers.js	(revision 6977)
@@ -11,102 +11,641 @@
     if(!isMail)
 	objActivity = DataLayer.encode( "schedulable:activity", objActivity );
+
+    /**
+    * canDiscardActivityDialog deve ser true se não houver alterações no evento
+    */
+    canDiscardActivityDialog = true;
+    /**
+	 * zebraDiscardActivityDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog)
+	 * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la
+	 */
+    zebraDiscardActivityDialog = false;
+	
+	var html = DataLayer.render( path+'templates/activity_add.ejs', {
+	    activity:objActivity
+	});	
+			
+	if (!UI.dialogs.addActivity) {
+
+	    UI.dialogs.addActivity = jQuery('#sandbox').append('<div title="Criar Atividade" class="new-activity-win active"> <div>').find('.new-activity-win.active').html(html).dialog({
+    		resizable: false, 
+    		modal:true, 
+    		autoOpen: false,
+    		width:735, 
+    		position: 'center', 
+    		close: function(event, ui) {
+    			/**
+    			 * Remove tooltip possivelmente existente
+    			 */
+    			if ($('.qtip.qtip-blue.qtip-active').length)
+    				$('.qtip.qtip-blue.qtip-active').qtip('destroy');						
+    			
+                attendees  = {};
+    		},
+    		beforeClose: function(event, ui) {
+    		
+    		    if (!canDiscardActivityDialog && !zebraDiscardActivityDialog) {
+        			zebraDiscardActivityDialog = true;
+        			window.setTimeout(function() {
+        			    $.Zebra_Dialog('Suas alterações na atividade não foram salvas. Deseja descartar as alterações?', {
+        				'type':     'question',
+        				'overlay_opacity': '0.5',
+        				'buttons':  ['Descartar alterações', 'Continuar editando'],
+        				'onClose':  function(clicked) {
+        				    if(clicked == 'Descartar alterações') {
+            					canDiscardActivityDialog = true;
+            					/**
+            					*Remoção dos anexos do eventos caso seja cancelado a edição
+            					*/
+            					DataLayer.rollback();
+
+            					var ids = false;
+            					$.each($('.attachment-list input'), function (i, input) {
+            					    DataLayer.put('attachment', {id: ''+input.value});
+            					    DataLayer.remove('attachment', ''+input.value);
+            						ids = true;
+            					});
+            					if(ids)
+            						DataLayer.commit();
+
+            					UI.dialogs.addActivity.dialog('close');
+        				    }else{
+        					   zebraDiscardActivityDialog = false;
+        				    }
+        										
+        				    /**
+        				    * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la
+        				    * com ESC, para que o evento ESC não seja propagado para fechamento da
+        				    * janela de edição de eventos, deve ser setada uma flag indicando que
+        				    * já existe uma janela de confirmação aberta.
+        				    */
+        				    if (!clicked) {
+            					window.setTimeout(function() {
+            					    zebraDiscardActivityDialog = false;
+            					}, 200);
+        				    }
+        				}
+        		    });
+        								
+        		}, 300);
+    	    }
+    	    //DataLayer.rollback();
+    	    return canDiscardActivityDialog;
+    	},
+    	dragStart: function(event, ui) {
+	    if ($('.qtip.qtip-blue.qtip-active').length)
+		$('.qtip.qtip-blue.qtip-active').qtip('destroy');
+       }
+    });
+				
+	} else {
+	    UI.dialogs.addActivity.html(html);
+	}
+
+/* Checkbox allday */
+UI.dialogs.addActivity.find('input[name="allDay"]').click(function(){
+    $(this).attr("checked") ? 
+    UI.dialogs.addActivity.find('.start-time, .end-time').addClass('hidden') :
+    UI.dialogs.addActivity.find('.start-time, .end-time').removeClass('hidden'); 
+});
+		
+var tabs = UI.dialogs.addActivity.children('.content').tabs({
+	select: function(event, ui) { 
+		if ($('.qtip.qtip-blue.qtip-active').length)
+			$('.qtip.qtip-blue.qtip-active').qtip('destroy');
+	}	
+	});
+
+var group = DataLayer.get('calendar', objActivity.group);
+				
+if (group.timezone != objActivity.timezone){
+    UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').find('option[value="'+objActivity.timezone+'"]').attr('selected','selected').trigger('change');
+    UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').addClass('hidden');
+    $('.group-addevent-details-txt-timezone').removeClass('hidden');
+			
+}
+
+UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').click(function(e){
+    $(this).addClass('hidden');
+    $('.group-addactivity-details-txt-timezone').removeClass('hidden');
+    e.preventDefault();
+});
+
+UI.dialogs.addActivity.find('.button.remove').button({
+    text:false, 
+    icons:{
+	primary:'ui-icon-close'
+    }
+}).click(function(el){
+    var id;
+    if( id = $(this).parent().find('input[name="alarmId[]"]').val())
+	DataLayer.remove('alarm', id);
+    $(this).parent().remove().find('li').is(':empty');
+});
+
+UI.dialogs.addActivity.find('.button-add-alarms').click(function(){
+            DataLayer.render( 'templates/alarms_add_itemlist.ejs', {type: 0}, function( template ){                     
+            jQuery('.activity-alarms-list').append(template)
+            .find('li:last label:eq(0)').remove().end()
+            .find('.number').numeric().end()
+            .find('.button.remove').button({
+                text:false, 
+                icons:{
+                    primary:'ui-icon-close'
+                }
+            }).click(function(el) {
+                $(this).parent().remove();
+            });    
+            });
+        });
+
+/*Seleciona a agenda padrão para visualização/edição de um evento*/
+if(objActivity.id)
+    UI.dialogs.addActivity.find('select[name="group"] option[value="'+objActivity.group+'"]').attr('selected','selected').trigger('change');
+
+UI.dialogs.addActivity.find('.button').button();
+    UI.dialogs.addActivity.find('.button.add').button({
+        icons: {
+    	   secondary: "ui-icon-plus"
+        }
+});
+
+todoStatus('addActivity', (objActivity.activityStatus != undefined) ? objActivity.activityStatus : 1);
+
+UI.dialogs.addActivity.find('select[name="activityStatus"]').attr('disabled', 'disabled');
+
+// ==== validation events ====
+UI.dialogs.addActivity.find(".input-group .h1").Watermark("Atividade sem título");
+
+UI.dialogs.addActivity.find(".number").numeric();
+
+User.preferences.dateFormat.indexOf('-') > 0 ? 
+UI.dialogs.addActivity.find(".date").mask("99-99-9999", {
+    completed:function(){
+	updateMap();
+    }
+}) : 
+
+UI.dialogs.addActivity.find(".date").mask("99/99/9999", {
+    completed:function(){
+	updateMap();
+    }
+});
+
+UI.dialogs.addActivity.find(".menu-addactivity")
+.children(".delete").click(function(){
+    $.Zebra_Dialog('Tem certeza que deseja excluir a atividade?', {
+	'type':     'question',
+	'overlay_opacity': '0.5',
+	'buttons':  ['Sim', 'Não'],
+	'onClose':  function(clicked) {
+	    if(clicked == 'Sim'){
+		canDiscardActivityDialog = true;
+		/* Remove por filtro */
+		DataLayer.removeFilter('schedulable', {filter: ['AND', ['=', 'id', objActivity.id], ['=', 'calendar', objActivity.group], ['=','user',(objActivity.me.user ? objActivity.me.user.id : objActivity.me.id)], ['=', 'type', '2']]});
+		Calendar.rerenderView(true);
+		/********************/
+		UI.dialogs.addActivity.dialog("close");
+	    }
+	}
+    });
+}).end()
+	    
+.children(".cancel").click(function(){
+    UI.dialogs.addActivity.dialog("close");
+}).end()
+	    
+.children(".save").click(function(){
+    /* Validação 
+    var msg = false;			
+    if(msg = validDateEvent()){
+    	$(".new-activity-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); 
+    	return false;
+    }
+    */
+	UI.dialogs.addActivity.find('select[name="activityStatus"]').removeAttr('disabled');
+    canDiscardActivityDialog = true;
+			
+	UI.dialogs.addActivity.children().find('form.form-addactivity').submit();
+	UI.dialogs.addActivity.dialog("close");
+
+}).end()
+		
+.children(".export").click(function(){
+    UI.dialogs.addActivity.children().find(".form-export").submit();
+});
+
+var task_activityHtml = DataLayer.render( path+'templates/task_activity_add.ejs', {	activity: objActivity});
+var blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8').append(task_activityHtml);
+
+var dates = UI.dialogs.addActivity.find('input.date').datepicker({
+    dateFormat: User.preferences.dateFormat.replace(/M/g, 'm').replace(/yyyy/g, 'yy'),
+    onSelect : function( selectedDate ){
+	updateMap();
+    }
+});
+
+blkAddTask.find('.add-activity-search .ui-icon-search').click(function(event) {
+    blkAddTask.find('.add-activity-search input').keydown();
+});
+			
+			
+blkAddTask.find('.add-activity-search input').keydown(function(event) {
+
+    if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') {	
+    // Fazer get das tarefas	
+	var filter = 
+        {
+            filter: 
+                ['AND',
+                    ['=', 'type', '2'], 
+                    ['>=','startTime', $.now()], 
+                    ['in', 'calendar', 
+                        [$('div.new-activity-win.active select[name="groupFilter"]').val()]
+                    ]
+                ], criteria: {'filterTasks': true}
+        };
+    if($(this).val() != ''){
+        filter['filter'].push(['OR',
+                            ["i*", "summary", $(this).val()], 
+                            ["i*", "description", $(this).val()]
+                           ]);
+    }
+
+    var result = DataLayer.get('schedulable:taskSearch', filter, true)
+	/**
+	* TODO: trocar por template
+	*/
+	blkAddTask.find('ul.search-result-list').empty().css('overflow', 'hidden');
+	if (!result) {
+	    blkAddTask.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>');
+	}else{
+    	for(i=0; i<result.length; i++)
+    	    result[i].enabled = (blkAddTask.find('dd.task-activity-list ul.task-activity-list input[value="' +  result[i].id + '"]').length) ? false : true;
+    											
+    	blkAddTask.find('ul.search-result-list').append(DataLayer.render( path+'templates/task_search_itemlist.ejs', result));
+
+        /* TODO - Verificar id da aitividade*/
+    	blkAddTask.find('ul.search-result-list li').click(function(event, ui){
+    	    if ($(event.target).is('input')) {
+                old_item = $(event.target).parents('li');
+
+                tasks[old_item.find('[name="id"]').val()] = {
+                    startDate: old_item.find('[name="taskStartDate"]').val(),
+                    startHour: old_item.find('[name="taskStartHour"]').val(),
+                    endDate: old_item.find('[name="taskEndDate"]').val(),
+                    endHour: old_item.find('[name="taskEndHour"]').val(),
+                    dueDate: old_item.find('[name="taskDueDate"]').val(),
+                    dueTime: old_item.find('[name="taskDueTime"]').val(),
+                    allDay: old_item.find('[name="taskAllDay"]').val(),
+                    percentage: old_item.find('[name="taskPercentage"]').val(),
+                    status: old_item.find('[name="taskStatus"]').val()
+                };
+
+                tasks.length += 1;
+        							
+		blkAddTask.find('dd.task-activity-list ul.task-activity-list')
+		    .append(DataLayer.render(path+'templates/task_add_itemlist.ejs', [{
+			idTask: old_item.find('[name="id"]').val(),
+        		    description: old_item.find('.description').html(),
+			    isWrite: false
+			}]))
+        		.scrollTo('max');
+		callbackTask();
+                registerStatus();
+                blkAddTask.find('.not-activity').addClass('hidden');
+                old_item.remove();
+    	    }
+    	});
+    }
+    event.preventDefault();
+    }
+});
+
+/*Carrega as tarefas já existentes em uma atividade*/
+if(objActivity.tasks.length){
+    tasks = objActivity.tasks;
+
+    for(var i in objActivity.tasks){
+        if(i != 'length')
+            blkAddTask.find('dd.task-activity-list ul.task-activity-list')
+                .append(DataLayer.render(path+'templates/task_add_itemlist.ejs', [{
+                    idTask: i,
+                    description: tasks[i].description,
+                    idTaskToActivity: tasks[i].taskToActivity,
+		    isWrite: true
+                 }]))
+            .scrollTo('max');
+    }
+
+    callbackTask();
+    registerStatus();
+    blkAddTask.find('.not-activity').addClass('hidden');
+}
+
+UI.dialogs.addActivity.find('.row.fileupload-buttonbar-activity .button').filter('.delete').button({
+    icons: {
+	   primary: "ui-icon-close"
+    },
+    text: 'Excluir'
+}).click(function () {
+    $.Zebra_Dialog('Tem certeza que deseja excluir todos anexos?', {
+	'type':     'question',
+	'overlay_opacity': '0.5',
+	'buttons':  ['Sim', 'Não'],
+	'onClose':  function(clicked) {
+	    if(clicked == 'Sim'){
+		
+                var ids = [];
+                $.each($('.attachment-list input'), function (i, input) {
+                     DataLayer.remove('schedulableToAttachment', {
+                        filter: ['=', 'id', ''+input.value]
+                        });
+                });
+                $('.attachment-list input').remove();
+                $('.row.fileupload-buttonbar-activity .attachments-list p').remove();
+            }
+        }});
+}).end()
+.filter('.close').button({
+    icons: {
+	   primary: "ui-icon-close"
+    },
+    text: false
+}).click(function () {
+    DataLayer.remove('schedulableToAttachment', $(this).parents('p').find('input[name="fileId[]"]').val());
+    $(this).parents('p').remove();
+}).end()
+.filter('.downlaod-archive').button({
+    icons: {
+	   primary: "ui-icon-arrowthickstop-1-s"
+    },
+    text: false
+});
+var maxSizeFile = 2000000;
+$('#fileuploadactivity').fileupload({
+    sequentialUploads: true,
+    add: function (e, data) {
+	if(data.files[0].size < maxSizeFile)
+	    data.submit();
+    },
+    change: function (e, data) {
+	$.each(data.files, function (index, file) {
+	    var attach = {};
+	    attach.fileName = file.name;
+	    var ext = file.name.split('.');
+	    if(file.name.length > 10)
+		attach.fileName = ext.length == 1 ? file.name.substr(0, 10) :  file.name.substr(0, 6) + '.' + ext[ext.length -1];
+	    attach.fileSize = formatBytes(file.size);
+	    if(file.size > maxSizeFile)
+		attach.error = 'Tamanho de arquivo nao permitido!!'
+				
+	    $('div.new-activity-win .attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', {
+		file : attach
+	    }));
+				
+	    if(file.size < maxSizeFile){
+		$('div.new-activity-win .fileinput-button.new').append(data.fileInput[0]).removeClass('new');
+		$('div.new-activity-win .attachments-list').find('[type=file]').addClass('hidden');
+					
+	    }else
+		$('div.new-activity-win .fileinput-button.new').removeClass('new');
+				
+				
+	    $('div.new-activity-win .attachments-list').find('.button.close').button({
+		icons: {
+		    primary: "ui-icon-close"
+		},
+		text: false
+	    }).click(function(){
+		var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
+		$('.attachment-list').find('input[value="'+idAttach+'"]')
+		$(this).parent().remove();
+	    });	
+				
+	})
+	},
+    done: function(e, data){
+    	var currentUpload = $('div.new-activity-win .progress.after-upload:first').removeClass('after-upload').addClass('on-complete').hide();
+
+    	if(!!data.result && data.result != "[]"){
+    	    var newAttach = (attch = jQuery.parseJSON(data.result)) ? attch : jQuery.parseJSON(data.result[0].activeElement.childNodes[0].data);
+    	    $('div.new-activity-win .attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>');
+    	    currentUpload.removeClass('on-complete').parents('p')
+    	    .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>')
+    	    .find('.status-upload').addClass('ui-icon ui-icon-check');
+    	}else
+    	    currentUpload.removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel');
+        }
+});
+$('.attachments-list .button').button();
+
+if(!!window.FormData)			
+$('#fileuploadactivity').bind('fileuploadstart', function () {
+    var widget = $(this),
+    progressElement = $('#fileupload-progress-activity').fadeIn(),
+    interval = 500,
+    total = 0,
+    loaded = 0,
+    loadedBefore = 0,
+    progressTimer,
+    progressHandler = function (e, data) {
+	loaded = data.loaded;
+	total = data.total;
+    },
+    stopHandler = function () {
+	widget
+	.unbind('fileuploadprogressall', progressHandler)
+	.unbind('fileuploadstop', stopHandler);
+	window.clearInterval(progressTimer);
+	progressElement.fadeOut(function () {
+	    progressElement.html('');
+	});
+    },
+    formatTime = function (seconds) {
+	var date = new Date(seconds * 1000);
+	return ('0' + date.getUTCHours()).slice(-2) + ':' +
+	('0' + date.getUTCMinutes()).slice(-2) + ':' +
+	('0' + date.getUTCSeconds()).slice(-2);
+    },
+    /* formatBytes = function (bytes) {
+            if (bytes >= 1000000000) {
+                return (bytes / 1000000000).toFixed(2) + ' GB';
+            }
+            if (bytes >= 1000000) {
+                return (bytes / 1000000).toFixed(2) + ' MB';
+            }
+            if (bytes >= 1000) {
+                return (bytes / 1000).toFixed(2) + ' KB';
+            }
+            return bytes + ' B';
+        },*/
+    formatPercentage = function (floatValue) {
+	return (floatValue * 100).toFixed(2) + ' %';
+    },
+    updateProgressElement = function (loaded, total, bps) {
+	progressElement.html(
+	    formatBytes(bps) + 'ps | ' +
+	    formatTime((total - loaded) / bps) + ' | ' +
+	    formatPercentage(loaded / total) + ' | ' +
+	    formatBytes(loaded) + ' / ' + formatBytes(total)
+	    );
+    },
+    intervalHandler = function () {
+	var diff = loaded - loadedBefore;
+	if (!diff) {
+	    return;
+	}
+	loadedBefore = loaded;
+	updateProgressElement(
+	    loaded,
+	    total,
+	    diff * (1000 / interval)
+	    );
+    };
+    widget
+    .bind('fileuploadprogressall', progressHandler)
+    .bind('fileuploadstop', stopHandler);
+    progressTimer = window.setInterval(intervalHandler, interval);
+});
+
+UI.dialogs.addActivity.find(':input').change(function(event){
+    if (event.keyCode != '27' && event.keyCode != '13')
+	canDiscardActivityDialog = false;
+}).keydown(function(event){
+    if (event.keyCode != '27' && event.keyCode != '13')
+	canDiscardActivityDialog = false;
+});
+
+UI.dialogs.addActivity.dialog('open');
+}
+
+function refreshTaskActivity(){
+    updateActivity = false;
+
+    var objActivity = DataLayer.get('schedulable:activity', UI.dialogs.addActivity.find('input[name="idActivity"]').val());
+    var blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8');
+    var blkAuto = UI.dialogs.addActivity.find('#group_addactivity_details1');
     
-    var registerStatus = function(){
-        var blkAuto = UI.dialogs.addActivity.find('#group_addactivity_details1');
-
-        var startDate = false;
-        var endDate = new Date;
-        var dueDate = new Date;
-        var percentage = 0;		
-		var statusTasks = {1: 0, 2: 0, 3: 0, 4: 0};
-		
-		var allDay = true;
-
-        var formatString =  User.preferences.dateFormat + " " +  User.preferences.hourFormat;
-
-        if(tasks.length == 0){
-
-            startDate = new Date();
-            var configData = (startDate.toString('mm') < 30)  ? {minutes: (30 - parseInt(startDate.toString('mm')))} : {hours: 1, minutes: '-'+startDate.toString('mm')};
-            startDate.add(configData); 
-
-            endDate = new Date(dateCalendar.decodeRange(startDate, (!!User.preferences.defaultCalendar ? (   !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ?  (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration) : (User.preferences.defaultDuration)) : (User.preferences.defaultDuration))));
-
-            blkAuto.find('input[name="startDate"]').val(startDate.toString(User.preferences.dateFormat ));
-            blkAuto.find('input[name="startHour"]').val(startDate.toString(User.preferences.hourFormat ));
-
-            blkAuto.find('input[name="endDate"]').val(endDate.toString(User.preferences.dateFormat ));
-            blkAuto.find('input[name="endHour"]').val(endDate.toString(User.preferences.hourFormat ));
-
-            blkAuto.find('input[name="dueDate"]').val('');
-            blkAuto.find('input[name="dueHour"]').val('');
-                        
-            blkAuto.find('input[name="percentage"]').val(percentage);
-			
-			todoStatus('addActivity', 1);
-		
-			UI.dialogs.addActivity.find('select[name="activityStatus"] option[value="'+1+'"]').attr('selected','selected');
-
-            blkAuto.find('input[name="allDay"]').attr('checked', false);
-
-            return true;
-        }
-
-        for (var i in tasks){
-
-            if(i == 'length')
-                continue;
-			
-			statusTasks[tasks[i].status]++;
-			
-            stTime = Date.parseExact( tasks[i].startDate + " "+$.trim( tasks[i].startHour) , formatString);
-            enTime = Date.parseExact( tasks[i].endDate + " "+$.trim( tasks[i].endHour), formatString );
-            
-            startDate = (startDate && startDate.compareTo(stTime) == -1) ? startDate : stTime;
-            endDate = endDate.compareTo(enTime) == -1 ? enTime : endDate;
-            
-            if(tasks[i].dueDate != ''){
-                pvTime = Date.parseExact( tasks[i].dueDate + " "+$.trim( tasks[i].dueTime), formatString );
-                dueDate = dueDate.compareTo(pvTime) == -1 ? pvTime : dueDate;
-            }
-
-            if(parseInt(tasks[i].percentage) > 0)
-                percentage += parseInt((100 / tasks.length)) * ( parseInt(tasks[i].percentage) / 100);
-        }
-		var statusActivity = 1;
-		
-		if(statusTasks[4] != 0)
-			statusActivity = 4;
-		else if(statusTasks[2] != 0)
-			statusActivity = 2;
-		else if(statusTasks[3] == tasks.length)
-			statusActivity = 3;
-		else if(statusTasks[1] == tasks.length)
-			statusActivity = 1;
-		else
-			statusActivity = 2;			
-			
-		todoStatus('addActivity', statusActivity);
-		
-		UI.dialogs.addActivity.find('select[name="activityStatus"] option[value="'+statusActivity+'"]').attr('selected','selected');
-		
-        dueDate = dueDate.compareTo(endDate) == -1 ? endDate : dueDate;
-
-        blkAuto.find('input[name="startDate"]').val(startDate.toString(User.preferences.dateFormat ));
-        blkAuto.find('input[name="startHour"]').val(startDate.toString(User.preferences.hourFormat ));
-
-        blkAuto.find('input[name="endDate"]').val(endDate.toString(User.preferences.dateFormat ));
-        blkAuto.find('input[name="endHour"]').val(endDate.toString(User.preferences.hourFormat ));
-
-        blkAuto.find('input[name="dueDate"]').val(dueDate.toString(User.preferences.dateFormat ));
-        blkAuto.find('input[name="dueHour"]').val(dueDate.toString(User.preferences.hourFormat ));
-
-        blkAuto.find('input[name="percentage"]').val(percentage);
-
-        blkAuto.find('input[name="allDay"]').attr('checked', (!!(startDate.compareTo(endDate) == 0) || (startDate.toString('HH:mm') == endDate.toString('HH:mm')) ? true : false));
-    }
-
-
-    var callbackTask = function(){
+   tasks = objActivity.tasks;
+   blkAddTask.find('dd.task-activity-list ul.task-activity-list').html('');
+   
+   for(var i in tasks)
+       DataLayer.remove('schedulable', i, false);
+
+    for(var i in objActivity.tasks){
+        if(i != 'length')
+            blkAddTask.find('dd.task-activity-list ul.task-activity-list')
+                .append(DataLayer.render('templates/task_add_itemlist.ejs', [{
+                    idTask: i,
+                    description: tasks[i].description,
+                    idTaskToActivity: tasks[i].taskToActivity,
+		    isWrite: true
+                 }]))
+            .scrollTo('max');
+    }
+
+    callbackTask(blkAddTask);
+    registerStatus(blkAuto);
+}
+
+function registerStatus(blkAuto){
+    if(!blkAuto)
+	blkAuto = UI.dialogs.addActivity.find('#group_addactivity_details1');
+
+    var startDate = false;
+    var endDate = new Date;
+    var dueDate = new Date;
+    var percentage = 0;		
+	    var statusTasks = {1: 0, 2: 0, 3: 0, 4: 0};
+	    var allDay = true;
+
+    var formatString =  User.preferences.dateFormat + " " +  User.preferences.hourFormat;
+
+    if(tasks.length == 0){
+
+	startDate = new Date();
+	var configData = (startDate.toString('mm') < 30)  ? {minutes: (30 - parseInt(startDate.toString('mm')))} : {hours: 1, minutes: '-'+startDate.toString('mm')};
+	startDate.add(configData); 
+
+	endDate = new Date(dateCalendar.decodeRange(startDate, (!!User.preferences.defaultCalendar ? (   !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ?  (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration) : (User.preferences.defaultDuration)) : (User.preferences.defaultDuration))));
+
+	blkAuto.find('input[name="startDate"]').val(startDate.toString(User.preferences.dateFormat ));
+	blkAuto.find('input[name="startHour"]').val(startDate.toString(User.preferences.hourFormat ));
+
+	blkAuto.find('input[name="endDate"]').val(endDate.toString(User.preferences.dateFormat ));
+	blkAuto.find('input[name="endHour"]').val(endDate.toString(User.preferences.hourFormat ));
+
+	blkAuto.find('input[name="dueDate"]').val('');
+	blkAuto.find('input[name="dueHour"]').val('');
+
+	blkAuto.find('input[name="percentage"]').val(percentage);
+
+	todoStatus('addActivity', 1);
+
+	UI.dialogs.addActivity.find('select[name="activityStatus"] option[value="'+1+'"]').attr('selected','selected');
+
+	blkAuto.find('input[name="allDay"]').attr('checked', false);
+
+	return true;
+    }
+
+    for (var i in tasks){
+
+	if(i == 'length')
+	    continue;
+
+	statusTasks[tasks[i].status]++;
+
+	var stTime = Date.parseExact( tasks[i].startDate + " "+$.trim( tasks[i].startHour) , formatString);
+	var enTime = Date.parseExact( tasks[i].endDate + " "+$.trim( tasks[i].endHour), formatString );
+
+	startDate = (startDate && startDate.compareTo(stTime) == -1) ? startDate : stTime;
+	endDate = endDate.compareTo(enTime) == -1 ? enTime : endDate;
+
+	if(tasks[i].dueDate != ''){
+	    var pvTime = Date.parseExact( tasks[i].dueDate + " "+$.trim( tasks[i].dueTime), formatString );
+	    dueDate = dueDate.compareTo(pvTime) == -1 ? pvTime : dueDate;
+	}
+
+	if(parseInt(tasks[i].percentage) > 0)
+	    percentage += parseInt(parseInt((100 / tasks.length)) * ( parseInt(tasks[i].percentage) / 100));
+    }
+    var statusActivity = 1;
+
+    if(statusTasks[4] != 0)
+	statusActivity = 4;
+    else if(statusTasks[2] != 0)
+	statusActivity = 2;
+    else if(statusTasks[3] == tasks.length)
+	statusActivity = 3;
+    else if(statusTasks[1] == tasks.length)
+	statusActivity = 1;
+    else
+	statusActivity = 2;			
+
+    todoStatus('addActivity', statusActivity);
+
+    UI.dialogs.addActivity.find('select[name="activityStatus"] option[value="'+statusActivity+'"]').attr('selected','selected');
+
+    dueDate = dueDate.compareTo(endDate) == -1 ? endDate : dueDate;
+
+    blkAuto.find('input[name="startDate"]').val(startDate.toString(User.preferences.dateFormat ));
+    blkAuto.find('input[name="startHour"]').val(startDate.toString(User.preferences.hourFormat ));
+
+    blkAuto.find('input[name="endDate"]').val(endDate.toString(User.preferences.dateFormat ));
+    blkAuto.find('input[name="endHour"]').val(endDate.toString(User.preferences.hourFormat ));
+
+    blkAuto.find('input[name="dueDate"]').val(dueDate.toString(User.preferences.dateFormat ));
+    blkAuto.find('input[name="dueHour"]').val(dueDate.toString(User.preferences.hourFormat ));
+
+    blkAuto.find('input[name="percentage"]').val(percentage);
+
+    blkAuto.find('input[name="allDay"]').attr('checked', (!!(startDate.compareTo(endDate) == 0) || (startDate.toString('HH:mm') == endDate.toString('HH:mm')) ? true : false));
+}
+
+function callbackTask(blkAddTask){
+	if(!blkAddTask)
+	    blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8');
 
         blkAddTask.find("li .button").filter(".close.new").button({
@@ -211,5 +750,16 @@
      })
  .addClass('tiny disable ui-button-disabled ui-state-disabled')
- .removeClass('new').end()    
+ .removeClass('new').end()
+ .filter(".edit.new").button({
+            icons: {
+            primary: "ui-icon-pencil"
+            },
+            text: false
+        }).click(function () {
+	    var task = DataLayer.get('schedulable:task', $(this).parents('li').find('input[name="idtask[]"]').val());
+	    taskDetails(task, true, '',true, null, true);           
+        })
+        .addClass('tiny disable ui-button-disabled ui-state-disabled')
+        .removeClass('new').end()
 
         UI.dialogs.addActivity.find('.task-activity-list li').hover(
@@ -226,510 +776,2 @@
         );        
     }
-
-
-    /**
-	 * canDiscardActivityDialog deve ser true se não houver alterações no evento
-	 */
-    canDiscardActivityDialog = true;
-    /**
-	 * zebraDiscardActivityDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog)
-	 * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la
-	 */
-    zebraDiscardActivityDialog = false;
-	
-	var html = DataLayer.render( path+'templates/activity_add.ejs', {
-	    activity:objActivity
-	});	
-			
-	if (!UI.dialogs.addActivity) {
-
-	    UI.dialogs.addActivity = jQuery('#sandbox').append('<div title="Criar Atividade" class="new-activity-win active"> <div>').find('.new-activity-win.active').html(html).dialog({
-    		resizable: false, 
-    		modal:true, 
-    		autoOpen: false,
-    		width:735, 
-    		position: 'center', 
-    		close: function(event, ui) {
-    			/**
-    			 * Remove tooltip possivelmente existente
-    			 */
-    			if ($('.qtip.qtip-blue.qtip-active').length)
-    				$('.qtip.qtip-blue.qtip-active').qtip('destroy');						
-    			
-                attendees  = {};
-    		},
-    		beforeClose: function(event, ui) {
-    		
-    		    if (!canDiscardActivityDialog && !zebraDiscardActivityDialog) {
-        			zebraDiscardActivityDialog = true;
-        			window.setTimeout(function() {
-        			    $.Zebra_Dialog('Suas alterações na atividade não foram salvas. Deseja descartar as alterações?', {
-        				'type':     'question',
-        				'overlay_opacity': '0.5',
-        				'buttons':  ['Descartar alterações', 'Continuar editando'],
-        				'onClose':  function(clicked) {
-        				    if(clicked == 'Descartar alterações') {
-            					canDiscardActivityDialog = true;
-            					/**
-            					*Remoção dos anexos do eventos caso seja cancelado a edição
-            					*/
-            					DataLayer.rollback();
-
-            					var ids = false;
-            					$.each($('.attachment-list input'), function (i, input) {
-            					    DataLayer.put('attachment', {id: ''+input.value});
-            					    DataLayer.remove('attachment', ''+input.value);
-            						ids = true;
-            					});
-            					if(ids)
-            						DataLayer.commit();
-
-            					UI.dialogs.addActivity.dialog('close');
-        				    }else{
-        					   zebraDiscardActivityDialog = false;
-        				    }
-        										
-        				    /**
-        				    * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la
-        				    * com ESC, para que o evento ESC não seja propagado para fechamento da
-        				    * janela de edição de eventos, deve ser setada uma flag indicando que
-        				    * já existe uma janela de confirmação aberta.
-        				    */
-        				    if (!clicked) {
-            					window.setTimeout(function() {
-            					    zebraDiscardActivityDialog = false;
-            					}, 200);
-        				    }
-        				}
-        		    });
-        								
-        		}, 300);
-    	    }
-    	    //DataLayer.rollback();
-    	    return canDiscardActivityDialog;
-    	},
-    	dragStart: function(event, ui) {
-	    if ($('.qtip.qtip-blue.qtip-active').length)
-		$('.qtip.qtip-blue.qtip-active').qtip('destroy');
-       }
-    });
-				
-	} else {
-	    UI.dialogs.addActivity.html(html);
-	}
-
-/* Checkbox allday */
-UI.dialogs.addActivity.find('input[name="allDay"]').click(function(){
-    $(this).attr("checked") ? 
-    UI.dialogs.addActivity.find('.start-time, .end-time').addClass('hidden') :
-    UI.dialogs.addActivity.find('.start-time, .end-time').removeClass('hidden'); 
-});
-		
-var tabs = UI.dialogs.addActivity.children('.content').tabs({
-	select: function(event, ui) { 
-		if ($('.qtip.qtip-blue.qtip-active').length)
-			$('.qtip.qtip-blue.qtip-active').qtip('destroy');
-	}	
-	});
-
-var group = DataLayer.get('calendar', objActivity.group);
-				
-if (group.timezone != objActivity.timezone){
-    UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').find('option[value="'+objActivity.timezone+'"]').attr('selected','selected').trigger('change');
-    UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').addClass('hidden');
-    $('.group-addevent-details-txt-timezone').removeClass('hidden');
-			
-}
-
-UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').click(function(e){
-    $(this).addClass('hidden');
-    $('.group-addactivity-details-txt-timezone').removeClass('hidden');
-    e.preventDefault();
-});
-
-UI.dialogs.addActivity.find('.button.remove').button({
-    text:false, 
-    icons:{
-	primary:'ui-icon-close'
-    }
-}).click(function(el){
-    var id;
-    if( id = $(this).parent().find('input[name="alarmId[]"]').val())
-	DataLayer.remove('alarm', id);
-    $(this).parent().remove().find('li').is(':empty');
-});
-
-UI.dialogs.addActivity.find('.button-add-alarms').click(function(){
-            DataLayer.render( 'templates/alarms_add_itemlist.ejs', {type: 0}, function( template ){                     
-            jQuery('.activity-alarms-list').append(template)
-            .find('li:last label:eq(0)').remove().end()
-            .find('.number').numeric().end()
-            .find('.button.remove').button({
-                text:false, 
-                icons:{
-                    primary:'ui-icon-close'
-                }
-            }).click(function(el) {
-                $(this).parent().remove();
-            });    
-            });
-        });
-
-/*Seleciona a agenda padrão para visualização/edição de um evento*/
-if(objActivity.id)
-    UI.dialogs.addActivity.find('select[name="group"] option[value="'+objActivity.group+'"]').attr('selected','selected').trigger('change');
-
-UI.dialogs.addActivity.find('.button').button();
-    UI.dialogs.addActivity.find('.button.add').button({
-        icons: {
-    	   secondary: "ui-icon-plus"
-        }
-});
-
-todoStatus('addActivity', (objActivity.activityStatus != undefined) ? objActivity.activityStatus : 1);
-
-UI.dialogs.addActivity.find('select[name="activityStatus"]').attr('disabled', 'disabled');
-
-// ==== validation events ====
-UI.dialogs.addActivity.find(".input-group .h1").Watermark("Atividade sem título");
-
-UI.dialogs.addActivity.find(".number").numeric();
-
-User.preferences.dateFormat.indexOf('-') > 0 ? 
-UI.dialogs.addActivity.find(".date").mask("99-99-9999", {
-    completed:function(){
-	updateMap();
-    }
-}) : 
-
-UI.dialogs.addActivity.find(".date").mask("99/99/9999", {
-    completed:function(){
-	updateMap();
-    }
-});
-
-UI.dialogs.addActivity.find(".menu-addactivity")
-.children(".delete").click(function(){
-    $.Zebra_Dialog('Tem certeza que deseja excluir a atividade?', {
-	'type':     'question',
-	'overlay_opacity': '0.5',
-	'buttons':  ['Sim', 'Não'],
-	'onClose':  function(clicked) {
-	    if(clicked == 'Sim'){
-		canDiscardActivityDialog = true;
-		/* Remove por filtro */
-		DataLayer.removeFilter('schedulable', {filter: ['AND', ['=', 'id', objActivity.id], ['=', 'calendar', objActivity.group], ['=','user',(objActivity.me.user ? objActivity.me.user.id : objActivity.me.id)], ['=', 'type', '2']]});
-		Calendar.rerenderView(true);
-		/********************/
-		UI.dialogs.addActivity.dialog("close");
-	    }
-	}
-    });
-}).end()
-	    
-.children(".cancel").click(function(){
-    UI.dialogs.addActivity.dialog("close");
-}).end()
-	    
-.children(".save").click(function(){
-    /* Validação 
-    var msg = false;			
-    if(msg = validDateEvent()){
-    	$(".new-activity-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); 
-    	return false;
-    }
-    */
-	UI.dialogs.addActivity.find('select[name="activityStatus"]').removeAttr('disabled');
-    canDiscardActivityDialog = true;
-			
-	UI.dialogs.addActivity.children().find('form.form-addactivity').submit();
-	UI.dialogs.addActivity.dialog("close");
-
-}).end()
-		
-.children(".export").click(function(){
-    UI.dialogs.addActivity.children().find(".form-export").submit();
-});
-
-var task_activityHtml = DataLayer.render( path+'templates/task_activity_add.ejs', {	activity: objActivity});
-var blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8').append(task_activityHtml);
-
-var dates = UI.dialogs.addActivity.find('input.date').datepicker({
-    dateFormat: User.preferences.dateFormat.replace(/M/g, 'm').replace(/yyyy/g, 'yy'),
-    onSelect : function( selectedDate ){
-	updateMap();
-    }
-});
-
-blkAddTask.find('.add-activity-search .ui-icon-search').click(function(event) {
-    blkAddTask.find('.add-activity-search input').keydown();
-});
-			
-			
-blkAddTask.find('.add-activity-search input').keydown(function(event) {
-
-    if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') {	
-    // Fazer get das tarefas	
-	var filter = 
-        {
-            filter: 
-                ['AND',
-                    ['=', 'type', '2'], 
-                    ['>=','startTime', $.now()], 
-                    ['in', 'calendar', 
-                        [$('div.new-activity-win.active select[name="groupFilter"]').val()]
-                    ]
-                ], criteria: {'filterTasks': true}
-        };
-    if($(this).val() != ''){
-        filter['filter'].push(['OR',
-                            ["i*", "summary", $(this).val()], 
-                            ["i*", "description", $(this).val()]
-                           ]);
-    }
-
-    var result = DataLayer.get('schedulable:taskSearch', filter, true)
-	/**
-	* TODO: trocar por template
-	*/
-	blkAddTask.find('ul.search-result-list').empty().css('overflow', 'hidden');
-	if (!result) {
-	    blkAddTask.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>');
-	}else{
-    	for(i=0; i<result.length; i++)
-    	    result[i].enabled = (blkAddTask.find('dd.task-activity-list ul.task-activity-list input[value="' +  result[i].id + '"]').length) ? false : true;
-    											
-    	blkAddTask.find('ul.search-result-list').append(DataLayer.render( path+'templates/task_search_itemlist.ejs', result));
-
-        /* TODO - Verificar id da aitividade*/
-    	blkAddTask.find('ul.search-result-list li').click(function(event, ui){
-    	    if ($(event.target).is('input')) {
-                old_item = $(event.target).parents('li');
-
-                tasks[old_item.find('[name="id"]').val()] = {
-                    startDate: old_item.find('[name="taskStartDate"]').val(),
-                    startHour: old_item.find('[name="taskStartHour"]').val(),
-                    endDate: old_item.find('[name="taskEndDate"]').val(),
-                    endHour: old_item.find('[name="taskEndHour"]').val(),
-                    dueDate: old_item.find('[name="taskDueDate"]').val(),
-                    dueTime: old_item.find('[name="taskDueTime"]').val(),
-                    allDay: old_item.find('[name="taskAllDay"]').val(),
-                    percentage: old_item.find('[name="taskPercentage"]').val(),
-                    status: old_item.find('[name="taskStatus"]').val()
-                };
-
-                tasks.length += 1;
-        							
-		blkAddTask.find('dd.task-activity-list ul.task-activity-list')
-		    .append(DataLayer.render(path+'templates/task_add_itemlist.ejs', [{
-			idTask: old_item.find('[name="id"]').val(),
-        		    description: old_item.find('.description').html()
-			}]))
-        		.scrollTo('max');
-		callbackTask();
-                registerStatus();
-                blkAddTask.find('.not-activity').addClass('hidden');
-                old_item.remove();
-    	    }
-    	});
-    }
-    event.preventDefault();
-    }
-});
-
-/*Carrega as tarefas já existentes em uma atividade*/
-if(objActivity.tasks.length){
-    tasks = objActivity.tasks;
-
-    for(var i in objActivity.tasks){
-        if(i != 'length')
-            blkAddTask.find('dd.task-activity-list ul.task-activity-list')
-                .append(DataLayer.render(path+'templates/task_add_itemlist.ejs', [{
-                    idTask: i,
-                    description: tasks[i].description,
-                    idTaskToActivity: tasks[i].taskToActivity
-                 }]))
-            .scrollTo('max');
-    }
-
-    callbackTask();
-    registerStatus();
-    blkAddTask.find('.not-activity').addClass('hidden');
-}
-
-UI.dialogs.addActivity.find('.row.fileupload-buttonbar-activity .button').filter('.delete').button({
-    icons: {
-	   primary: "ui-icon-close"
-    },
-    text: 'Excluir'
-}).click(function () {
-    $.Zebra_Dialog('Tem certeza que deseja excluir todos anexos?', {
-	'type':     'question',
-	'overlay_opacity': '0.5',
-	'buttons':  ['Sim', 'Não'],
-	'onClose':  function(clicked) {
-	    if(clicked == 'Sim'){
-		
-                var ids = [];
-                $.each($('.attachment-list input'), function (i, input) {
-                     DataLayer.remove('schedulableToAttachment', {
-                        filter: ['=', 'id', ''+input.value]
-                        });
-                });
-                $('.attachment-list input').remove();
-                $('.row.fileupload-buttonbar-activity .attachments-list p').remove();
-            }
-        }});
-}).end()
-.filter('.close').button({
-    icons: {
-	   primary: "ui-icon-close"
-    },
-    text: false
-}).click(function () {
-    DataLayer.remove('schedulableToAttachment', $(this).parents('p').find('input[name="fileId[]"]').val());
-    $(this).parents('p').remove();
-}).end()
-.filter('.downlaod-archive').button({
-    icons: {
-	   primary: "ui-icon-arrowthickstop-1-s"
-    },
-    text: false
-});
-var maxSizeFile = 2000000;
-$('#fileuploadactivity').fileupload({
-    sequentialUploads: true,
-    add: function (e, data) {
-	if(data.files[0].size < maxSizeFile)
-	    data.submit();
-    },
-    change: function (e, data) {
-	$.each(data.files, function (index, file) {
-	    var attach = {};
-	    attach.fileName = file.name;
-	    var ext = file.name.split('.');
-	    if(file.name.length > 10)
-		attach.fileName = ext.length == 1 ? file.name.substr(0, 10) :  file.name.substr(0, 6) + '.' + ext[ext.length -1];
-	    attach.fileSize = formatBytes(file.size);
-	    if(file.size > maxSizeFile)
-		attach.error = 'Tamanho de arquivo nao permitido!!'
-				
-	    $('div.new-activity-win .attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', {
-		file : attach
-	    }));
-				
-	    if(file.size < maxSizeFile){
-		$('div.new-activity-win .fileinput-button.new').append(data.fileInput[0]).removeClass('new');
-		$('div.new-activity-win .attachments-list').find('[type=file]').addClass('hidden');
-					
-	    }else
-		$('div.new-activity-win .fileinput-button.new').removeClass('new');
-				
-				
-	    $('div.new-activity-win .attachments-list').find('.button.close').button({
-		icons: {
-		    primary: "ui-icon-close"
-		},
-		text: false
-	    }).click(function(){
-		var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
-		$('.attachment-list').find('input[value="'+idAttach+'"]')
-		$(this).parent().remove();
-	    });	
-				
-	})
-	},
-    done: function(e, data){
-    	var currentUpload = $('div.new-activity-win .progress.after-upload:first').removeClass('after-upload').addClass('on-complete').hide();
-
-    	if(!!data.result && data.result != "[]"){
-    	    var newAttach = (attch = jQuery.parseJSON(data.result)) ? attch : jQuery.parseJSON(data.result[0].activeElement.childNodes[0].data);
-    	    $('div.new-activity-win .attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>');
-    	    currentUpload.removeClass('on-complete').parents('p')
-    	    .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>')
-    	    .find('.status-upload').addClass('ui-icon ui-icon-check');
-    	}else
-    	    currentUpload.removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel');
-        }
-});
-$('.attachments-list .button').button();
-
-if(!!window.FormData)			
-$('#fileuploadactivity').bind('fileuploadstart', function () {
-    var widget = $(this),
-    progressElement = $('#fileupload-progress-activity').fadeIn(),
-    interval = 500,
-    total = 0,
-    loaded = 0,
-    loadedBefore = 0,
-    progressTimer,
-    progressHandler = function (e, data) {
-	loaded = data.loaded;
-	total = data.total;
-    },
-    stopHandler = function () {
-	widget
-	.unbind('fileuploadprogressall', progressHandler)
-	.unbind('fileuploadstop', stopHandler);
-	window.clearInterval(progressTimer);
-	progressElement.fadeOut(function () {
-	    progressElement.html('');
-	});
-    },
-    formatTime = function (seconds) {
-	var date = new Date(seconds * 1000);
-	return ('0' + date.getUTCHours()).slice(-2) + ':' +
-	('0' + date.getUTCMinutes()).slice(-2) + ':' +
-	('0' + date.getUTCSeconds()).slice(-2);
-    },
-    /* formatBytes = function (bytes) {
-            if (bytes >= 1000000000) {
-                return (bytes / 1000000000).toFixed(2) + ' GB';
-            }
-            if (bytes >= 1000000) {
-                return (bytes / 1000000).toFixed(2) + ' MB';
-            }
-            if (bytes >= 1000) {
-                return (bytes / 1000).toFixed(2) + ' KB';
-            }
-            return bytes + ' B';
-        },*/
-    formatPercentage = function (floatValue) {
-	return (floatValue * 100).toFixed(2) + ' %';
-    },
-    updateProgressElement = function (loaded, total, bps) {
-	progressElement.html(
-	    formatBytes(bps) + 'ps | ' +
-	    formatTime((total - loaded) / bps) + ' | ' +
-	    formatPercentage(loaded / total) + ' | ' +
-	    formatBytes(loaded) + ' / ' + formatBytes(total)
-	    );
-    },
-    intervalHandler = function () {
-	var diff = loaded - loadedBefore;
-	if (!diff) {
-	    return;
-	}
-	loadedBefore = loaded;
-	updateProgressElement(
-	    loaded,
-	    total,
-	    diff * (1000 / interval)
-	    );
-    };
-    widget
-    .bind('fileuploadprogressall', progressHandler)
-    .bind('fileuploadstop', stopHandler);
-    progressTimer = window.setInterval(intervalHandler, interval);
-});
-
-UI.dialogs.addActivity.find(':input').change(function(event){
-    if (event.keyCode != '27' && event.keyCode != '13')
-	canDiscardActivityDialog = false;
-}).keydown(function(event){
-    if (event.keyCode != '27' && event.keyCode != '13')
-	canDiscardActivityDialog = false;
-});
-
-UI.dialogs.addActivity.dialog('open');
-}
Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/task.helpers.js
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/task.helpers.js	(revision 6974)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/js/task.helpers.js	(revision 6977)
@@ -99,5 +99,5 @@
 }
 
-function taskDetails(objTask, decoded, path, isMail, repeat) {
+function taskDetails(objTask, decoded, path, isMail, repeat, isActivityView) {
 
     $('.qtip.qtip-blue').remove();
@@ -278,5 +278,5 @@
                                     canDiscardTaskDialog = true;
                                     /**
-                                     *Remoção dos anexos da task caso seja cancelado a ediçãoo
+                                     *Remoção dos anexos da task caso seja cancelado a edição
                                      */
                                     DataLayer.rollback();
@@ -487,9 +487,12 @@
         UI.dialogs.addTask.find('input[name="summary"]').focus();
 		
-		if (msg = validDateTask()) {
+	if (msg = validDateTask()) {
             $(".new-task-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg);
             return false;
         }
-		canDiscardTaskDialog = true;
+	canDiscardTaskDialog = true;
+	
+	if(isActivityView)
+	    updateActivity = true;
 
         UI.dialogs.addTask.children().find('form.form-addtask').submit();
Index: /sandbox/2.4.2-expresso1/prototype/modules/calendar/templates/task_add_itemlist.ejs
===================================================================
--- /sandbox/2.4.2-expresso1/prototype/modules/calendar/templates/task_add_itemlist.ejs	(revision 6974)
+++ /sandbox/2.4.2-expresso1/prototype/modules/calendar/templates/task_add_itemlist.ejs	(revision 6977)
@@ -2,5 +2,8 @@
     <div style="overflow:hidden; width:100%; display:table;">	
 	<div class="activity-options" style="float: right; margin: 0 10px 0 0;">
-	    <a class="button info activity-options-button-edit new ui-icon-notice">Informações</a>
+	    <%if(data[0].isWrite){%>
+		<a class="button edit activity-options-button-edit new ui-icon-pencil">Editar</a>
+	    <%}%>
+	    <a class="button info activity-options-button-notice new ui-icon-notice">Informações</a>
 	    <a class="button close new">Remover</a>
 	</div>	
