Index: /trunk/prototype/modules/mail/js/followupflag.js
===================================================================
--- /trunk/prototype/modules/mail/js/followupflag.js	(revision 7760)
+++ /trunk/prototype/modules/mail/js/followupflag.js	(revision 7780)
@@ -69,119 +69,126 @@
 
 	winElement.find('.button').button()
+	
 	.filter('.menu-configure-followupflag .cancel').click(function(){
 		winElement.dialog("close");
+		$.each(selectedMessageIds, function(index, value){	
+			$('tr#' + value + ' .td-followup-flag').find('img').remove();
+		});
+		
 	}).end()
 	
 	.filter('.menu-configure-followupflag .save').click(function(){	
-	var saveFollowupflagged = function(){
-		var idFollowupflagged = winElement.find('[name="followupflagId"]').val();
+		var saveFollowupflagged = function(){
+			var idFollowupflagged = winElement.find('[name="followupflagId"]').val();
 			idFollowupflagged = idFollowupflagged.split(',');
-			for(x=0; x<idFollowupflagged.length; x++){
+			for (x=0; x<idFollowupflagged.length; x++){
 				(idFollowupflagged[x] == "false") ? idFollowupflagged[x] = false : idFollowupflagged;
 			}
-		for(i=0; i<selectedMessageIds.length; i++){
-				var isDone = winElement.find('[name="done"]').is(':checked') ? 1 : 0;
-				var alarmDate = false;
-				var doneDate  = false;
-				var folder_name;
-				var folders = [];
-				var messages = [];
-				var roles = get_selected_messages_search_role().split(',');
-				for (var i=0; i < selectedMessageIds.length; i++ ){
-					if (currentTab == 0) {
-						folder_name = current_folder;
-						var messageNumber = selectedMessageIds[i];
-					}else{
-						var tr = $('[role="'+roles[i]+'"]');
-						folder_name = $(tr).attr('name'); 
-						var id = $(tr).attr('id'); 
-						var messageNumber = id.replace(/_[a-zA-Z0-9]+/,"");
-					}
-					folders.push(folder_name);
-					
-						var followupflagged = DataLayer.merge({
-							uid : User.me.id,
-							followupflagId : followupflagId, 
-							folderName : folder_name, 
-							messageNumber : messageNumber,
-							isDone: isDone,
-							isSent: 0,
-							backgroundColor : backgroundColor
-						}, !!idFollowupflagged[i] ? {id: idFollowupflagged[i]} : {});
-					
-					if (alarmDate = winElement.find('[name="alarmDate"]').datepicker("getDate")) {
-						if (alarmTime = winElement.find('[name="alarmTime"]').datepicker("getDate")) {
-							alarmDate.set({hour:alarmTime.getHours(), minute:alarmTime.getMinutes()});
+			for(i=0; i<selectedMessageIds.length; i++){
+					var isDone = winElement.find('[name="done"]').is(':checked') ? 1 : 0;
+					var alarmDate = false;
+					var doneDate  = false;
+					var folder_name;
+					var folders = [];
+					var messages = [];
+					var roles = get_selected_messages_search_role().split(',');
+					for (var i=0; i < selectedMessageIds.length; i++ ){
+						if (currentTab == 0) {
+							folder_name = current_folder;
+							var messageNumber = selectedMessageIds[i];
+						}else{
+							var tr = $('[role="'+roles[i]+'"]');
+							folder_name = $(tr).attr('name'); 
+							var id = $(tr).attr('id'); 
+							var messageNumber = id.replace(/_[a-zA-Z0-9]+/,"");
 						}
-						followupflagged.alarmDeadline = alarmDate.toString('yyyy-MM-dd HH:mm:ss');
-					}
-
-					if (doneDate = winElement.find('[name="doneDate"]').datepicker("getDate")) {
-						if (doneTime = winElement.find('[name="doneTime"]').datepicker("getDate")) {
-							doneDate.set({hour:doneTime.getHours(), minute:doneTime.getMinutes()});
+						folders.push(folder_name);
+						
+							var followupflagged = DataLayer.merge({
+								uid : User.me.id,
+								followupflagId : followupflagId, 
+								folderName : folder_name, 
+								messageNumber : messageNumber,
+								isDone: isDone,
+								isSent: 0,
+								backgroundColor : backgroundColor
+							}, !!idFollowupflagged[i] ? {id: idFollowupflagged[i]} : {});
+						
+						if (alarmDate = winElement.find('[name="alarmDate"]').datepicker("getDate")) {
+							if (alarmTime = winElement.find('[name="alarmTime"]').datepicker("getDate")) {
+								alarmDate.set({hour:alarmTime.getHours(), minute:alarmTime.getMinutes()});
+							}
+							followupflagged.alarmDeadline = alarmDate.toString('yyyy-MM-dd HH:mm:ss');
 						}
-						followupflagged.doneDeadline = doneDate.toString('yyyy-MM-dd HH:mm:ss');
+
+						if (doneDate = winElement.find('[name="doneDate"]').datepicker("getDate")) {
+							if (doneTime = winElement.find('[name="doneTime"]').datepicker("getDate")) {
+								doneDate.set({hour:doneTime.getHours(), minute:doneTime.getMinutes()});
+							}
+							followupflagged.doneDeadline = doneDate.toString('yyyy-MM-dd HH:mm:ss');
+						}
+						
+						/**
+						 * Aplica o ícone correspondente na lista de mensagens do expressoMail
+						 */
+						if(current_folder == folder_name){
+							var flagged = $('#td_message_followup_' + messageNumber + ', tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).find(".flag-edited");
+						} else{
+							var flagged = $('tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).find(".flag-edited");
+						}
+						if(isDone){
+							flagged.find("img").attr("src", "../prototype/modules/mail/img/flagChecked.png").css("margin-left","-3px");
+						}else{
+							flagged.css({"background-image":"url(../prototype/modules/mail/img/flagEditor.png)"});			
+						}
+						
+						var followupflagName = winElement.find('[name="name"] option:selected').text();
+						if(current_folder == folder_name){
+							$('#td_message_followup_' + messageNumber + ', ' + 
+							'tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).attr('title', followupflagName).find(".flag-edited").css("background", backgroundColor); 
+						}else{
+							$('tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).attr('title', followupflagName).find(".flag-edited").css("background", backgroundColor); 
+						}  
+						/**
+						 * Salva ou, caso já exista, atualiza
+						 */
+						DataLayer.put('followupflagged', followupflagged);
 					}
 					
-					/**
-					 * Aplica o ícone correspondente na lista de mensagens do expressoMail
-					 */
-					if(current_folder == folder_name){
-						var flagged = $('#td_message_followup_' + messageNumber + ', tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).find(".flag-edited");
-					} else{
-						var flagged = $('tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).find(".flag-edited");
-					}
-					if(isDone){
-						flagged.find("img").attr("src", "../prototype/modules/mail/img/flagChecked.png").css("margin-left","-3px");
-					}else{
-						flagged.css({"background-image":"url(../prototype/modules/mail/img/flagEditor.png)"});			
-					}
+					DataLayer.commit(false, false, function(data){
+						winElement.find('.menu-configure-followupflag .delete').button("option", "disabled", false);
+						updateCacheFollowupflag(selectedMessageIds, folders, true);
+						winElement.dialog("close");
+						alarmFollowupflagged('followupflagAlarms');
+						var fail = 'success';
+						$.each(data,function(index,value){
+							if (typeof value == 'string'){
+								fail = value;
+							}				
+						});
+						if (fail == '#FollowupflagMessageIdError'){
+							 alert('Uma ou mais mensagens não puderam ser sinalizadas. \nDetalhes do erro: mensagem não contém o atributo message-id.');
+						}
+						else if (fail == '#FollowupflagLimitError'){
+							 alert('Uma ou mais mensagens não puderam ser sinalizadas. \nDetalhes do erro: limite de flags atingido para esta pasta.');	
+						}
+						$.each(selectedMessageIds,function(index,value){	
+							var flagged = DataLayer.get('followupflagged', {filter: [
+								'AND', 
+								['=', 'messageNumber', value], 
+								['=', 'folderName', folder_name]
+							]});
+							if (!flagged)
+								$('#td_message_followup_'+value).find(".flag-edited").css("background","#cccccc").find('img').remove();
+							
+							$('tr#' + value + ' .td-followup-flag').find('img').remove();
+						});					
+					});
+					winElement.find('.menu-configure-followupflag .save').button("option", "disabled", true);
 					
-					var followupflagName = winElement.find('[name="name"] option:selected').text();
-					if(current_folder == folder_name){
-						$('#td_message_followup_' + messageNumber + ', ' + 
-						'tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).attr('title', followupflagName).find(".flag-edited").css("background", backgroundColor); 
-					}else{
-						$('tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).attr('title', followupflagName).find(".flag-edited").css("background", backgroundColor); 
-					}  
-					/**
-					 * Salva ou, caso já exista, atualiza
-					 */
-					DataLayer.put('followupflagged', followupflagged);
-				}
-				
-				DataLayer.commit(false, false, function(data){
-					winElement.find('.menu-configure-followupflag .delete').button("option", "disabled", false);
-					updateCacheFollowupflag(selectedMessageIds, folders, true);
-					winElement.dialog("close");
-					alarmFollowupflagged('followupflagAlarms');
-					var fail = 'success';
-					$.each(data,function(index,value){
-						if (typeof value == 'string'){
-							fail = value;
-						}				
-					});
-					if (fail == '#FollowupflagMessageIdError'){
-						 alert('Uma ou mais mensagens não puderam ser sinalizadas. \nDetalhes do erro: mensagem não contém o atributo message-id.');
-					}
-					else if (fail == '#FollowupflagLimitError'){
-						 alert('Uma ou mais mensagens não puderam ser sinalizadas. \nDetalhes do erro: limite de flags atingido para esta pasta.');	
-					}
-					$.each(selectedMessageIds,function(index,value){	
-			 			var flagged = DataLayer.get('followupflagged', {filter: [
-							'AND', 
-							['=', 'messageNumber', value], 
-							['=', 'folderName', folder_name]
-						]});
-				 		if (!flagged)
-				 			$('#td_message_followup_'+value).find(".flag-edited").css("background","#cccccc");
-				 	});					
-				});
-				winElement.find('.menu-configure-followupflag .save').button("option", "disabled", true);
-				
-		
-		}
-		selectAllFolderMsgs(false);
-    }
+			
+			}
+			selectAllFolderMsgs(false);
+		}
 		winElement.find('[name="name"]').next().data("autocomplete")._trigger("change");
 		var backgroundColor = winElement.find('[name="backgroundColor"]').val();
@@ -239,5 +246,5 @@
 					
 					if(current_folder == folder_name){
-						$('#td_message_followup_' + messageNumber + ', ' + 
+						flag = $('#td_message_followup_' + messageNumber + ', ' + 
 						  'tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).attr('title', '').find(".flag-edited").css("background", '#CCC');
 						$('#td_message_followup_' + messageNumber + ', ' + 
@@ -245,5 +252,5 @@
 							.css({"background-image":"url(../prototype/modules/mail/img/flagEditor.png)"});
 					}else{
-						$('tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).attr('title', '').find(".flag-edited").css("background", '#CCC');
+						flag = $('tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).attr('title', '').find(".flag-edited").css("background", '#CCC');
 						$('tr[role="'+messageNumber+'_'+folder_name+'"] #td_message_followup_search_' + messageNumber).find(".flag-edited")
 							.css({"background-image":"url(../prototype/modules/mail/img/flagEditor.png)"});
@@ -252,10 +259,20 @@
 				}
 			}
+			
+			
 		}
 		DataLayer.commit(false, false, function(){
 			winElement.dialog("close");
 			alarmFollowupflagged('followupflagAlarms');
+			
+			$.each(selectedMessageIds, function(index, value){	
+				$('tr#' + value + ' .td-followup-flag').find('img').remove();
+			});
+			
+			selectAllFolderMsgs(false);	
 		});
-		selectAllFolderMsgs(false);
+
+
+			
 	});
 	
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 7774)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 7780)
@@ -2219,8 +2219,14 @@
 				$('#td_message_followup_' + messageClickedId + ', ' + 
 				'tr[role="'+messageClickedId+'_'+msg_folder+'"] #td_message_followup_search_' + messageClickedId).find(".flag-edited")
-				.css({"background-image":"url(../prototype/modules/mail/img/flagEditor.png)"});
-				$('#td_message_followup_' + messageClickedId + ', ' + 
-				'tr[role="'+messageClickedId+'_'+msg_folder+'"] #td_message_followup_search_' + messageClickedId).find(".flag-edited").css("background", followupColor);
+				.css({"background-image":"url(../prototype/modules/mail/img/flagEditor.png)"}).css("background", followupColor);
+				
 				$(tr_element).addClass('selected_msg').find(':checkbox').trigger('click');
+				
+				/**
+				 * Hack - Força a atualização da seleção da mensagem, devido a problema na 
+				 * function de seleção atribuida ao evento onclick do checkbox
+				 */
+				updateSelectedMsgs(true,messageClickedId);
+				
 				configureFollowupflag();
 			}
