Index: /trunk/prototype/call.php
===================================================================
--- /trunk/prototype/call.php	(revision 6286)
+++ /trunk/prototype/call.php	(revision 6286)
@@ -0,0 +1,35 @@
+<?php
+
+/*
+ * Remove and Update by criteria 
+ */
+
+$data = $_POST;
+
+require_once "api/controller.php";
+
+Controller::addFallbackHandler(0, function($e) {
+	    throw $e;
+	});
+
+$result = array();
+foreach ($data as $concept => &$content) {
+    if (!is_array($content))
+	$content = array($content);
+
+    foreach ($content as $key => $value) {
+	$criteria = isset($value['filter']) ? isset($value['criteria']) ?
+			array_merge($value['criteria'], array('filter' => $value['filter'])) :
+			array('filter' => $value['filter']) :
+		$value['criteria'];
+
+	$service = ( isset($value['criteria']) && isset($value['criteria']['service']) ) ? $value['criteria']['service'] : false;
+
+	try {
+	    $result[$concept][] = Controller::call($value['method'], Controller::URI($concept, false, $service), false, $criteria);
+	} catch (Exception $e) {
+	    $result[$concept]['error'] = $e->getMessage();
+	}
+    }
+}
+echo json_encode($result);
Index: /trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6250)
+++ /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6286)
@@ -560,8 +560,7 @@
     public function deepnessReadParticipant( &$uri , &$result , &$criteria , $original ){
 	
-	
        if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0)
        {
-            if(isset($result['id']))
+            if(isset($result['id']) && isset($result['user']))
             {
 		$result['user'] = Controller::read( array( 'concept' => 'user' , 'id' => $result['user'] , 'service' => ( $result['isExternal'] == 1 ? 'PostgreSQL' : 'OpenLDAP' ) ) );
@@ -713,4 +712,29 @@
 	if (Config::module('useCaldav', 'expressoCalendar'))
 	    require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
+	
+	if(isset($criteria['filter']) && $criteria['filter'] && isset($criteria['filter'][1][2])){
+	    $idSchedulable = $criteria['filter'][1][2];
+	    $idCalendar = $criteria['filter'][2][2];
+	    
+	    if(!self::ownerSchedulable($idSchedulable)){
+		$isPermissionFromOwner = self::permissionFromCalendarSignature($idCalendar, $idSchedulable);
+		
+		if($isPermissionFromOwner){
+		    Controller::delete(array('concept' => 'schedulable', 'id' => $idSchedulable));
+
+		}else{
+		    $calendarsToSchedulable = self::schedulable2calendarToObject($idSchedulable);
+
+		    foreach($calendarsToSchedulable as $value)
+			if($value['calendar_id'] == $idCalendar){
+			    Controller::delete(array('concept' => 'calendarToSchedulable', 'id' => $value['calendar_to_calendar_object']));
+			    break;
+			}
+		}
+		return false;
+	    }
+
+	    $uri['id'] = $idSchedulable;
+	}
 
 	$calendarsToSchedulable = self::schedulable2calendarToObject($uri['id']);
@@ -973,4 +997,24 @@
     }
 
+    private static function permissionFromCalendarSignature($idCalendar, $idEvent) {
+	$signature = Controller::find(array('concept' => 'calendarSignature'), false, array( 'filter' => array('AND', array('=', 'calendar', $idCalendar), array('=', 'isOwner', '1')), 'deepness' => 2));
+	
+	$signature = is_array($signature) ? $signature[0] : $signature;
+
+	if($signature['user']['id'] == Config::me('uidNumber')){
+	    return false;
+	}else{
+	   $isOwner = Controller::find(array('concept' => 'participant'), array('id'), array('filter' =>
+		    array('AND',
+			array('=', 'isOrganizer', '1'),
+			array('=', 'user', $signature['user']['id']),
+			array('=', 'schedulable', $idEvent)
+			)));
+
+	return ( isset($isOwner[0]['id']) ) ? true : false;
+	}
+    }
+    
+    
     private static function ownerSchedulable($id) {
 
Index: /trunk/prototype/modules/calendar/js/calendar.contentMenu.js
===================================================================
--- /trunk/prototype/modules/calendar/js/calendar.contentMenu.js	(revision 5863)
+++ /trunk/prototype/modules/calendar/js/calendar.contentMenu.js	(revision 6286)
@@ -8,6 +8,5 @@
                 
 		var classes = $(this).attr('class').split(" ");
-		var idEvent = false;
-                var idRecurrence = false;
+		var idEvent = false, idRecurrence = false, idCalendar = false;
                 
 		//recupera o id do calendar eo id do evento para tratamento
@@ -19,14 +18,17 @@
                         idRecurrence = classes[i].replace(/[a-zA-Z-]+/g, '');
                         continue;
+                    }else if (classes[i].indexOf("calendar-id-") >= 0 ){
+                        idCalendar = classes[i].replace(/[a-zA-Z-]+/g, '');
+                        continue;
                     }
                 }
 
                 var schedulable = DataLayer.get('schedulable', idEvent);
-                
+
 		var isRecurrence = DataLayer.get('repeat', schedulable.repeat).frequency;
-		
+
 		var template = DataLayer.render( 'templates/menu_context_event.ejs', {event: schedulable.id ,
                     top: (event.clientY - 135), left: (event.clientX - 445), 
-                    signature: Calendar.signatureOf[schedulable.calendar],
+                    signature: Calendar.signatureOf[idCalendar],
                     calendars: Calendar.calendars, isRecurrence: isRecurrence == 'none' ? false : true,
                     idRecurrence: idRecurrence
Index: /trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- /trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 6198)
+++ /trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 6286)
@@ -1062,5 +1062,5 @@
 			    return (attendee.acl.indexOf('w') >= 0 || attendee.acl.indexOf('o') >= 0 ) ? {
 				selectable: true, 
-				className: 'fullcalendar-context-menu  event-id-'+idEvent+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '')
+				className: 'fullcalendar-context-menu  event-id-'+idEvent+' calendar-id-'+calendar.id+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '')
 				} : {
 				editable: false, 
@@ -1071,5 +1071,5 @@
 		    return {
 			editable: false, 
-			className: 'blocked-event-permision  fullcalendar-not-context-menu event-id-'+idEvent,  
+			className: 'blocked-event-permision  fullcalendar-not-context-menu event-id-'+idEvent+' calendar-id-'+calendar.id,  
 			selectable: true, 
 			disableDragging: isRecurrence
@@ -1082,6 +1082,6 @@
 			var returns = ""
 			returns += acl['write'] ? "" :  'blocked-event-permision ';
-			returns += acl['busy'] ? 'fullcalendar-not-context-menu ' : (acl['read']  ?  'fullcalendar-context-menu '+ idEvent + (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '') : '');
-			returns += 'event-id-'+idEvent;
+			returns += acl['busy'] ? 'fullcalendar-not-context-menu ' : (acl['read']  ?  'fullcalendar-context-menu '+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '') : '');
+			returns += 'event-id-'+idEvent+' calendar-id-'+calendar.id;
 			return returns;
 		    }				
Index: /trunk/prototype/modules/calendar/js/helpers.js
===================================================================
--- /trunk/prototype/modules/calendar/js/helpers.js	(revision 6209)
+++ /trunk/prototype/modules/calendar/js/helpers.js	(revision 6286)
@@ -780,5 +780,8 @@
 	    if(clicked == 'Sim'){
 		canDiscardEventDialog = true;
-		DataLayer.remove( "schedulable", UI.dialogs.addEvent.find(".id-event").val() );
+		/* Remove por filtro */
+		DataLayer.removeFilter('schedulable', {filter: ['AND', ['=', 'id', objEvent.id], ['=', 'calendar', objEvent.calendar]]});
+		Calendar.rerenderView(true);
+		/********************/
 		UI.dialogs.addEvent.dialog("close");
 	    }
@@ -1905,5 +1908,5 @@
 }
 
-function remove_event(eventId){
+function remove_event(eventId, idCalendar){
     $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', {
 	'type':     'question',
@@ -1912,6 +1915,6 @@
 	'onClose':  function(clicked) {
 	    if(clicked == 'Sim'){
-		DataLayer.remove('schedulable', ''+eventId);
-		DataLayer.commit();
+		DataLayer.removeFilter('schedulable', {filter: ['AND', ['=','id',eventId], ['=','calendar',idCalendar]]})
+		Calendar.rerenderView(true);
 	    }
 	}
Index: /trunk/prototype/modules/calendar/templates/menu_context_event.ejs
===================================================================
--- /trunk/prototype/modules/calendar/templates/menu_context_event.ejs	(revision 5746)
+++ /trunk/prototype/modules/calendar/templates/menu_context_event.ejs	(revision 6286)
@@ -12,8 +12,8 @@
 			<li role="menuitem" class="menu-item"><a href="../prototype/modules/calendar/export.php?event=<%=data.event%>" class="ui-corner-all">Exportar</a></li>
 			 <%if(data.isRecurrence){%>
-                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>);" class="ui-corner-all">Remover repetição</a></li>
+                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>, <%= signature.calendar.id %>);" class="ui-corner-all">Remover repetição</a></li>
                                 <li role="menuitem" class="menu-item"><a href="#" onclick="remove_ocurrence(<%= data.event%>, <%= data.idRecurrence%>);" class="ui-corner-all">Remover ocorrência</a></li>
                             <%}else{%>
-                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>);" class="ui-corner-all">Remover</a></li>
+                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>, <%= signature.calendar.id %>);" class="ui-corner-all">Remover</a></li>
                             <%}%>
 		<%}else{%>
@@ -25,8 +25,8 @@
 			<%if(signature.permission.acl['write'] || signature.permission.acl['remove']){%>
                             <%if(data.isRecurrence){%>
-                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>);" class="ui-corner-all">Remover repetição</a></li>
+                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>, <%= signature.calendar.id %>);" class="ui-corner-all">Remover repetição</a></li>
                                 <li role="menuitem" class="menu-item"><a href="#" onclick="remove_ocurrence(<%= data.event%>, <%= data.idRecurrence%>);" class="ui-corner-all">Remover ocorrência</a></li>
                             <%}else{%>
-                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>);" class="ui-corner-all">Remover</a></li>
+                                <li role="menuitem" class="menu-item"><a href="#" onclick="remove_event(<%= data.event%>, <%= signature.calendar.id %>);" class="ui-corner-all">Remover</a></li>
                             <%}%>
 			<%}%>
Index: /trunk/prototype/api/datalayer.js
===================================================================
--- /trunk/prototype/api/datalayer.js	(revision 6008)
+++ /trunk/prototype/api/datalayer.js	(revision 6286)
@@ -554,4 +554,32 @@
 	if( oneSide )
 	    this.commit( concept, ids );
+
+	this.broadcast( concept, oneSide ? 'server' : bothSides ? 'serverclient' : 'client', false );
+    },
+    
+    /*
+     * RemoveFilter = método para remoção de objetos por critério, funcionalidade não implementada no método remove
+     * TODO - A remoção é feira em tempo real, onde ainda o mesmo não suporta remoção apenas na camada do cliente
+     * caso necessária tao funcionalidade a mesma será implementada no futuro
+     **/
+    removeFilter: function( concept, filter, oneSide ){
+	//remover
+	oneSide = true;
+
+	if(filter)
+	    filter = this.criteria(concept, filter);
+	else
+	    return;
+	
+	if ( $.type(filter) === "array" )
+	    filter = { filter: filter, criteria: false };
+
+	var toRemove = {};
+
+	toRemove[concept] = [];
+	
+	toRemove[concept][toRemove[concept].length] = {filter: filter.filter, criteria: filter.criteria, method: 'delete'};
+
+	this.dispatch( 'call', toRemove, false, true );
 
 	this.broadcast( concept, oneSide ? 'server' : bothSides ? 'serverclient' : 'client', false );
Index: /trunk/prototype/post.php
===================================================================
--- /trunk/prototype/post.php	(revision 6071)
+++ /trunk/prototype/post.php	(revision 6286)
@@ -8,27 +8,29 @@
 if( count($_FILES) )
 {
-	$files = array();
-	foreach( $_FILES as $name => $file )
+    $files = array();
+    foreach( $_FILES as $name => $file )
+    {
+	if( is_array( $file['name'] ) )
 	{
-		if( is_array( $file['name'] ) )
-		{
-			foreach( $file['name'] as $key => $value ){
-				$counter = count($files);
-				$files[$name.$counter] = array('name' => $file['name'][$counter], 
-					'type' => $file['type'][$counter],
-					'source' => base64_encode(file_get_contents( $file['tmp_name'][$counter], $file['size'][$counter])),
-					'size' => $file['size'][$counter],
-					'error' => $file['error'][$counter]
-				);
-			}
-		}else
-			$files[$name] = $file;
-	} 
-	
-	$_FILES = $files;	
+	    foreach( $file['name'] as $key => $value ){
+		$counter = count($files);
+		$files[$name.$counter] = array('name' => $file['name'][$counter], 
+			'type' => $file['type'][$counter],
+			'source' => base64_encode(file_get_contents( $file['tmp_name'][$counter], $file['size'][$counter])),
+			'size' => $file['size'][$counter],
+			'error' => $file['error'][$counter]
+		);
+	    }
+	}else
+	    $files[$name] = $file;
+    } 
+
+    $_FILES = $files;	
+
+
+    if(isset($data['MAX_FILE_SIZE']))
+	unset($data['MAX_FILE_SIZE']);	
 }
 
-if(isset($data['MAX_FILE_SIZE']))
-	unset($data['MAX_FILE_SIZE']);
 	
 require_once "api/controller.php";
