Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 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.Repeater");
13
dojo.provide("dojo.widget.Repeater");
12
dojo.require("dojo.widget.HtmlWidget");
14
dojo.require("dojo.widget.HtmlWidget");
13
dojo.require("dojo.string");
15
dojo.require("dojo.string");
14
dojo.require("dojo.event.*");
16
dojo.require("dojo.event.*");
15
dojo.require("dojo.experimental");
17
dojo.require("dojo.experimental");
16
dojo.experimental("dojo.widget.Repeater");
18
dojo.experimental("dojo.widget.Repeater");
17
dojo.widget.defineWidget("dojo.widget.Repeater", dojo.widget.HtmlWidget, {name:"", rowTemplate:"", myObject:null, pattern:"", useDnd:false, isContainer:true, initialize:function (args, frag) {
19
dojo.widget.defineWidget("dojo.widget.Repeater", dojo.widget.HtmlWidget, {name:"", rowTemplate:"", myObject:null, pattern:"", useDnd:false, isContainer:true, initialize:function (args, frag) {
18
	var node = this.getFragNodeRef(frag);
20
	var node = this.getFragNodeRef(frag);
19
	node.removeAttribute("dojotype");
21
	node.removeAttribute("dojotype");
20
	this.setRow(dojo.string.trim(node.innerHTML), {});
22
	this.setRow(dojo.string.trim(node.innerHTML), {});
21
	node.innerHTML = "";
23
	node.innerHTML = "";
22
	frag = null;
24
	frag = null;
23
}, postCreate:function (args, frag) {
25
}, postCreate:function (args, frag) {
24
	if (this.useDnd) {
26
	if (this.useDnd) {
25
		dojo.require("dojo.dnd.*");
27
		dojo.require("dojo.dnd.*");
26
		var dnd = new dojo.dnd.HtmlDropTarget(this.domNode, [this.widgetId]);
28
		var dnd = new dojo.dnd.HtmlDropTarget(this.domNode, [this.widgetId]);
27
	}
29
	}
28
}, _reIndexRows:function () {
30
}, _reIndexRows:function () {
29
	for (var i = 0, len = this.domNode.childNodes.length; i < len; i++) {
31
	for (var i = 0, len = this.domNode.childNodes.length; i < len; i++) {
30
		var elems = ["INPUT", "SELECT", "TEXTAREA"];
32
		var elems = ["INPUT", "SELECT", "TEXTAREA"];
31
		for (var k = 0; k < elems.length; k++) {
33
		for (var k = 0; k < elems.length; k++) {
32
			var list = this.domNode.childNodes[i].getElementsByTagName(elems[k]);
34
			var list = this.domNode.childNodes[i].getElementsByTagName(elems[k]);
33
			for (var j = 0, len2 = list.length; j < len2; j++) {
35
			for (var j = 0, len2 = list.length; j < len2; j++) {
34
				var name = list[j].name;
36
				var name = list[j].name;
35
				var index = dojo.string.escape("regexp", this.pattern);
37
				var index = dojo.string.escape("regexp", this.pattern);
36
				index = index.replace(/(%\\\{index\\\})/g, "%{index}");
38
				index = index.replace(/(%\\\{index\\\})/g, "%{index}");
37
				var nameRegexp = dojo.string.substituteParams(index, {"index":"[0-9]*"});
39
				var nameRegexp = dojo.string.substituteParams(index, {"index":"[0-9]*"});
38
				var newName = dojo.string.substituteParams(this.pattern, {"index":"" + i});
40
				var newName = dojo.string.substituteParams(this.pattern, {"index":"" + i});
39
				var re = new RegExp(nameRegexp, "g");
41
				var re = new RegExp(nameRegexp, "g");
40
				list[j].name = name.replace(re, newName);
42
				list[j].name = name.replace(re, newName);
41
			}
43
			}
42
		}
44
		}
43
	}
45
	}
44
}, onDeleteRow:function (e) {
46
}, onDeleteRow:function (e) {
45
	var index = dojo.string.escape("regexp", this.pattern);
47
	var index = dojo.string.escape("regexp", this.pattern);
46
	index = index.replace(/%\\\{index\\\}/g, "%{index}");
48
	index = index.replace(/%\\\{index\\\}/g, "%{index}");
47
	var nameRegexp = dojo.string.substituteParams(index, {"index":"([0-9]*)"});
49
	var nameRegexp = dojo.string.substituteParams(index, {"index":"([0-9]*)"});
48
	var re = new RegExp(nameRegexp, "g");
50
	var re = new RegExp(nameRegexp, "g");
49
	this.deleteRow(re.exec(e.target.name)[1]);
51
	this.deleteRow(re.exec(e.target.name)[1]);
50
}, hasRows:function () {
52
}, hasRows:function () {
51
	if (this.domNode.childNodes.length > 0) {
53
	if (this.domNode.childNodes.length > 0) {
52
		return true;
54
		return true;
53
	}
55
	}
54
	return false;
56
	return false;
55
}, getRowCount:function () {
57
}, getRowCount:function () {
56
	return this.domNode.childNodes.length;
58
	return this.domNode.childNodes.length;
57
}, deleteRow:function (idx) {
59
}, deleteRow:function (idx) {
58
	this.domNode.removeChild(this.domNode.childNodes[idx]);
60
	this.domNode.removeChild(this.domNode.childNodes[idx]);
59
	this._reIndexRows();
61
	this._reIndexRows();
60
}, _changeRowPosition:function (e) {
62
}, _changeRowPosition:function (e) {
61
	if (e.dragStatus == "dropFailure") {
63
	if (e.dragStatus == "dropFailure") {
62
		this.domNode.removeChild(e["dragSource"].domNode);
64
		this.domNode.removeChild(e["dragSource"].domNode);
63
	} else {
65
	} else {
64
		if (e.dragStatus == "dropSuccess") {
66
		if (e.dragStatus == "dropSuccess") {
65
		}
67
		}
66
	}
68
	}
67
	this._reIndexRows();
69
	this._reIndexRows();
68
}, setRow:function (template, myObject) {
70
}, setRow:function (template, myObject) {
69
	template = template.replace(/\%\{(index)\}/g, "0");
71
	template = template.replace(/\%\{(index)\}/g, "0");
70
	this.rowTemplate = template;
72
	this.rowTemplate = template;
71
	this.myObject = myObject;
73
	this.myObject = myObject;
72
}, getRow:function () {
74
}, getRow:function () {
73
	return this.rowTemplate;
75
	return this.rowTemplate;
74
}, _initRow:function (node) {
76
}, _initRow:function (node) {
75
	if (typeof (node) == "number") {
77
	if (typeof (node) == "number") {
76
		node = this.domNode.childNodes[node];
78
		node = this.domNode.childNodes[node];
77
	}
79
	}
78
	var elems = ["INPUT", "SELECT", "IMG"];
80
	var elems = ["INPUT", "SELECT", "IMG"];
79
	for (var k = 0; k < elems.length; k++) {
81
	for (var k = 0; k < elems.length; k++) {
80
		var list = node.getElementsByTagName(elems[k]);
82
		var list = node.getElementsByTagName(elems[k]);
81
		for (var i = 0, len = list.length; i < len; i++) {
83
		for (var i = 0, len = list.length; i < len; i++) {
82
			var child = list[i];
84
			var child = list[i];
83
			if (child.nodeType != 1) {
85
			if (child.nodeType != 1) {
84
				continue;
86
				continue;
85
			}
87
			}
86
			if (child.getAttribute("rowFunction") != null) {
88
			if (child.getAttribute("rowFunction") != null) {
87
				if (typeof (this.myObject[child.getAttribute("rowFunction")]) == "undefined") {
89
				if (typeof (this.myObject[child.getAttribute("rowFunction")]) == "undefined") {
88
					dojo.debug("Function " + child.getAttribute("rowFunction") + " not found");
90
					dojo.debug("Function " + child.getAttribute("rowFunction") + " not found");
89
				} else {
91
				} else {
90
					this.myObject[child.getAttribute("rowFunction")](child);
92
					this.myObject[child.getAttribute("rowFunction")](child);
91
				}
93
				}
92
			} else {
94
			} else {
93
				if (child.getAttribute("rowAction") != null) {
95
				if (child.getAttribute("rowAction") != null) {
94
					if (child.getAttribute("rowAction") == "delete") {
96
					if (child.getAttribute("rowAction") == "delete") {
95
						child.name = dojo.string.substituteParams(this.pattern, {"index":"" + (this.getRowCount() - 1)});
97
						child.name = dojo.string.substituteParams(this.pattern, {"index":"" + (this.getRowCount() - 1)});
96
						dojo.event.connect(child, "onclick", this, "onDeleteRow");
98
						dojo.event.connect(child, "onclick", this, "onDeleteRow");
97
					}
99
					}
98
				}
100
				}
99
			}
101
			}
100
		}
102
		}
101
	}
103
	}
102
}, onAddRow:function (e) {
104
}, onAddRow:function (e) {
103
}, addRow:function (doInit) {
105
}, addRow:function (doInit) {
104
	if (typeof (doInit) == "undefined") {
106
	if (typeof (doInit) == "undefined") {
105
		doInit = true;
107
		doInit = true;
106
	}
108
	}
107
	var node = document.createElement("span");
109
	var node = document.createElement("span");
108
	node.innerHTML = this.getRow();
110
	node.innerHTML = this.getRow();
109
	if (node.childNodes.length == 1) {
111
	if (node.childNodes.length == 1) {
110
		node = node.childNodes[0];
112
		node = node.childNodes[0];
111
	}
113
	}
112
	this.domNode.appendChild(node);
114
	this.domNode.appendChild(node);
113
	var parser = new dojo.xml.Parse();
115
	var parser = new dojo.xml.Parse();
114
	var frag = parser.parseElement(node, null, true);
116
	var frag = parser.parseElement(node, null, true);
115
	dojo.widget.getParser().createSubComponents(frag, this);
117
	dojo.widget.getParser().createSubComponents(frag, this);
116
	this._reIndexRows();
118
	this._reIndexRows();
117
	if (doInit) {
119
	if (doInit) {
118
		this._initRow(node);
120
		this._initRow(node);
119
	}
121
	}
120
	if (this.useDnd) {
122
	if (this.useDnd) {
121
		node = new dojo.dnd.HtmlDragSource(node, this.widgetId);
123
		node = new dojo.dnd.HtmlDragSource(node, this.widgetId);
122
		dojo.event.connect(node, "onDragEnd", this, "_changeRowPosition");
124
		dojo.event.connect(node, "onDragEnd", this, "_changeRowPosition");
123
	}
125
	}
124
	this.onAddRow(node);
126
	this.onAddRow(node);
125
}});
127
}});
126
 
128