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.DocPane");
12
dojo.require("dojo.widget.*");
13
dojo.require("dojo.io.*");
14
dojo.require("dojo.event.*");
15
dojo.require("dojo.widget.HtmlWidget");
16
dojo.require("dojo.widget.Editor2");
17
dojo.require("dojo.widget.Dialog");
18
dojo.require("dojo.html.common");
19
dojo.require("dojo.html.display");
20
dojo.widget.DocPane = function () {
21
	dojo.event.topic.subscribe("/docs/function/results", this, "onDocResults");
22
	dojo.event.topic.subscribe("/docs/package/results", this, "onPkgResults");
23
	dojo.event.topic.subscribe("/docs/function/detail", this, "onDocSelectFunction");
24
};
25
dojo.widget.defineWidget("dojo.widget.DocPane", dojo.widget.HtmlWidget, {dialog:null, dialogBg:null, dialogFg:null, logIn:null, edit:null, save:null, cancel:null, detail:null, result:null, packag:null, fn:null, fnLink:null, count:null, row:null, summary:null, description:null, variables:null, vRow:null, vLink:null, vDesc:null, methods:null, mRow:null, mLink:null, mDesc:null, requires:null, rRow:null, rRow2:null, rH3:null, rLink:null, parameters:null, pRow:null, pLink:null, pDesc:null, pOpt:null, pType:null, sType:null, sName:null, sParams:null, sPType:null, sPTypeSave:null, sPName:null, sPNameSave:null, pkgDescription:null, _appends:[], templateString:"<div class=\"dojoDocPane\">\n\t<div dojoAttachPoint=\"containerNode\" class=\"container\"></div>\n\n\t<div dojoAttachPoint=\"dialog\" class=\"dialog\">\n\t\t<div class=\"container\" dojoAttachPoint=\"dialogBg\">\n\t\t\t<div class=\"docDialog\" dojoAttachPoint=\"dialogFg\">\n\t\t\t\t<h2>Log In</h2>\n\t\t\t\t<p><input id=\"dojoDocUserName\" dojoAttachPoint=\"userName\"><label for=\"dojoDocUserName\">User Name:</label></p>\n\t\t\t\t<p><input id=\"dojoDocPassword\" dojoAttachPoint=\"password\" type=\"password\"><label for=\"dojoDocPassword\">Password:</label></p>\n\t\t\t\t<p><input type=\"button\" dojoAttachPoint=\"cancel\" value=\"cancel\"> <input type=\"button\" dojoAttachPoint=\"logIn\" value=\"Log In\"></p>\n\t\t\t\t<p></p>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n\n\t<div dojoAttachPoint=\"nav\" class=\"nav\"><span>Detail</span> | <span>Source</span> | <span>Examples</span> | <span>Walkthrough</span></div>\n\n\t<div dojoAttachPoint=\"detail\" class=\"detail\">\n\t\t<h1>Detail: <span class=\"fn\" dojoAttachPoint=\"fn\">dojo.select</span></h1>\n\t\t<div class=\"description\" dojoAttachPoint=\"description\">Description</div>\n\t\t<div class=\"params\" dojoAttachPoint=\"parameters\">\n\t\t\t<h2>Parameters</h2>\n\t\t\t<div class=\"row\" dojoAttachPoint=\"pRow\">\n\t\t\t\t<span dojoAttachPoint=\"pOpt\"><em>optional</em> </span>\n\t\t\t\t<span><span dojoAttachPoint=\"pType\">type</span> </span>\n\t\t\t\t<a href=\"#\" dojoAttachPoint=\"pLink\">variable</a>\n\t\t\t\t<span> - <span dojoAttachPoint=\"pDesc\"></span></span>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"variables\" dojoAttachPoint=\"variables\">\n\t\t\t<h2>Variables</h2>\n\t\t\t<div class\"row\" dojoAttachPoint=\"vRow\">\n\t\t\t\t<a href=\"#\" dojoAttachPoint=\"vLink\">variable</a><span> - <span dojoAttachPoint=\"vDesc\"></span></span>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"signature\">\n\t\t\t<h2>Signature</h2>\n\t\t\t<div class=\"source\">\n\t\t\t\t<span class=\"return\" dojoAttachPoint=\"sType\">returnType</span> \n\t\t\t\t<span class=\"function\" dojoAttachPoint=\"sName\">foo</span>\n\t\t\t\t(<span class=\"params\" dojoAttachPoint=\"sParams\">\n\t\t\t\t\t<span class=\"type\" dojoAttachPoint=\"sPType\">type </span>\n\t\t\t\t\t<span class=\"name\" dojoAttachPoint=\"sPName\">paramName</span>\n\t\t\t\t</span>)\n\t\t\t</div>\n\t\t</div>\n\t</div>\n\t\n\t<div dojoAttachPoint=\"result\" class=\"result\">\n\t\t<h1>Search Results: <span dojoAttachPoint=\"count\">0</span> matches</h1>\n\t\t<div class=\"row\" dojoAttachPoint=\"row\">\n\t\t\t<a href=\"#\" dojoAttachPoint=\"fnLink\">dojo.fnLink</a>\n\t\t\t<span> - <span class=\"summary\" dojoAttachPoint=\"summary\">summary</span></span>\n\t\t</div>\n\t</div>\n\n\t<div dojoAttachPoint=\"packag\" class=\"package\">\n\t\t<h1>Package: \n\t\t\t<span class=\"pkg\" dojoAttachPoint=\"pkg\">dojo.package</span> \n\t\t\t<span class=\"edit\" dojoAttachPoint=\"edit\">[edit]</span> \n\t\t\t<span class=\"save\" dojoAttachPoint=\"save\">[save]</span>\n\t\t</h1>\n\t\t<div dojoAttachPoint=\"pkgDescription\" class=\"description\">Description</div>\n\t\t<div class=\"methods\" dojoAttachPoint=\"methods\">\n\t\t\t<h2>Methods</h2>\n\t\t\t<div class=\"row\" dojoAttachPoint=\"mRow\">\n\t\t\t\t<a href=\"#\" dojoAttachPoint=\"mLink\">method</a>\n\t\t\t\t<span> - <span class=\"description\" dojoAttachPoint=\"mDesc\"></span></span>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"requires\" dojoAttachPoint=\"requires\">\n\t\t\t<h2>Requires</h2>\n\t\t\t<div class=\"row\" dojoAttachPoint=\"rRow\">\n\t\t\t\t<h3 dojoAttachPoint=\"rH3\">Environment</h3>\n\t\t\t\t<div dojoAttachPoint=\"rRow2\"><a href=\"#\" dojoAttachPoint=\"rLink\" class=\"package\">require</a></div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</div>\n", templateCssString:".dojoDocPane { padding:1em; font: 1em Georgia,Times,\"Times New Roman\",serif; }\n\n.dojoDocPane .container{ }\n\n.dojoDocPane .dialog{ }\n.dojoDocPane .dialog .container{ padding: 0.5em; background: #fff; border: 2px solid #333; }\n.dojoDocPane .dialog .docDialog{ background: transparent; width: 20em; }\n.dojoDocPane .dialog .docDialog h2{ margin-top: 0; padding-top: 0; }\n.dojoDocPane .dialog .docDialog input { float: right; margin-right: 1em; }\n.dojoDocPane .dialog .docDialog p{ clear: both; }\n#dojoDocUserName, #dojoDocPassword { width: 10em; }\n\n.dojoDocPane .nav{ }\n.dojoDocPane .nav span{ }\n\n.dojoDocPane .detail{ }\n.dojoDocPane .detail h1{ }\n.dojoDocPane .detail h1 span.fn{ }\n.dojoDocPane .detail .description{ }\n.dojoDocPane .detail .params{ }\n.dojoDocPane .detail .params .row{ }\n.dojoDocPane .detail .params .row span{ }\n.dojoDocPane .detail .variables{ }\n.dojoDocPane .detail .variables .row{ }\n.dojoDocPane .detail .signature{ }\n.dojoDocPane .detail .signature .source{ white-space: pre; font: 0.8em Monaco, Courier, \"Courier New\", monospace; }\n.dojoDocPane .detail .signature .source .return{ color:#369; }\n.dojoDocPane .detail .signature .source .function{ color: #98543F; font-weight: bold; }\n.dojoDocPane .detail .signature .source .params{ }\n.dojoDocPane .detail .signature .source .params .type{ font-style: italic; color: #d17575; }\n.dojoDocPane .detail .signature .source .params .name{ color: #d14040; }\n\n.dojoDocPane .result{ }\n.dojoDocPane .result h1{ }\n.dojoDocPane .result .row{ }\n.dojoDocPane .result .row .summary{ }\n\n.dojoDocPane .package{ }\n.dojoDocPane .package h1{ }\n.dojoDocPane .package .row{ }\n.dojoDocPane .package .row .summary{ }\n.dojoDocPane .package .description{ }\n.dojoDocPane .package .methods{ }\n.dojoDocPane .package .methods h2{ }\n.dojoDocPane .package .methods .row{ }\n.dojoDocPane .package .methods .row .description{ }\n.dojoDocPane .package .requires{ }\n.dojoDocPane .package .requires h2{ }\n.dojoDocPane .package .requires .row{ }\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/DocPane.css"), isContainer:true, fillInTemplate:function () {
26
	this.requires = dojo.html.removeNode(this.requires);
27
	this.rRow.style.display = "none";
28
	this.rRow2.style.display = "none";
29
	this.methods = dojo.html.removeNode(this.methods);
30
	this.mRow.style.display = "none";
31
	this.dialog = dojo.widget.createWidget("dialog", {}, this.dialog);
32
	this.dialog.setCloseControl(this.cancel);
33
	dojo.html.setOpacity(this.dialogBg, 0.8);
34
	dojo.html.setOpacity(this.dialogFg, 1);
35
	dojo.event.connect(this.edit, "onclick", dojo.lang.hitch(this, function () {
36
		if (!this._isLoggedIn) {
37
			this.dialog.show();
38
		}
39
	}));
40
	dojo.event.connect(this.logIn, "onclick", this, "_logIn");
41
	dojo.event.connect(this.save, "onclick", this, "_save");
42
	dojo.event.connect(dojo.docs, "logInSuccess", this, "_loggedIn");
43
	this.homeSave = this.containerNode.cloneNode(true);
44
	this.detailSave = dojo.html.removeNode(this.detail);
45
	this.resultSave = dojo.html.removeNode(this.result);
46
	this.packageSave = dojo.html.removeNode(this.packag);
47
	this.results = dojo.html.removeNode(this.results);
48
	this.rowParent = this.row.parentNode;
49
	this.rowSave = dojo.html.removeNode(this.row);
50
	this.vParent = this.vRow.parentNode;
51
	this.vSave = dojo.html.removeNode(this.vRow);
52
	this.pParent = this.pRow.parentNode;
53
	this.pSave = dojo.html.removeNode(this.pRow);
54
	this.sPTypeSave = dojo.html.removeNode(this.sPType);
55
	this.sPNameSave = dojo.html.removeNode(this.sPName);
56
	this.navSave = dojo.html.removeNode(this.nav);
57
}, _logIn:function () {
58
	dojo.docs.setUserName(this.userName.value);
59
	dojo.docs.setPassword(this.password.value);
60
}, _loggedIn:function () {
61
	this._isLoggedIn = true;
62
	this.dialog.hide();
63
	this.pkgEditor = dojo.widget.createWidget("editor2", {toolbarAlwaysVisible:true}, this.pkgDescription);
64
}, _save:function () {
65
	if (this.pkgEditor) {
66
		dojo.docs.savePackage(this._pkgPath, {description:this.pkgEditor.getEditorContent()});
67
	}
68
}, onDocSelectFunction:function (message) {
69
	dojo.debug("onDocSelectFunction()");
70
	for (var key in message) {
71
		dojo.debug(key + ": " + dojo.json.serialize(message[key]));
72
	}
73
	var meta = message.meta;
74
	if (meta) {
75
		var variables = meta.variables;
76
		var this_variables = meta.this_variables;
77
		var child_variables = meta.child_variables;
78
		var parameters = meta.parameters;
79
	}
80
	var doc = message.doc;
81
	dojo.debug(dojo.json.serialize(doc));
82
	var appends = this._appends;
83
	dojo.html.removeChildren(this.domNode);
84
	this.fn.innerHTML = message.name;
85
	this.variables.style.display = "block";
86
	var all = [];
87
	if (variables) {
88
		all = variables;
89
	}
90
	if (this_variables) {
91
		all = all.concat(this_variables);
92
	}
93
	if (child_variables) {
94
		all = all.concat(child_variables);
95
	}
96
	if (!all.length) {
97
		this.variables.style.display = "none";
98
	} else {
99
		for (var i = 0, one; one = all[i]; i++) {
100
			this.vLink.innerHTML = one;
101
			this.vDesc.parentNode.style.display = "none";
102
			appends.push(this.vParent.appendChild(this.vSave.cloneNode(true)));
103
		}
104
	}
105
	this.sParams.innerHTML = "";
106
	var first = true;
107
	for (var param in parameters) {
108
		var paramType = parameters[param].type;
109
		var paramSummary = parameters[param].summary;
110
		var paramName = param;
111
		this.parameters.style.display = "block";
112
		this.pLink.innerHTML = paramName;
113
		this.pOpt.style.display = "none";
114
		if (parameters[param].opt) {
115
			this.pOpt.style.display = "inline";
116
		}
117
		this.pType.parentNode.style.display = "none";
118
		if (parameters[param][0]) {
119
			this.pType.parentNode.style.display = "inline";
120
			this.pType.innerHTML = paramType;
121
		}
122
		this.pDesc.parentNode.style.display = "none";
123
		if (paramSummary) {
124
			this.pDesc.parentNode.style.display = "inline";
125
			this.pDesc.innerHTML = paramSummary;
126
		}
127
		appends.push(this.pParent.appendChild(this.pSave.cloneNode(true)));
128
		if (!first) {
129
			this.sParams.appendChild(document.createTextNode(", "));
130
		}
131
		first = false;
132
		if (paramType) {
133
			dojo.debug(this.sPTypeSave);
134
			this.sPTypeSave.innerHTML = paramType;
135
			this.sParams.appendChild(this.sPTypeSave.cloneNode(true));
136
			this.sParams.appendChild(document.createTextNode(" "));
137
		}
138
		dojo.debug(this.sPNameSave);
139
		this.sPNameSave.innerHTML = paramName;
140
		this.sParams.appendChild(this.sPNameSave.cloneNode(true));
141
	}
142
	if (message.returns) {
143
		this.sType.innerHTML = message.returns;
144
	} else {
145
		this.sType.innerHTML = "void";
146
	}
147
	this.sName.innerHTML = message.name;
148
	this.domNode.appendChild(this.navSave);
149
	this.domNode.appendChild(this.detailSave.cloneNode(true));
150
	for (var i = 0, append; append = appends[i]; i++) {
151
		dojo.html.removeNode(append);
152
	}
153
}, onPkgResult:function (results) {
154
	if (this.pkgEditor) {
155
		this.pkgEditor.close(true);
156
		dojo.debug(this.pkgDescription);
157
	}
158
	var methods = results.methods;
159
	var requires = results.requires;
160
	var description = results.description;
161
	this._pkgPath = results.path;
162
	var requireLinks = [];
163
	var appends = this._appends;
164
	while (appends.length) {
165
		dojo.html.removeNode(appends.shift());
166
	}
167
	dojo.html.removeChildren(this.domNode);
168
	this.pkg.innerHTML = results.pkg;
169
	var hasRequires = false;
170
	for (var env in requires) {
171
		hasRequires = true;
172
		this.rH3.style.display = "none";
173
		if (env != "common") {
174
			this.rH3.style.display = "";
175
			this.rH3.innerHTML = env;
176
		}
177
		for (var i = 0, require; require = requires[env][i]; i++) {
178
			requireLinks.push({name:require});
179
			this.rLink.innerHTML = require;
180
			this.rLink.href = "#" + require;
181
			var rRow2 = this.rRow2.parentNode.insertBefore(this.rRow2.cloneNode(true), this.rRow2);
182
			rRow2.style.display = "";
183
			appends.push(rRow2);
184
		}
185
		var rRow = this.rRow.parentNode.insertBefore(this.rRow.cloneNode(true), this.rRow);
186
		rRow.style.display = "";
187
		appends.push(rRow);
188
	}
189
	if (hasRequires) {
190
		appends.push(this.packageSave.appendChild(this.requires.cloneNode(true)));
191
	}
192
	if (results.size) {
193
		for (var i = 0, method; method = methods[i]; i++) {
194
			this.mLink.innerHTML = method.name;
195
			this.mLink.href = "#" + method.name;
196
			this.mDesc.parentNode.style.display = "none";
197
			if (method.summary) {
198
				this.mDesc.parentNode.style.display = "inline";
199
				this.mDesc.innerHTML = method.summary;
200
			}
201
			var mRow = this.mRow.parentNode.insertBefore(this.mRow.cloneNode(true), this.mRow);
202
			mRow.style.display = "";
203
			appends.push(mRow);
204
		}
205
		appends.push(this.packageSave.appendChild(this.methods.cloneNode(true)));
206
	}
207
	this.domNode.appendChild(this.packageSave);
208
	this.pkgDescription.innerHTML = description;
209
	function makeSelect(fOrP, x) {
210
		return function (e) {
211
			dojo.event.topic.publish("/docs/" + fOrP + "/select", x);
212
		};
213
	}
214
	var as = this.domNode.getElementsByTagName("a");
215
	for (var i = 0, a; a = as[i]; i++) {
216
		if (a.className == "docMLink") {
217
			dojo.event.connect(a, "onclick", makeSelect("function", methods[i]));
218
		} else {
219
			if (a.className == "docRLink") {
220
				dojo.event.connect(a, "onclick", makeSelect("package", requireLinks[i]));
221
			}
222
		}
223
	}
224
}, onDocResults:function (fns) {
225
	dojo.debug("onDocResults(): called");
226
	if (fns.length == 1) {
227
		dojo.event.topic.publish("/docs/function/select", fns[0]);
228
		return;
229
	}
230
	dojo.html.removeChildren(this.domNode);
231
	this.count.innerHTML = fns.length;
232
	var appends = [];
233
	for (var i = 0, fn; fn = fns[i]; i++) {
234
		this.fnLink.innerHTML = fn.name;
235
		this.fnLink.href = "#" + fn.name;
236
		if (fn.id) {
237
			this.fnLink.href = this.fnLink.href + "," + fn.id;
238
		}
239
		this.summary.parentNode.style.display = "none";
240
		if (fn.summary) {
241
			this.summary.parentNode.style.display = "inline";
242
			this.summary.innerHTML = fn.summary;
243
		}
244
		appends.push(this.rowParent.appendChild(this.rowSave.cloneNode(true)));
245
	}
246
	function makeSelect(x) {
247
		return function (e) {
248
			dojo.event.topic.publish("/docs/function/select", x);
249
		};
250
	}
251
	this.domNode.appendChild(this.resultSave.cloneNode(true));
252
	var as = this.domNode.getElementsByTagName("a");
253
	for (var i = 0, a; a = as[i]; i++) {
254
		dojo.event.connect(a, "onclick", makeSelect(fns[i]));
255
	}
256
	for (var i = 0, append; append = appends[i]; i++) {
257
		this.rowParent.removeChild(append);
258
	}
259
}});
260