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 6903)
+++ sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.codecs.js	(revision 6945)
@@ -799,5 +799,214 @@
         };
     });
-
+    return (notArray ? res[0] : res);
+    }
+});
+
+DataLayer.codec( "schedulable", "taskSearch", {
+
+    decoder: function( evtObj ){
+
+    },
+
+    encoder: function( evtObj ){
+
+    var notArray = false;
+      
+    if( notArray = $.type(evtObj) !== "array" )
+        evtObj = [ evtObj ];
+
+    var res = $.map(evtObj, function( objEvent ){           
+            
+        if(!(typeof(objEvent) == 'object'))
+            return (null);
+
+        return {
+            id: objEvent.id,
+            description: !!objEvent.summary ? objEvent.summary : objEvent.description,
+            startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
+            startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat),
+            endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0)  ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
+            endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)),  objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat),
+            dueDate: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : new Date( parseInt(objEvent.due) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
+            dueTime: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.due)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat),
+            allDay: !!parseInt( objEvent.allDay ),
+            percentage: (objEvent.percentage) ? objEvent.percentage : '0'
+        }
+    });
+    return (notArray ? res[0] : res);
+    }
+});
+
+DataLayer.codec( "schedulable", "activity", {
+
+    decoder: function( evtObj ){
+    Encoder.EncodeType = "entity";
+    
+    if( notArray = $.type(evtObj) !== "array" )
+        evtObj = [ evtObj ];
+
+    var pref = User.preferences;
+
+    var res = $.map(evtObj, function( form ){
+    
+        var tzId =  form.timezone || Calendar.signatureOf[form.group].calendar.timezone || User.preferences.timezone,
+
+        formatString = pref.dateFormat + " " + pref.hourFormat;
+
+	var decodeParticipants = function(attend){
+	    return [DataLayer.merge(
+		{  
+		    user: User.me.id, 
+		    isOrganizer: 1,
+		    acl: 'row',
+		    alarms: $.map( form.alarmTime || [], function( alarmTime, i ){
+			if( alarmTime === "" )
+			    return( null );
+			return !!form.alarmId[i] ? {
+			    type: form.alarmType[i], 
+			    unit: form.alarmUnit[i], 
+			    time: form.alarmTime[i], 
+			    id: form.alarmId[i]
+			    }:
+
+			    {
+			    type: form.alarmType[i],
+			    unit: form.alarmUnit[i], 
+			    time: form.alarmTime[i]
+			    };
+		    })
+		}, attend != '0' ? {id: attend} : {})];
+	};
+
+        return DataLayer.merge({
+        "class": form["class"],
+        startTime: Date.parseExact(form.startDate + " "+$.trim(form.startHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'),
+        endTime:  Date.parseExact(form.endDate + " "+$.trim(form.endHour), formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'),  //+ (!!form.allDay ? 86400000 : 0) ,
+        due: (form.dueDate == '' )? 0 : Date.parseExact(form.dueDate + " "+$.trim(form.dueHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'),
+        allDay: ( !!form.allDay ? 1 : 0 ),      
+        status: form.taskStatus,      
+        id: form.idActivity,
+        type: !!form.type ?  form.type : 2,
+        percentage: form.percentage,
+        priority: form.priority,
+        category: form.category,
+        summary: form.summary,
+        description: form.description,
+        timezone: tzId,
+        attachments: $.map(form.attachment || [], function( attachment, i ){
+            return {
+            attachment: attachment
+            }
+        }),
+        participants: decodeParticipants(form.idAttendee),
+        taskToActivity:$.map( form.idtask || [], function( task, i ){
+
+            return DataLayer.merge({
+                task: task,
+                owner: User.me.id
+            }, form.idTaskToActivity[i] != '' ? {id: form.idTaskToActivity[i]} : {});
+
+        })
+        }, form.lastGroup ? (( form.lastGroup == form.group ) ? {} : {calendar: form.group, lastGroup: form.lastGroup}) : {calendar: form.group});
+    });
+
+    return notArray ? res[0] : res;
+    },
+
+    encoder: function( evtObj ){
+
+    var notArray = false;
+      
+    if( notArray = $.type(evtObj) !== "array" )
+        evtObj = [ evtObj ];
+    
+    var res = $.map(evtObj, function( objEvent ){           
+            
+        if(!(typeof(objEvent) == 'object'))
+            return (null);
+
+        var decodeTasks = function(obj){
+
+            var tasks = {}, task = {};
+
+            for(var i =0; i < obj.taskToActivity.length; i++){
+
+                taskToActivity = DataLayer.get('taskToActivity', obj.taskToActivity[i]); 
+                task = taskToActivity.task;
+
+                if($.type(task) != 'object')
+                    task = DataLayer.get('schedulable', task);
+
+                tasks[task.id] = {
+                    taskToActivity: taskToActivity.id,
+                    allDay: !!parseInt(task.allDay),
+                    dueDate: (!task.due || task.due == '' || task.due == '0') ? '' : new Date( parseInt(task.due) ).setTimezoneOffset( Timezone.timezone( task.timezone ) ).toString( User.preferences.dateFormat ),
+                    dueTime: (!task.due || task.due == '' || task.due == '0') ? '' : dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(task.due)), task.timezone, obj.calendar, obj.DayLigth, 'startTime'), User.preferences.hourFormat),
+                    startDate: new Date( parseInt(task.startTime) ).setTimezoneOffset( Timezone.timezone( task.timezone ) ).toString( User.preferences.dateFormat ),
+                    startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(task.startTime)), task.timezone, task.calendar, obj.DayLigth, 'startTime'), User.preferences.hourFormat),
+                    endDate: new Date( parseInt(task.endTime) - (!!parseInt(task.allDay) ? 86400000 : 0)  ).setTimezoneOffset( Timezone.timezone( task.timezone ) ).toString( User.preferences.dateFormat ),
+                    endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(task.endTime)),  task.timezone, obj.calendar, obj.DayLigth, 'endTime'), User.preferences.hourFormat),
+                }
+
+                tasks[task.id].description = tasks[task.id].startDate + ' - ' + (!!task.summary ? task.summary : task.description);
+
+            }
+
+            tasks.length = obj.taskToActivity.length;
+            return tasks;
+
+        };
+
+        return {
+        "class": objEvent["class"],
+        id: objEvent.id,
+        location: objEvent.location,
+        category: objEvent.category,
+        activityStatus: objEvent.status,
+        groups: Calendar.groups,
+        group: objEvent.group ? objEvent.group : objEvent.calendar,
+        summary: objEvent.summary,
+        type: !!objEvent.type ? objEvent.type : 2,
+        description: objEvent.description,
+        timezone: objEvent.timezone,
+        timezones: Timezone.timezones,
+        percentage: (objEvent.percentage) ? objEvent.percentage : '0',
+        priority: objEvent.priority,
+        startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
+        startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat),
+        endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0)  ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
+        endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)),  objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat),
+        dueDate: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : new Date( parseInt(objEvent.due) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ),
+        dueTime: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.due)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat),
+        allDay: !!parseInt( objEvent.allDay ),
+        historic: [],
+        tasks: objEvent.taskToActivity ? decodeTasks(objEvent) : {},
+        attachments: $.map(objEvent.attachments || [], function( attachment, i ){
+            var attach = DataLayer.get('schedulableToAttachment', attachment, false);
+            //TODO - Verificar na API retorno de id sobre os conceitos em que s?o utilizados tabelas de liga??o
+            if(!attach.name) return(null); 
+            
+            var ext = attach.name.split('.');
+            attach.name = attach.name.length < 10 ?  attach.name : ( ext.length == 1 ? attach.name.substr(0, 10) : (attach.name.substr(0, 6) + '.' +  ext[ext.length -1]));
+            attach.size = formatBytes(attach.size);
+            return attach;
+        }),
+        me : User.me,
+        attendee: $.map(objEvent.participants || [], function( participant, i ){                        
+
+            var attend = DataLayer.get('participant', (participant.id || participant));
+            attend.user = DataLayer.get('user', attend.user);
+
+            return {
+                id: attend.id,
+                alarms : $.map(attend.alarms || [], function( alarm ){
+                    var alarm = DataLayer.get('alarm', alarm);
+                    return (alarm == "" ? (null) : alarm);
+                })
+            };
+        }),
+
+        };
+    });
     return (notArray ? res[0] : res);
     }
@@ -1089,5 +1298,5 @@
     
     if(!(!!evtObj))
-        return undefined;
+        evtObj = [];
 
     var notArray = false;
@@ -1314,18 +1523,21 @@
 
 	    //occurrences = DataLayer.unique( occurrences ).sort();
-		  
-	    for( var i = 0; i < occurrences.length; i++ )
-		grouped[ evt.calendar ].push( DataLayer.merge(
-		{
-		    id: evt.URI || evt.id+ '-' + i,
-		    title: Encoder.htmlDecode(evt.summary),
-		    start: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) ), calendar.timezone,  !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving),
-		    end:   Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) + duration - (!!parseInt(evt.allDay) ? 86400000 : 0)), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving),
-		    allDay: parseInt( evt.allDay ),
-		    isRepeat: isRepeat,
-		    occurrence: i,
-		    type: evt.type,
-		    calendar: evt.calendar
-		    }, eventEditable(evt.id, isRepeat, i ) ) );
+		var typeEvent;  
+	    for( var i = 0; i < occurrences.length; i++ ){
+
+            typeEvent = (evt.type == 2 && evt.taskToActivity ? 3 : evt.type)
+    		grouped[ evt.calendar ].push( DataLayer.merge(
+    		{
+    		    id: evt.URI || evt.id+ '-' + i,
+    		    title: Encoder.htmlDecode(evt.summary),
+    		    start: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) ), calendar.timezone,  !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving),
+    		    end:   Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) + duration - (!!parseInt(evt.allDay) ? 86400000 : 0)), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving),
+    		    allDay: parseInt( evt.allDay ),
+    		    isRepeat: isRepeat,
+    		    occurrence: i,
+    		    type: typeEvent,
+    		    calendar: evt.calendar
+    		    }, (parseInt(typeEvent) == 1 ? eventEditable(evt.id, isRepeat, i ) : (parseInt(typeEvent) == 2 ? {editable: true, disableResizing: false, disableDragging: false} : {editable: false, disableResizing: true, disableDragging: true}) )) );
+        }
 	});
 
