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);
}
}
|