Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Go to most recent revision | 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
 
11
dojo.provide("dojo.widget.InlineEditBox");
12
dojo.require("dojo.widget.*");
13
dojo.require("dojo.event.*");
14
dojo.require("dojo.lfx.*");
15
dojo.require("dojo.gfx.color");
16
dojo.require("dojo.string");
17
dojo.require("dojo.html.*");
18
dojo.require("dojo.html.layout");
19
dojo.widget.defineWidget("dojo.widget.InlineEditBox", dojo.widget.HtmlWidget, function () {
20
	this.history = [];
21
}, {templateString:"<form class=\"inlineEditBox\" style=\"display: none\" dojoAttachPoint=\"form\" dojoAttachEvent=\"onSubmit:saveEdit; onReset:cancelEdit; onKeyUp: checkForValueChange;\">\n\t<input type=\"text\" dojoAttachPoint=\"text\" style=\"display: none;\" />\n\t<textarea dojoAttachPoint=\"textarea\" style=\"display: none;\"></textarea>\n\t<input type=\"submit\" value=\"Save\" dojoAttachPoint=\"submitButton\" />\n\t<input type=\"reset\" value=\"Cancel\" dojoAttachPoint=\"cancelButton\" />\n</form>\n", templateCssString:".editLabel {\n\tfont-size : small;\n\tpadding : 0 5px;\n\tdisplay : none;\n}\n\n.editableRegionDisabled {\n\tcursor : pointer;\n\t_cursor : hand;\n}\n\n.editableRegion {\n\tbackground-color : #ffc !important;\n\tcursor : pointer;\n\t_cursor : hand;\n}\n\n.editableRegion .editLabel {\n\tdisplay : inline;\n}\n\n.editableTextareaRegion .editLabel {\n\tdisplay : block;\n}\n\n.inlineEditBox {\n\t/*background-color : #ffc;*/\n\tdisplay : inline;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/InlineEditBox.css"), mode:"text", name:"", minWidth:100, minHeight:200, editing:false, value:"", textValue:"", defaultText:"", postMixInProperties:function () {
22
	if (this.textValue) {
23
		dojo.deprecated("InlineEditBox: Use value parameter instead of textValue; will be removed in 0.5");
24
		this.value = this.textValue;
25
	}
26
	if (this.defaultText) {
27
		dojo.deprecated("InlineEditBox: Use value parameter instead of defaultText; will be removed in 0.5");
28
		this.value = this.defaultText;
29
	}
30
}, postCreate:function (args, frag) {
31
	this.editable = this.getFragNodeRef(frag);
32
	dojo.html.insertAfter(this.editable, this.form);
33
	dojo.event.connect(this.editable, "onmouseover", this, "onMouseOver");
34
	dojo.event.connect(this.editable, "onmouseout", this, "onMouseOut");
35
	dojo.event.connect(this.editable, "onclick", this, "_beginEdit");
36
	if (this.value) {
37
		this.editable.innerHTML = this.value;
38
		return;
39
	} else {
40
		this.value = dojo.string.trim(this.editable.innerHTML);
41
		this.editable.innerHTML = this.value;
42
	}
43
}, onMouseOver:function () {
44
	if (!this.editing) {
45
		if (this.disabled) {
46
			dojo.html.addClass(this.editable, "editableRegionDisabled");
47
		} else {
48
			dojo.html.addClass(this.editable, "editableRegion");
49
			if (this.mode == "textarea") {
50
				dojo.html.addClass(this.editable, "editableTextareaRegion");
51
			}
52
		}
53
	}
54
}, onMouseOut:function () {
55
	if (!this.editing) {
56
		dojo.html.removeClass(this.editable, "editableRegion");
57
		dojo.html.removeClass(this.editable, "editableTextareaRegion");
58
		dojo.html.removeClass(this.editable, "editableRegionDisabled");
59
	}
60
}, _beginEdit:function (e) {
61
	if (this.editing || this.disabled) {
62
		return;
63
	}
64
	this.onMouseOut();
65
	this.editing = true;
66
	var ee = this[this.mode.toLowerCase()];
67
	ee.value = dojo.string.trim(this.value);
68
	ee.style.fontSize = dojo.html.getStyle(this.editable, "font-size");
69
	ee.style.fontWeight = dojo.html.getStyle(this.editable, "font-weight");
70
	ee.style.fontStyle = dojo.html.getStyle(this.editable, "font-style");
71
	var bb = dojo.html.getBorderBox(this.editable);
72
	ee.style.width = Math.max(bb.width, this.minWidth) + "px";
73
	if (this.mode.toLowerCase() == "textarea") {
74
		ee.style.display = "block";
75
		ee.style.height = Math.max(bb.height, this.minHeight) + "px";
76
	} else {
77
		ee.style.display = "";
78
	}
79
	this.form.style.display = "";
80
	this.editable.style.display = "none";
81
	ee.focus();
82
	ee.select();
83
	this.submitButton.disabled = true;
84
}, saveEdit:function (e) {
85
	e.preventDefault();
86
	e.stopPropagation();
87
	var ee = this[this.mode.toLowerCase()];
88
	if ((this.value != ee.value) && (dojo.string.trim(ee.value) != "")) {
89
		this.doFade = true;
90
		this.history.push(this.value);
91
		this.onSave(ee.value, this.value, this.name);
92
		this.value = ee.value;
93
		this.editable.innerHTML = "";
94
		var textNode = document.createTextNode(this.value);
95
		this.editable.appendChild(textNode);
96
	} else {
97
		this.doFade = false;
98
	}
99
	this._finishEdit(e);
100
}, _stopEditing:function () {
101
	this.editing = false;
102
	this.form.style.display = "none";
103
	this.editable.style.display = "";
104
	return true;
105
}, cancelEdit:function (e) {
106
	this._stopEditing();
107
	this.onCancel();
108
	return true;
109
}, _finishEdit:function (e) {
110
	this._stopEditing();
111
	if (this.doFade) {
112
		dojo.lfx.highlight(this.editable, dojo.gfx.color.hex2rgb("#ffc"), 700).play(300);
113
	}
114
	this.doFade = false;
115
}, setText:function (txt) {
116
	dojo.deprecated("setText() is deprecated, call setValue() instead, will be removed in 0.5");
117
	this.setValue(txt);
118
}, setValue:function (txt) {
119
	txt = "" + txt;
120
	var tt = dojo.string.trim(txt);
121
	this.value = tt;
122
	this.editable.innerHTML = tt;
123
}, undo:function () {
124
	if (this.history.length > 0) {
125
		var curValue = this.value;
126
		var value = this.history.pop();
127
		this.editable.innerHTML = value;
128
		this.value = value;
129
		this.onUndo(value);
130
		this.onSave(value, curValue, this.name);
131
	}
132
}, onChange:function (newValue, oldValue) {
133
}, onSave:function (newValue, oldValue, name) {
134
}, onCancel:function () {
135
}, checkForValueChange:function () {
136
	var ee = this[this.mode.toLowerCase()];
137
	if ((this.value != ee.value) && (dojo.string.trim(ee.value) != "")) {
138
		this.submitButton.disabled = false;
139
	}
140
	this.onChange(this.value, ee.value);
141
}, disable:function () {
142
	this.submitButton.disabled = true;
143
	this.cancelButton.disabled = true;
144
	var ee = this[this.mode.toLowerCase()];
145
	ee.disabled = true;
146
	dojo.widget.InlineEditBox.superclass.disable.apply(this, arguments);
147
}, enable:function () {
148
	this.checkForValueChange();
149
	this.cancelButton.disabled = false;
150
	var ee = this[this.mode.toLowerCase()];
151
	ee.disabled = false;
152
	dojo.widget.InlineEditBox.superclass.enable.apply(this, arguments);
153
}});
154