Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.widget.Toaster");
12
dojo.require("dojo.widget.*");
13
dojo.require("dojo.lfx.*");
14
dojo.require("dojo.html.iframe");
15
dojo.widget.defineWidget("dojo.widget.Toaster", dojo.widget.HtmlWidget, {templateString:"<div dojoAttachPoint=\"clipNode\"><div dojoAttachPoint=\"containerNode\" dojoAttachEvent=\"onClick:onSelect\"><div dojoAttachPoint=\"contentNode\"></div></div></div>", templateCssString:".dojoToasterClip {\n\tposition: absolute;\n\toverflow: hidden;\n}\n\n.dojoToasterContainer {\n\tdisplay: block;\n\tposition: absolute;\n\twidth: 17.5em;\n\tz-index: 5000;\n\tmargin: 0px;\n\tfont:0.75em Tahoma, Helvetica, Verdana, Arial;\n}\n\n.dojoToasterContent{\n\tpadding:1em;\n\tpadding-top:0.25em;\n\tbackground:#73c74a;\n}\n\n.dojoToasterMessage{ \n\tcolor:#fff;\n}\n.dojoToasterWarning{ }\n.dojoToasterError,\n.dojoToasterFatal{\n\tfont-weight:bold;\n\tcolor:#fff;\n}\n\n\n.dojoToasterWarning .dojoToasterContent{\n\tpadding:1em;\n\tpadding-top:0.25em;\n\tbackground:#d4d943;\n} \n\n.dojoToasterError .dojoToasterContent{\n\tpadding:1em;\n\tpadding-top:0.25em;\n\tbackground:#c46600;\n} \n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Toaster.css"), messageTopic:"", messageTypes:{MESSAGE:"MESSAGE", WARNING:"WARNING", ERROR:"ERROR", FATAL:"FATAL"}, defaultType:"MESSAGE", clipCssClass:"dojoToasterClip", containerCssClass:"dojoToasterContainer", contentCssClass:"dojoToasterContent", messageCssClass:"dojoToasterMessage", warningCssClass:"dojoToasterWarning", errorCssClass:"dojoToasterError", fatalCssClass:"dojoToasterFatal", positionDirection:"br-up", positionDirectionTypes:["br-up", "br-left", "bl-up", "bl-right", "tr-down", "tr-left", "tl-down", "tl-right"], showDelay:2000, postCreate:function () {
16
	this.hide();
17
	dojo.html.setClass(this.clipNode, this.clipCssClass);
18
	dojo.html.addClass(this.containerNode, this.containerCssClass);
19
	dojo.html.setClass(this.contentNode, this.contentCssClass);
20
	if (this.messageTopic) {
21
		dojo.event.topic.subscribe(this.messageTopic, this, "_handleMessage");
22
	}
23
	if (!this.positionDirection || !dojo.lang.inArray(this.positionDirectionTypes, this.positionDirection)) {
24
		this.positionDirection = this.positionDirectionTypes.BRU;
25
	}
26
}, _handleMessage:function (msg) {
27
	if (dojo.lang.isString(msg)) {
28
		this.setContent(msg);
29
	} else {
30
		this.setContent(msg["message"], msg["type"], msg["delay"]);
31
	}
32
}, setContent:function (msg, messageType, delay) {
33
	var delay = delay || this.showDelay;
34
	if (this.slideAnim && this.slideAnim.status() == "playing") {
35
		dojo.lang.setTimeout(50, dojo.lang.hitch(this, function () {
36
			this.setContent(msg, messageType);
37
		}));
38
		return;
39
	} else {
40
		if (this.slideAnim) {
41
			this.slideAnim.stop();
42
			if (this.fadeAnim) {
43
				this.fadeAnim.stop();
44
			}
45
		}
46
	}
47
	if (!msg) {
48
		dojo.debug(this.widgetId + ".setContent() incoming content was null, ignoring.");
49
		return;
50
	}
51
	if (!this.positionDirection || !dojo.lang.inArray(this.positionDirectionTypes, this.positionDirection)) {
52
		dojo.raise(this.widgetId + ".positionDirection is an invalid value: " + this.positionDirection);
53
	}
54
	dojo.html.removeClass(this.containerNode, this.messageCssClass);
55
	dojo.html.removeClass(this.containerNode, this.warningCssClass);
56
	dojo.html.removeClass(this.containerNode, this.errorCssClass);
57
	dojo.html.removeClass(this.containerNode, this.fatalCssClass);
58
	dojo.html.clearOpacity(this.containerNode);
59
	if (msg instanceof String || typeof msg == "string") {
60
		this.contentNode.innerHTML = msg;
61
	} else {
62
		if (dojo.html.isNode(msg)) {
63
			this.contentNode.innerHTML = dojo.html.getContentAsString(msg);
64
		} else {
65
			dojo.raise("Toaster.setContent(): msg is of unknown type:" + msg);
66
		}
67
	}
68
	switch (messageType) {
69
	  case this.messageTypes.WARNING:
70
		dojo.html.addClass(this.containerNode, this.warningCssClass);
71
		break;
72
	  case this.messageTypes.ERROR:
73
		dojo.html.addClass(this.containerNode, this.errorCssClass);
74
		break;
75
	  case this.messageTypes.FATAL:
76
		dojo.html.addClass(this.containerNode, this.fatalCssClass);
77
		break;
78
	  case this.messageTypes.MESSAGE:
79
	  default:
80
		dojo.html.addClass(this.containerNode, this.messageCssClass);
81
		break;
82
	}
83
	this.show();
84
	var nodeSize = dojo.html.getMarginBox(this.containerNode);
85
	if (this.positionDirection.indexOf("-up") >= 0) {
86
		this.containerNode.style.left = 0 + "px";
87
		this.containerNode.style.top = nodeSize.height + 10 + "px";
88
	} else {
89
		if (this.positionDirection.indexOf("-left") >= 0) {
90
			this.containerNode.style.left = nodeSize.width + 10 + "px";
91
			this.containerNode.style.top = 0 + "px";
92
		} else {
93
			if (this.positionDirection.indexOf("-right") >= 0) {
94
				this.containerNode.style.left = 0 - nodeSize.width - 10 + "px";
95
				this.containerNode.style.top = 0 + "px";
96
			} else {
97
				if (this.positionDirection.indexOf("-down") >= 0) {
98
					this.containerNode.style.left = 0 + "px";
99
					this.containerNode.style.top = 0 - nodeSize.height - 10 + "px";
100
				} else {
101
					dojo.raise(this.widgetId + ".positionDirection is an invalid value: " + this.positionDirection);
102
				}
103
			}
104
		}
105
	}
106
	this.slideAnim = dojo.lfx.html.slideTo(this.containerNode, {top:0, left:0}, 450, null, dojo.lang.hitch(this, function (nodes, anim) {
107
		dojo.lang.setTimeout(dojo.lang.hitch(this, function (evt) {
108
			if (this.bgIframe) {
109
				this.bgIframe.hide();
110
			}
111
			this.fadeAnim = dojo.lfx.html.fadeOut(this.containerNode, 1000, null, dojo.lang.hitch(this, function (evt) {
112
				this.hide();
113
			})).play();
114
		}), delay);
115
	})).play();
116
}, _placeClip:function () {
117
	var scroll = dojo.html.getScroll();
118
	var view = dojo.html.getViewport();
119
	var nodeSize = dojo.html.getMarginBox(this.containerNode);
120
	this.clipNode.style.height = nodeSize.height + "px";
121
	this.clipNode.style.width = nodeSize.width + "px";
122
	if (this.positionDirection.match(/^t/)) {
123
		this.clipNode.style.top = scroll.top + "px";
124
	} else {
125
		if (this.positionDirection.match(/^b/)) {
126
			this.clipNode.style.top = (view.height - nodeSize.height - 2 + scroll.top) + "px";
127
		}
128
	}
129
	if (this.positionDirection.match(/^[tb]r-/)) {
130
		this.clipNode.style.left = (view.width - nodeSize.width - 1 - scroll.left) + "px";
131
	} else {
132
		if (this.positionDirection.match(/^[tb]l-/)) {
133
			this.clipNode.style.left = 0 + "px";
134
		}
135
	}
136
	this.clipNode.style.clip = "rect(0px, " + nodeSize.width + "px, " + nodeSize.height + "px, 0px)";
137
	if (dojo.render.html.ie) {
138
		if (!this.bgIframe) {
139
			this.bgIframe = new dojo.html.BackgroundIframe(this.containerNode);
140
			this.bgIframe.setZIndex(this.containerNode);
141
		}
142
		this.bgIframe.onResized();
143
		this.bgIframe.show();
144
	}
145
}, onSelect:function (e) {
146
}, show:function () {
147
	dojo.widget.Toaster.superclass.show.call(this);
148
	this._placeClip();
149
	if (!this._scrollConnected) {
150
		this._scrollConnected = true;
151
		dojo.event.connect(window, "onscroll", this, "_placeClip");
152
	}
153
}, hide:function () {
154
	dojo.widget.Toaster.superclass.hide.call(this);
155
	if (this._scrollConnected) {
156
		this._scrollConnected = false;
157
		dojo.event.disconnect(window, "onscroll", this, "_placeClip");
158
	}
159
	dojo.html.setOpacity(this.containerNode, 1);
160
}});
161