Index: trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 7680)
+++ trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 7702)
@@ -73,8 +73,5 @@
 		    if( Calendar.currentViewKey !== viewKey ){
 			Calendar.currentViewKey = viewKey;
-			Calendar.currentView = DataLayer.get( 'schedulable:calendar', {
-			    start: start, 
-			    end: end
-			} );
+			Calendar.currentView =  DataLayer.encode('schedulable:calendar', DataLayer.dispatch('modules/calendar/schedules', DataLayer.criteria('schedulable:calendar', {start: start,end: end}))  );   //DataLayer.get( 'schedulable:calendar', {start: start,end: end} );
 		    }
 		    var view = Calendar.currentView[ signature.calendar.id ];
@@ -199,9 +196,12 @@
   
     if( status === 'serverclient' ){
-	DataLayer.commit( false, false, function(){	
+        DataLayer.commit( false, false, function(){
+            //Clean cache client after commit
+            DataLayer.remove('schedulable', false);
+
             Calendar.rerenderView(true);
-	    if(updateActivity)
-		refreshTaskActivity();
-	});
+            if(updateActivity)
+                refreshTaskActivity();
+        });
     }
 });
@@ -1337,8 +1337,8 @@
 function encodeRepeat( repeat ){
   
-    if( !repeat )
-	return( false );
+    if( !repeat || repeat == '0' )
+	    return( false );
     if(typeof(repeat) == "object")
-	return repeat;
+	    return repeat;
 
     return DataLayer.get( 'repeat', repeat );
@@ -1436,80 +1436,146 @@
 
     encoder: function( evtObj ){
-	if(!(!!evtObj))
-	    return undefined;
-
-	var notArray = false;
-		  
-	if( notArray = $.type(evtObj) !== "array" )
-	    evtObj = [ evtObj ];
-
-	var pref = User.preferences;
-    var res = [];
-
-    for(var i = 0; i < evtObj.length; i++){
-	   res.push(DataLayer.encode('schedulable:' + (evtObj[i].type == '1' ?  'preview' : ( !!evtObj[i].taskToActivity ? 'activity': 'task')) , evtObj[i]));
-    }
-
-	if( !notArray ){
-	    var dates = {};
-	    var typeRepeat = {
-		'none': false, 
-		'daily': 'Repetição diária',
-		'weekly': 'Repetição semanal',
-		'monthly': 'Repetição mensal',
-		'yearly': 'repetição anual'
+        if(!(!!evtObj))
+            return undefined;
+
+        var notArray = false;
+
+        if( notArray = $.type(evtObj) !== "array" )
+            evtObj = [ evtObj ];
+
+        var pref = User.preferences;
+        var res = [];
+
+        for(var i = 0; i < evtObj.length; i++){
+           res.push(DataLayer.encode('schedulable:' + (evtObj[i].type == '1' ?  'preview' : ( !!evtObj[i].taskToActivity ? 'activity': 'task')) , evtObj[i]));
+        }
+
+        if( !notArray ){
+            var dates = {};
+            var typeRepeat = {
+                'none': false,
+                'daily': 'Repetição diária',
+                'weekly': 'Repetição semanal',
+                'monthly': 'Repetição mensal',
+                'yearly': 'repetição anual'
+            }
+
+            for (var i=0; i < res.length; i++) {
+
+                res[i].type = (res[i].type == '2' && !!res[i].tasks) ? '3' : res[i].type;
+
+                var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat );
+                var endDate   = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat );
+
+                var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() );
+
+                var occurrences = [ startDate.getTime() ];
+
+                if( res[i].occurrences )
+                {
+                    occurrences = res[i].occurrences;
+                }
+
+                for( var ii = 0; ii < occurrences.length; ii++ )
+                {
+                    var currentDate = new Date( occurrences[ii] );
+                    var counter = currentDate.clone();
+
+                    res[i].startDate = currentDate.toString( User.preferences.dateFormat );
+                    res[i].endDate = new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat );
+
+                    if(res[i].repeat)
+                        res[i].repeat = typeRepeat[res[i].repeat.frequency];
+                }
+            }
 	    }
 
-	    for (var i=0; i < res.length; i++) {
-
-        res[i].type = (res[i].type == '2' && !!res[i].tasks) ? '3' : res[i].type;
-			  
-		var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat );
-		var endDate   = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat );
-			  
-		var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() );
-		
-		var occurrences = [ startDate.getTime() ];
-				
-		if( res[i].occurrences )
-		{
-		    occurrences = res[i].occurrences;
-		}
-
-		for( var ii = 0; ii < occurrences.length; ii++ )
-		{
-		    var currentDate = new Date( occurrences[ii] );
-		    var counter = currentDate.clone();
-				    
-		    var res2 = $.extend( {}, res[i], {
-			'startDate': currentDate.toString( User.preferences.dateFormat ), 
-			'endDate': new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat )
-			} );
-
-		    if(res[i].repeat)
-                res2.repeat = typeRepeat[res[i].repeat.frequency];
-				  
-		    while (counter.compareTo( currentDate ) == 0) {
-
-			if (!dates[counter.toString(User.preferences.dateFormat)]) 
-			    dates[counter.toString(User.preferences.dateFormat)] = {
-				startDate:false, 
-				events:[]
-			    };
-			if (!dates[counter.toString(User.preferences.dateFormat)].startDate) 
-			    dates[counter.toString(User.preferences.dateFormat)].startDate = counter.toString(User.preferences.dateFormat);
-
-			dates[counter.toString(User.preferences.dateFormat)].events.push(res2);
-			counter.addDays(-1);
-		    }      
-		}
-	    }
-	    res = {
-		events_list: dates,
-		count : res.length
-	    };
-	}
-
-	return notArray ? res[0] : res;
+	    return notArray ? res[0] : res;
+    }
+
+});
+
+DataLayer.codec( "schedulable", "list", {
+
+    decoder: function( evtObj ){},
+
+
+    encoder: function( evtObj ){
+        if(!(!!evtObj))
+            return undefined;
+
+        var notArray = false;
+
+        if( notArray = $.type(evtObj) !== "array" )
+            evtObj = [ evtObj ];
+
+        var pref = User.preferences;
+        var res = [];
+
+        for(var i = 0; i < evtObj.length; i++){
+            res.push(DataLayer.encode('schedulable:' + (evtObj[i].type == '1' ?  'preview' : ( !!evtObj[i].taskToActivity ? 'activity': 'task')) , evtObj[i]));
+        }
+
+        if( !notArray ){
+            var dates = {};
+            var typeRepeat = {
+                'none': false,
+                'daily': 'Repetição diária',
+                'weekly': 'Repetição semanal',
+                'monthly': 'Repetição mensal',
+                'yearly': 'repetição anual'
+            }
+
+            for (var i=0; i < res.length; i++) {
+
+                res[i].type = (res[i].type == '2' && !!res[i].tasks) ? '3' : res[i].type;
+
+                var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat );
+                var endDate   = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat );
+
+                var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() );
+
+                var occurrences = [ startDate.getTime() ];
+
+                if( res[i].occurrences )
+                {
+                    occurrences = res[i].occurrences;
+                }
+
+                for( var ii = 0; ii < occurrences.length; ii++ )
+                {
+                    var currentDate = new Date( occurrences[ii] );
+                    var counter = currentDate.clone();
+
+                    var res2 = $.extend( {}, res[i], {
+                        'startDate': currentDate.toString( User.preferences.dateFormat ),
+                        'endDate': new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat )
+                    } );
+
+                    if(res[i].repeat)
+                        res2.repeat = typeRepeat[res[i].repeat.frequency];
+
+                    while (counter.compareTo( currentDate ) == 0) {
+
+                        if (!dates[counter.toString(User.preferences.dateFormat)])
+                            dates[counter.toString(User.preferences.dateFormat)] = {
+                                startDate:false,
+                                events:[]
+                            };
+                        if (!dates[counter.toString(User.preferences.dateFormat)].startDate)
+                            dates[counter.toString(User.preferences.dateFormat)].startDate = counter.toString(User.preferences.dateFormat);
+
+                        dates[counter.toString(User.preferences.dateFormat)].events.push(res2);
+                        counter.addDays(-1);
+                    }
+                }
+            }
+            res = {
+                events_list: dates,
+                count : res.length
+            };
+        }
+
+        return notArray ? res[0] : res;
     }
 
@@ -1693,48 +1759,35 @@
 		
 		var taskEditable = function(idTask){
-			for(var i = 0; i < evt.participants.length; i++){
-				attendee = DataLayer.get('participant', evt.participants[i]);
-				if(attendee.user == User.me.id)
-					return attendee.isOrganizer == '1' ? 
-					{
-						editable: true, 
-						disableResizing: false, 
-						disableDragging: false,
-						className: 'fullcalendar-context-menu  event-type-2 event-id-'+idTask+' calendar-id-'+calendar.id
-					} 
-					: 
-					{
-						editable: false, 
-						disableResizing: true, 
-						disableDragging: true,
-						className: 'blocked-event-permision  fullcalendar-not-context-menu event-id-'+idTask
-					};
-			}
+
+            return evt.editable == '1' ?
+                {
+                    editable: true,
+                    disableResizing: false,
+                    disableDragging: false,
+                    className: 'fullcalendar-context-menu  event-type-2 event-id-'+idTask+' calendar-id-'+calendar.id
+                }
+                :
+                {
+                    editable: false,
+                    disableResizing: true,
+                    disableDragging: true,
+                    className: 'blocked-event-permision  fullcalendar-not-context-menu event-id-'+idTask
+                };
 		}
 		
 	    var eventEditable = function(idEvent, isRecurrence, Recurrence){
 			if(Calendar.signatureOf[calendar.id].isOwner == "1"){
-				var attendee = {};
-				for(var i = 0; i < evt.participants.length; i++){
-					attendee = DataLayer.get('participant', evt.participants[i]);
-					if(attendee.user == User.me.id)
-						return (attendee.acl.indexOf('w') >= 0 || attendee.acl.indexOf('o') >= 0 ) ? 
-						{
-							selectable: true, 
-							className: 'fullcalendar-context-menu  event-type-1 event-id-'+idEvent+' calendar-id-'+calendar.id+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '')
-						} : {
-							editable: false, 
-							selectable: true ,
-							className: 'blocked-event-permision  fullcalendar-not-context-menu event-id-'+idEvent
-						};
-				}
-				return {
-					editable: false, 
-					className: 'blocked-event-permision  fullcalendar-not-context-menu event-id-'+idEvent+' calendar-id-'+calendar.id,  
-					selectable: true, 
-					disableDragging: isRecurrence
-				};
-			}
-			else{
+
+                return (evt.editable == '1' ) ?
+                {
+                    selectable: true,
+                    className: 'fullcalendar-context-menu  event-type-1 event-id-'+idEvent+' calendar-id-'+calendar.id+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '')
+                } : {
+                    editable: false,
+                    selectable: true ,
+                    className: 'blocked-event-permision  fullcalendar-not-context-menu event-id-'+idEvent
+                };
+
+			}else{
 				var aclSignature = Calendar.signatureOf[calendar.id].permission;
 					
@@ -1799,37 +1852,20 @@
     criteria: function( filter ){
       
-	if( $.type(filter.start) !== 'date' )
-	    filter.start = new Date( filter.start * 1000 );
-	if( $.type(filter.end) !== 'date' )
-	    filter.end = new Date( filter.end * 1000 );
-
-	var timezone = {};
-	for(var i in Calendar.signatureOf)
-	    timezone[i] = Calendar.signatureOf[i].calendar.timezone;
-	
-	return {
-	    filter: ['AND', 
-			['OR',
-			    ['AND', 
-				['>=', 'rangeEnd', filter.start.getTime()], 
-				['<=', 'rangeEnd', filter.end.getTime()]
-			    ],
-			    ['AND', 
-				['>=', 'rangeStart', filter.start.getTime()], 
-				['<=', 'rangeStart', filter.end.getTime()]
-			    ],
-			    ['AND', 
-				['<=', 'rangeStart', filter.start.getTime()], 
-				['>=', 'rangeEnd', filter.end.getTime()]
-			    ]
-			],
-			['IN', 'calendar',  $.merge( Calendar.calendarIds, Calendar.groupIds )]
-		], 
-	    criteria: {
-		deepness: 2, 
-		timezones: timezone
-	    }
-	}
-}
+        if( $.type(filter.start) !== 'date' )
+            filter.start = new Date( filter.start * 1000 );
+        if( $.type(filter.end) !== 'date' )
+            filter.end = new Date( filter.end * 1000 );
+
+        var timezone = {};
+        for(var i in Calendar.signatureOf)
+            timezone[i] = Calendar.signatureOf[i].calendar.timezone;
+
+        return {
+            timezones: timezone,
+            rangeStart: filter.start.getTime(),
+            rangeEnd: filter.end.getTime(),
+            calendar: $.merge( [], Calendar.calendarIds, Calendar.groupIds )
+        }
+    }
 });
 
