Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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