Index: trunk/expressoMail1_2/js/doiMenuData.js
===================================================================
--- trunk/expressoMail1_2/js/doiMenuData.js	(revision 5497)
+++ trunk/expressoMail1_2/js/doiMenuData.js	(revision 5533)
@@ -8,29 +8,89 @@
 }
 
-$.contextMenu({
-	selector: ".table_box tbody tr",
-	callback: function(key, options) {
-		//TODO - default actions
-		//TODO - aply labels actions
-
-	},
-	items: {
-		"flagSeen":      {"name": get_lang("Mark as") + " " + get_lang('seen'), "icon": "seen", callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('seen','get_selected_messages'); }},
-		"flagUnseen":    {"name": get_lang("Mark as") + " " + get_lang('unseen'), "icon": "unseen", callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('unseen','get_selected_messages'); }},
-		"flagFlagged":   {"name": get_lang("Mark as") + " " + get_lang('important'), "icon": "important", callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('flagged','get_selected_messages'); }},
-		"flagUnflagged": {"name": get_lang("Mark as") + " " + get_lang('normal'), callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('unflagged','get_selected_messages'); }},
-		
-		
-		"sep2": "---------",
-		"move": {"name": get_lang("Move to")+"...", "icon": "move", callback: function(key, opt){ wfolders.makeWindow('', 'move_to'); }},
-		"remove": {"name": get_lang("Delete"),      "icon": "delete", callback: function(key, opt){ proxy_mensagens.delete_msgs('null','selected','null'); }},
-		"export": {"name": get_lang("Export"),      "icon": "export", callback: function(key, opt){ proxy_mensagens.export_all_messages(); }}
-	}
-});
-
 
 /**
- * Cria a lista de itens para o menu ferramentas
+ * Cria a lista de marcadores para o submenu "Marcadores"
  */
+function getLabels(){
+	var labels = DataLayer.get('label',{criteria:{order: 'name'}});
+	var menuLabelItems = {};
+	for(var i=0; i<labels.length; i++) {
+		menuLabelItems["label"+labels[i].id] = {
+			"name" : labels[i].name,
+		}
+	}
+	return menuLabelItems;
+}
+
+/**
+ *	Carrega o menu de opÃ§Ã£o de uma mensagem
+ */
+function loadMenu(){
+	var labelItems = getLabels();
+	$.contextMenu({
+		selector: ".table_box tbody tr",
+		callback: function(key, options) {
+			//TODO - default actions
+			
+			/** 
+			 * Aply labels to selected messages
+			 */
+			var isLabel = key.match(/label(.*)/);
+			if (isLabel && isLabel.length > 1) {
+				var label = {
+					id: isLabel[1]
+				}	
+				var lableleds = new Array();
+				
+				if(currentTab == 0){
+					var messages = get_selected_messages().split(',');
+				}else{
+					var messages = get_selected_messages_search().split(',');
+				}
+
+				for (var i=0; i < messages.length; i++) {
+					var hasLabel = DataLayer.get('labeled', [
+							'AND',
+							['=', 'labelId', label.id], 
+							['=', 'folderName', current_folder], 
+							['=', 'messageNumber', messages[i]]
+					]);
+					if (!hasLabel) {
+						lableleds.push(
+							DataLayer.put('labeled', {
+								labelId:label.id, 
+								folderName:current_folder, 
+								messageNumber:messages[i]
+							})
+						);
+						
+					}
+				}
+				DataLayer.commit();
+				for (var i=0; i < messages.length; i++) {
+					updateLabelsColumn({msg_number:messages[i], labels:false});
+				}
+			}
+		},
+		items: {
+			"flagSeen":      {"name": get_lang("Mark as") + " " + get_lang('seen'), "icon": "seen", callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('seen','get_selected_messages'); }},
+			"flagUnseen":    {"name": get_lang("Mark as") + " " + get_lang('unseen'), "icon": "unseen", callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('unseen','get_selected_messages'); }},
+			"flagFlagged":   {"name": get_lang("Mark as") + " " + get_lang('important'), "icon": "important", callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('flagged','get_selected_messages'); }},
+			"flagUnflagged": {"name": get_lang("Mark as") + " " + get_lang('normal'), callback: function(key, opt){ proxy_mensagens.proxy_set_messages_flag('unflagged','get_selected_messages'); }},
+			
+			"sep1": "---------",
+			"label": { "name": get_lang("Labels"), "items": labelItems},
+			"follouwpflag":{"name": get_lang("Follow up"), callback: function(key, opt){ configureFollowupflag(); } },
+			
+			"sep2": "---------",
+			"move": {"name": get_lang("Move to")+"...", "icon": "move", callback: function(key, opt){ wfolders.makeWindow('', 'move_to'); }},
+			"remove": {"name": get_lang("Delete"),      "icon": "delete", callback: function(key, opt){ proxy_mensagens.delete_msgs('null','selected','null'); }},
+			"export": {"name": get_lang("Export"),      "icon": "export", callback: function(key, opt){ proxy_mensagens.export_all_messages(); }}
+		}
+	});
+}
+/*FIM*/
+loadMenu();
+
 if (!expresso_offline) {
 	var menuToolsItems = {
@@ -40,6 +100,6 @@
 		"i04": {"name": get_lang("Edit folders"), "icon": "edit-folder", callback: folderbox },
 		"i05": {"name": get_lang("Share mailbox"), "icon": "share-mailbox", callback: sharebox },
-
-		"i08": {"name": get_lang("Empty trash"), "icon": "empty-trash", callback: function(key, opt){ empty_trash_imap() } }
+		"i06": {"name": get_lang("Labels"), "icon": "tag", callback: configureLabels }, 
+		"i08": {"name": get_lang("Empty trash"), "icon": "empty-trash", callback: function(key, opt){ empty_trash_imap }}
 	};
 		
@@ -56,7 +116,4 @@
 }
 
-/**
- * Aplica o menu ferramentas
- */
 $.contextMenu({
 	selector: "#link_tools",
@@ -70,7 +127,4 @@
 	events: {
 		show: function(opt) {
-			/**
-			 * Modifica cor do elemento de trigger para o menu
-			 */
 			var $trigger = $(opt.selector).css({'background-color': '#EEEEEE', 'border': '1px solid #CCCCCC'});
 			$('.context-menu-list.context-menu-root').css({'width': $trigger.css('width') });
@@ -78,7 +132,4 @@
 		},
 		hide: function(opt) {
-			/**
-			 * Modifica cor do elemento de trigger para o menu
-			 */
 			$(opt.selector).css({'background-color': '', 'border': 'none'});
 			return true;
@@ -86,7 +137,54 @@
 	},
 	callback: function(key, options) {
-		//TODO - default actions		
+		
 	},
 	items: menuToolsItems
 });
 
+
+function updateLabelsColumn(messageInfo) {
+	$('#td_message_labels_' + messageInfo.msg_number +', #td_message_labels_search_' + messageInfo.msg_number)
+	.html('<img src="../prototype/modules/mail/img/tag.png">');
+
+	var menuItems = {};
+	if (messageInfo.labels) {
+		menuItems = messageInfo.labels;
+	} else {
+		var labeleds = DataLayer.get('labeled', {
+			filter: [
+				'AND',
+				['=', 'folderName', current_folder], 
+				['=', 'messageNumber', messageInfo.msg_number]
+			],
+			criteria: {deepness: 2}
+		});
+		if (labeleds) {
+			for (var i=0; i < labeleds.length; i++)
+				menuItems[labeleds[i].label.id] = labeleds[i].label;
+		} else {
+			//nÃ£o tem labels
+			return false;
+		}
+	}
+
+	$.contextMenu( 'destroy', '#td_message_labels_' + messageInfo.msg_number +', #td_message_labels_search_' + messageInfo.msg_number);
+
+	$.contextMenu({
+		selector: '#td_message_labels_' + messageInfo.msg_number +', #td_message_labels_search_' + messageInfo.msg_number,
+		trigger: 'hover',
+		delay:100,
+		autoHide:true,
+		callback: function(key, options) {
+			//alert($(this).attr('id'));
+		},
+		items: menuItems
+	});
+}
+
+/**
+ * TODO
+ * * ao clicar com o botao direito em cima da mensagem, selecionar a mensagem
+ * * clarear a cor do menu ferramentas
+ * * pintar o botao ferramentas, quando clicado, da cor do menu
+ * 
+ */
