Messages.js 2.46 KB
Ext.define("treps.Messages",
	{
		requires: [
			"Ext.window.MessageBox",
			"treps.Constants"
		],
	
		singleton  : true,

		bubble : null,
        
		showWarning: function(message)
		{
			Ext.Msg.show({
				title:treps.Constants.APP_TITLE+" - Warning",
				msg: message,
				buttons: Ext.Msg.OK,
				icon: Ext.Msg.WARNING
			});
		},
		
		showError: function(message,onOk)
		{
			Ext.Msg.show({
				title:treps.Constants.APP_TITLE+" - Error",
				msg: message,
				buttons: Ext.Msg.OK,
				icon: Ext.Msg.ERROR,
				fn: function(buttonId)
				{
					if ((buttonId == "ok") && (onOk != null))
						onOk.call();
				}
			});
		},
		
		showInfo: function(message,onOk)
		{
			Ext.Msg.show({
				title:treps.Constants.APP_TITLE+" - Info",
				msg: message,
				buttons: Ext.Msg.OK,
				icon: Ext.Msg.INFO
			});
		},

		showQuestion: function(message,onYes,onNo)
		{
			Ext.Msg.show({
				title:treps.Constants.APP_TITLE+" - Question",
				msg: message,
				buttons: Ext.Msg.YESNO,
				icon: Ext.Msg.QUESTION,
				fn: function(buttonId)
					{
						if ((buttonId == "yes") && (onYes != null))
							onYes.call();
						if ((buttonId == "no") && (onNo != null))
                                                        onNo.call();
					}
			});
		},

		showBubble: function(title, messageHTML, target, anchor)
		{
			if (!this.bubble)
				this.bubble = new Ext.ToolTip({
					target: target,
					anchor: anchor,
					anchorToTarget: true,
					title: title,
					html: messageHTML,
					closable: true,
					autoHide: false
				});
			else
			{
				this.hideBubble();
				this.bubble.setTitle(title);
				this.bubble.update(messageHTML);
				this.bubble.setTarget(target);
				this.bubble.anchor = anchor;
			}

			this.bubble.show();
		},

		hideBubble: function()
		{
			if (this.bubble)
			{
				this.bubble.hide();
				this.bubble.setTarget(null);
			}
		},

		showBubbleTT: function(title, messageHTML, target, anchor)
		{
			if (!this.bubble)
				this.bubble = new Ext.ToolTip({
					target: target,
					anchor: anchor,
					anchorToTarget: true,
					title: title,
					html: messageHTML,
					closable: false,
					showDelay: 1000,
					dismissDelay: 10000,
					autoHide: true
				});
			else
			{
				this.hideBubble();
				this.bubble.setTitle(title);
				this.bubble.update(messageHTML);
				this.bubble.setTarget(target);
				this.bubble.anchor = anchor;
				this.bubble.showDelay = 1000;
				this.bubble.dismissDelay = 10000;
				this.bubble.autoHide = true;
			}

			this.bubble.show();
		}

	}
	
	
);