Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | 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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.TreeV3");
14
dojo.require("dojo.widget.TreeWithNode");
15
dojo.require("dojo.widget.*");
16
dojo.require("dojo.event.*");
17
dojo.require("dojo.io.*");
18
dojo.require("dojo.widget.HtmlWidget");
19
dojo.require("dojo.widget.TreeNodeV3");
20
dojo.widget.defineWidget("dojo.widget.TreeV3", [dojo.widget.HtmlWidget, dojo.widget.TreeWithNode], function () {
21
	this.eventNames = {};
22
	this.DndAcceptTypes = [];
23
	this.actionsDisabled = [];
24
	this.listeners = [];
25
	this.tree = this;
26
}, {DndMode:"", defaultChildWidget:null, defaultChildTitle:"New Node", eagerWidgetInstantiation:false, eventNamesDefault:{afterTreeCreate:"afterTreeCreate", beforeTreeDestroy:"beforeTreeDestroy", beforeNodeDestroy:"beforeNodeDestroy", afterChangeTree:"afterChangeTree", afterSetFolder:"afterSetFolder", afterUnsetFolder:"afterUnsetFolder", beforeMoveFrom:"beforeMoveFrom", beforeMoveTo:"beforeMoveTo", afterMoveFrom:"afterMoveFrom", afterMoveTo:"afterMoveTo", afterAddChild:"afterAddChild", afterDetach:"afterDetach", afterExpand:"afterExpand", beforeExpand:"beforeExpand", afterSetTitle:"afterSetTitle", afterCollapse:"afterCollapse", beforeCollapse:"beforeCollapse"}, classPrefix:"Tree", style:"", allowAddChildToLeaf:true, unsetFolderOnEmpty:true, DndModes:{BETWEEN:1, ONTO:2}, DndAcceptTypes:"", templateCssString:"/* indent for all tree children excepts root */\n.TreeNode {\n	background-image : url('../templates/images/TreeV3/i.gif');\n	background-position : top left;\n	background-repeat : repeat-y;\n	margin-left: 19px;\n	zoom: 1;\n}\n.TreeIsRoot {\n	margin-left: 0;\n}\n \n/* left vertical line (grid) for all nodes */\n.TreeIsLast {\n	background-image: url('../templates/images/TreeV3/i_half.gif');\n	background-repeat : no-repeat;\n}\n \n.TreeExpandOpen .TreeExpand {\n	background-image: url('../templates/images/TreeV3/expand_minus.gif');\n}\n \n/* closed is higher priority than open */\n.TreeExpandClosed .TreeExpand {\n	background-image: url('../templates/images/TreeV3/expand_plus.gif');\n}\n \n/* highest priority */\n.TreeExpandLeaf .TreeExpand {\n	background-image: url('../templates/images/TreeV3/expand_leaf.gif');\n}\n\n/* \nshould always override any expand setting, but do not touch children.\nif I add .TreeExpand .TreeExpandLoading same time and put it to top/bottom, then it will take precedence over +- for all descendants or always fail\nso I have to remove TreeExpand and process this one specifically\n*/\n\n.TreeExpandLoading   {\n	width: 18px;\n	height: 18px;\n	float: left;\n	display: inline;\n	background-repeat : no-repeat;\n	background-image: url('../templates/images/TreeV3/expand_loading.gif');\n}\n \n.TreeContent {\n	min-height: 18px;\n	min-width: 18px;\n	margin-left:18px;\n	cursor: default;\n	/* can't make inline - multiline bugs */\n}\n\n.TreeIEContent {\n\theight: 18px;\n}\n \n.TreeExpand {\n	width: 18px;\n	height: 18px;\n	float: left;\n	display: inline;\n	background-repeat : no-repeat;\n}\n \n/* same style as IE selection */\n.TreeNodeEmphasized {\n	background-color: Highlight;\n	color: HighlightText;\n}\n \n.TreeContent .RichTextEditable, .TreeContent .RichTextEditable iframe {\n	  background-color: #ffc;\n	  color: black;\n}\n\n/* don't use :focus due to opera's lack of support on div's */\n.TreeLabelFocused {\n	  outline: 1px invert dotted;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/TreeV3.css"), templateString:"<div style=\"${this.style}\">\n</div>", isExpanded:true, isTree:true, createNode:function (data) {
27
	data.tree = this.widgetId;
28
	if (data.widgetName) {
29
		return dojo.widget.createWidget(data.widgetName, data);
30
	} else {
31
		if (this.defaultChildWidget.prototype.createSimple) {
32
			return this.defaultChildWidget.prototype.createSimple(data);
33
		} else {
34
			var ns = this.defaultChildWidget.prototype.ns;
35
			var wt = this.defaultChildWidget.prototype.widgetType;
36
			return dojo.widget.createWidget(ns + ":" + wt, data);
37
		}
38
	}
39
}, makeNodeTemplate:function () {
40
	var domNode = document.createElement("div");
41
	dojo.html.setClass(domNode, this.classPrefix + "Node " + this.classPrefix + "ExpandLeaf " + this.classPrefix + "ChildrenNo");
42
	this.nodeTemplate = domNode;
43
	var expandNode = document.createElement("div");
44
	var clazz = this.classPrefix + "Expand";
45
	if (dojo.render.html.ie) {
46
		clazz = clazz + " " + this.classPrefix + "IEExpand";
47
	}
48
	dojo.html.setClass(expandNode, clazz);
49
	this.expandNodeTemplate = expandNode;
50
	var labelNode = document.createElement("span");
51
	dojo.html.setClass(labelNode, this.classPrefix + "Label");
52
	this.labelNodeTemplate = labelNode;
53
	var contentNode = document.createElement("div");
54
	var clazz = this.classPrefix + "Content";
55
	if (dojo.render.html.ie && !dojo.render.html.ie70) {
56
		clazz = clazz + " " + this.classPrefix + "IEContent";
57
	}
58
	dojo.html.setClass(contentNode, clazz);
59
	this.contentNodeTemplate = contentNode;
60
	domNode.appendChild(expandNode);
61
	domNode.appendChild(contentNode);
62
	contentNode.appendChild(labelNode);
63
}, makeContainerNodeTemplate:function () {
64
	var div = document.createElement("div");
65
	div.style.display = "none";
66
	dojo.html.setClass(div, this.classPrefix + "Container");
67
	this.containerNodeTemplate = div;
68
}, actions:{ADDCHILD:"ADDCHILD"}, getInfo:function () {
69
	var info = {widgetId:this.widgetId, objectId:this.objectId};
70
	return info;
71
}, adjustEventNames:function () {
72
	for (var name in this.eventNamesDefault) {
73
		if (dojo.lang.isUndefined(this.eventNames[name])) {
74
			this.eventNames[name] = this.widgetId + "/" + this.eventNamesDefault[name];
75
		}
76
	}
77
}, adjustDndMode:function () {
78
	var _this = this;
79
	var DndMode = 0;
80
	dojo.lang.forEach(this.DndMode.split(";"), function (elem) {
81
		var mode = _this.DndModes[dojo.string.trim(elem).toUpperCase()];
82
		if (mode) {
83
			DndMode = DndMode | mode;
84
		}
85
	});
86
	this.DndMode = DndMode;
87
}, destroy:function () {
88
	dojo.event.topic.publish(this.tree.eventNames.beforeTreeDestroy, {source:this});
89
	return dojo.widget.HtmlWidget.prototype.destroy.apply(this, arguments);
90
}, initialize:function (args) {
91
	this.domNode.widgetId = this.widgetId;
92
	for (var i = 0; i < this.actionsDisabled.length; i++) {
93
		this.actionsDisabled[i] = this.actionsDisabled[i].toUpperCase();
94
	}
95
	if (!args.defaultChildWidget) {
96
		this.defaultChildWidget = dojo.widget.TreeNodeV3;
97
	} else {
98
		this.defaultChildWidget = dojo.lang.getObjPathValue(args.defaultChildWidget);
99
	}
100
	this.adjustEventNames();
101
	this.adjustDndMode();
102
	this.makeNodeTemplate();
103
	this.makeContainerNodeTemplate();
104
	this.containerNode = this.domNode;
105
	dojo.html.setClass(this.domNode, this.classPrefix + "Container");
106
	var _this = this;
107
	dojo.lang.forEach(this.listeners, function (elem) {
108
		var t = dojo.lang.isString(elem) ? dojo.widget.byId(elem) : elem;
109
		t.listenTree(_this);
110
	});
111
}, postCreate:function () {
112
	dojo.event.topic.publish(this.eventNames.afterTreeCreate, {source:this});
113
}, move:function (child, newParent, index) {
114
	if (!child.parent) {
115
		dojo.raise(this.widgetType + ": child can be moved only while it's attached");
116
	}
117
	var oldParent = child.parent;
118
	var oldTree = child.tree;
119
	var oldIndex = child.getParentIndex();
120
	var newTree = newParent.tree;
121
	var newParent = newParent;
122
	var newIndex = index;
123
	var message = {oldParent:oldParent, oldTree:oldTree, oldIndex:oldIndex, newParent:newParent, newTree:newTree, newIndex:newIndex, child:child};
124
	dojo.event.topic.publish(oldTree.eventNames.beforeMoveFrom, message);
125
	dojo.event.topic.publish(newTree.eventNames.beforeMoveTo, message);
126
	this.doMove.apply(this, arguments);
127
	dojo.event.topic.publish(oldTree.eventNames.afterMoveFrom, message);
128
	dojo.event.topic.publish(newTree.eventNames.afterMoveTo, message);
129
}, doMove:function (child, newParent, index) {
130
	child.doDetach();
131
	newParent.doAddChild(child, index);
132
}, toString:function () {
133
	return "[" + this.widgetType + " ID:" + this.widgetId + "]";
134
}});
135