File: quickedit.js

package info (click to toggle)
virtuoso-opensource 6.1.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 245,116 kB
  • sloc: ansic: 639,631; sql: 439,225; xml: 287,085; java: 61,048; sh: 38,723; cpp: 36,889; cs: 25,240; php: 12,562; yacc: 9,036; lex: 7,149; makefile: 6,093; jsp: 4,447; awk: 1,643; perl: 1,017; ruby: 1,003; python: 329
file content (73 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 *  $Id: quickedit.js,v 1.6.2.4 2010/04/06 16:46:12 source Exp $
 *
 *  This file is part of the OpenLink Software Ajax Toolkit (OAT) project.
 *
 *  Copyright (C) 2005-2010 OpenLink Software
 *
 *  See LICENSE file for details.
 */
/*
	OAT.QuickEdit.assign(something,type,options)
	OAT.QuickEdit.STRING
	OAT.QuickEdit.SELECT
*/


OAT.QuickEdit = {
	STRING:1,
	SELECT:2,

	assign:function(something,type,options) {
		var elm = $(something);
		elm._QuickEdit_edit_type = type;
		if (options) { elm._QuickEdit_edit_options = options; }
		var ref = function() {
			OAT.QuickEdit.edit(elm);
		}
		OAT.Event.attach(elm,"click",ref);
	},

	edit:function(elm) {
		switch (elm._QuickEdit_edit_type) {
			case OAT.QuickEdit.STRING:
				/* create inputbox */
				var newelm = OAT.Dom.create("input");
				newelm.setAttribute("type","text");
				var content = elm.innerHTML;
				newelm.setAttribute("size",content.length+1);
				newelm.value = content;
			break;
			case OAT.QuickEdit.SELECT:
				/* create select */
				var newelm = OAT.Dom.create("select");
				var options = [];
				if (elm._QuickEdit_edit_options) { options = elm._QuickEdit_edit_options; }
				var content = elm.innerHTML;
				var index = -1;
				for (var i=0;i<options.length;i++) {
					OAT.Dom.option(options[i],options[i],newelm);
					if (content == options[i]) { index = i; }
				}
				if (index == -1) {
					OAT.Dom.option(content,content,newelm);
					newelm.selectedIndex = i;
				} else { newelm.selectedIndex = index;	}
			break;
		} /* switch */

		/* insert into hierarchy */
		elm.parentNode.replaceChild(newelm,elm);
		var callback = function() {
			OAT.QuickEdit.revert(newelm,elm);
		}
		OAT.Instant.assign(newelm,callback);
		newelm._Instant_show();
		newelm.focus();
	},

	revert:function(elm,oldelm) {
		oldelm.innerHTML = elm.value;
		elm.parentNode.replaceChild(oldelm,elm);
	}
}