= 0) item.className = String(item.className).replace(/disabled/gi,"");
item._enabled = true;
},
disable: function(item) {
if (String(item.className).search("disabled") < 0) item.className += " disabled";
item._enabled = false;
},
setText: function(item, text) {
item.firstChild.innerHTML = text;
},
getText: function(item) {
return item.firstChild.innerHTML;
}
};
(function(){
for (var a in {doUnloadNestedLists:1,isEnabled:1})
dhtmlXForm.prototype.items.label[a] = dhtmlXForm.prototype.items.checkbox[a];
})();
/* button */
dhtmlXForm.prototype.items.button = {
render: function(item, data) {
item._type = "bt";
item._enabled = true;
item._name = data.name;
item.className = String(item.className).replace("item_label_top","item_label_left").replace("item_label_right","item_label_left");
item._doOnKeyUpDown = function(evName, evObj) {
this.callEvent(evName, [this.childNodes[0].childNodes[0], evObj, this._idd]);
}
item.innerHTML = '';
if (!isNaN(data.width)) {
var w = Math.max(data.width,10);
if (dhtmlXForm.prototype.items[this.t]._dim == null) {
item.firstChild.style.width = w+"px";
dhtmlXForm.prototype.items[this.t]._dim = item.getForm()._checkDim(item, item.firstChild);
}
item.firstChild.style.width = w-dhtmlXForm.prototype.items[this.t]._dim+"px";
item.firstChild.firstChild.className += " dhxform_btn_txt_autowidth";
}
if (!isNaN(data.inputLeft)) item.childNodes[0].style.left = parseInt(data.inputLeft)+"px";
if (!isNaN(data.inputTop)) item.childNodes[0].style.top = parseInt(data.inputTop)+"px";
if (data.hidden == true) this.hide(item);
if (data.disabled == true) this.userDisable(item);
if (typeof(data.tooltip) != "undefined") item.firstChild.title = data.tooltip;
// item onselectstart also needed once
// will reconstructed!
item.onselectstart = function(e){
e = e||event;
e.cancelBubble = true;
if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
return false;
}
item.firstChild.onselectstart = function(e){
e = e||event;
e.cancelBubble = true;
if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
return false;
}
item.firstChild.onkeypress = function(e) {
e = e||event
if ((e.keyCode == 32 || e.charCode == 32 || e.keyCode == 13 || e.charCode == 13) && !this.parentNode._busy) {
this.parentNode._busy = true;
e.cancelBubble = true;
if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
_dhxForm_doClick(this.childNodes[0], ["mousedown", "mouseup"]);
return false;
}
}
item.firstChild.onfocus = function() {
this.parentNode._doOnFocus(this.parentNode);
}
item.firstChild.onblur = function() {
_dhxForm_doClick(this.childNodes[0], "mouseout");
this.parentNode._doOnBlur(this.parentNode);
}
item.firstChild.onkeyup = function(e) {
this.parentNode._doOnKeyUpDown("onKeyUp", e||event);
}
item.firstChild.onkeydown = function(e) {
this.parentNode._doOnKeyUpDown("onKeyDown", e||event);
}
item.firstChild.onmouseover = function(){
var t = this.parentNode;
if (!t._enabled) return;
this._isOver = true;
this.className = "dhxform_btn dhxform_btn_over";
t = null;
}
item.firstChild.onmouseout = function(){
var t = this.parentNode;
if (!t._enabled) return;
this.className = "dhxform_btn";
this._allowClick = false;
this._pressed = false;
this._isOver = false;
t = null;
}
item.firstChild.ontouchstart = item.firstChild.onmousedown = function(e){
e = e||event;
if (e.type == "touchstart" && e.preventDefault) e.preventDefault();
if (e.button >= 2) return; // ie=0/other=1
if (this._pressed) return;
var t = this.parentNode;
if (!t._enabled) return;
this.className = "dhxform_btn dhxform_btn_pressed";
this._allowClick = true;
this._pressed = true;
t = null;
}
item.firstChild.ontouchend = item.firstChild.onmouseup = function(e){
e = e||event;
if (e.button >= 2) return;
if (!this._pressed) return;
var t = this.parentNode;
if (!t._enabled) return;
t._busy = false;
this.className = "dhxform_btn"+(this._isOver?" dhxform_btn_over":"");
if (this._pressed && this._allowClick) t.callEvent("_onButtonClick", [t._name, t._cmd]);
this._allowClick = false;
this._pressed = false;
t = null;
}
item._doOnFocus = function(item) {
item.getForm().callEvent("onFocus",[item._idd]);
}
item._doOnBlur = function(item) {
item.getForm().callEvent("onBlur",[item._idd]);
}
return this;
},
destruct: function(item) {
this.doUnloadNestedLists(item);
item.callEvent = null;
item.checkEvent = null;
item.getForm = null;
item._autoCheck = null;
item._type = null;
item._enabled = null;
item._cmd = null;
item._name = null;
item._doOnFocus = null;
item._doOnBlur = null;
item._doOnKeyUpDown = null;
item.onselectstart = null;
item.firstChild.onselectstart = null;
item.firstChild.onkeypress = null;
item.firstChild.ontouchstart = null;
item.firstChild.ontouchend = null;
item.firstChild.onfocus = null;
item.firstChild.onblur = null;
item.firstChild.onkeyup = null;
item.firstChild.onkeydown = null;
item.firstChild.onmouseover = null;
item.firstChild.onmouseout = null;
item.firstChild.onmousedown = null;
item.firstChild.onmouseup = null;
while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]);
item.parentNode.removeChild(item);
item = null;
},
enable: function(item) {
if (String(item.className).search("disabled") >= 0) item.className = String(item.className).replace(/disabled/gi,"");
item._enabled = true;
item.childNodes[0].removeAttribute("disabled");
item.childNodes[0].setAttribute("role", "link");
item.childNodes[0].setAttribute("tabIndex", "0");
},
disable: function(item) {
if (String(item.className).search("disabled") < 0) item.className += " disabled";
item._enabled = false;
item.childNodes[0].setAttribute("disabled", "true");
item.childNodes[0].removeAttribute("role");
item.childNodes[0].removeAttribute("tabIndex");
},
setText: function(item, text) {
item.childNodes[0].childNodes[0].innerHTML = text;
},
getText: function(item) {
return item.childNodes[0].childNodes[0].innerHTML;
},
setFocus: function(item) {
item.childNodes[0].focus();
}
};
(function(){
for (var a in {doUnloadNestedLists:1,isEnabled:1})
dhtmlXForm.prototype.items.button[a] = dhtmlXForm.prototype.items.checkbox[a];
})();
/* hidden item */
dhtmlXForm.prototype.items.hidden = {
_index: false,
render: function(item, data) {
item.style.display = "none";
item._name = data.name;
item._type = "hd";
item._enabled = true;
var t = document.createElement("INPUT");
t.type = "HIDDEN";
t.name = data.name;
t.value = (data.value||"")
item.appendChild(t);
return this;
},
destruct: function(item) {
this.doUnloadNestedLists(item);
while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]);
item._autoCheck = null;
item._name = null;
item._type = null;
item._enabled = null;
item.onselectstart = null;
item.callEvent = null;
item.checkEvent = null;
item.getForm = null;
item.parentNode.removeChild(item);
item = null;
},
enable: function(item) {
item._enabled = true;
item.childNodes[0].setAttribute("name", item._name);
},
disable: function(item) {
item._enabled = false;
item.childNodes[0].removeAttribute("name");
},
show: function() {
},
hide: function() {
},
isHidden: function() {
return true;
},
setValue: function(item, val) {
item.childNodes[0].value = val;
},
getValue: function(item) {
return item.childNodes[0].value;
},
getInput: function(item) {
return item.childNodes[0];
}
};
(function(){
for (var a in {doUnloadNestedLists:1,isEnabled:1})
dhtmlXForm.prototype.items.hidden[a] = dhtmlXForm.prototype.items.checkbox[a];
})();
/* sub list */
dhtmlXForm.prototype.items.list = {
_index: false,
render: function(item, skin) {
item._type = "list";
item._enabled = true;
item._isNestedForm = true;
item.style.paddingLeft = item._ofsNested+"px";
item.className = "dhxform_base_nested"+(item._custom_css||"");
return [this, new dhtmlXForm(item, null, skin)];
},
destruct: function(item) {
// linked to _listBase
// automaticaly cleared when parent item unloaded
}
};
/* fieldset */
dhtmlXForm.prototype.items.fieldset = {
_index: false,
render: function(item, data) {
item._type = "fs";
if (typeof(parseInt(data.inputWidth)) == "number") {
// if (window.dhx4.isFF||window.dhx4.isOpera) data.inputWidth -= 12;
// chrome-11/ie9 - ok
}
item._width = data.width;
item._enabled = true;
item._checked = true; // required for authoCheck
item.className = "fs_"+data.position+(typeof(data.className)=="string"?" "+data.className:"");
var f = document.createElement("FIELDSET");
f.className = "dhxform_fs";
var align = String(data.labelAlign).replace("align_","");
f.innerHTML = "";
item.appendChild(f);
if (!isNaN(data.inputLeft)) f.style.left = parseInt(data.inputLeft)+"px";
if (!isNaN(data.inputTop)) f.style.top = parseInt(data.inputTop)+"px";
if (data.inputWidth != "auto") {
if (!isNaN(data.inputWidth)) {
f.style.width = parseInt(data.inputWidth)+"px";
var w = parseInt(f.style.width);
if (f.offsetWidth > w) f.style.width = w+(w-f.offsetWidth)+"px";
}
}
item._addSubListNode = function() {
var t = document.createElement("DIV");
t._custom_css = " dhxform_fs_nested";
this.childNodes[0].appendChild(t);
return t;
}
if (data.hidden == true) this.hide(item);
if (data.disabled == true) this.userDisable(item);
return this;
},
destruct: function(item) {
this.doUnloadNestedLists(item);
item._checked = null;
item._enabled = null;
item._idd = null;
item._type = null;
item._width = null;
item.onselectstart = null;
item._addSubListNode = null;
item._autoCheck = null;
item.callEvent = null;
item.checkEvent = null;
item.getForm = null;
while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]);
item.parentNode.removeChild(item);
item = null;
},
setText: function(item, text) {
item.childNodes[0].childNodes[0].innerHTML = text;
},
getText: function(item) {
return item.childNodes[0].childNodes[0].innerHTML;
},
enable: function(item) {
item._enabled = true;
if (String(item.className).search("disabled") >= 0) item.className = String(item.className).replace(/disabled/gi,"");
},
disable: function(item) {
item._enabled = false;
if (String(item.className).search("disabled") < 0) item.className += " disabled";
},
setWidth: function(item, width) {
item.childNodes[0].style.width = width+"px";
item._width = width;
},
getWidth: function(item) {
return item._width;
}
};
(function(){
for (var a in {doUnloadNestedLists:1,isEnabled:1})
dhtmlXForm.prototype.items.fieldset[a] = dhtmlXForm.prototype.items.checkbox[a];
})();
/* block */
dhtmlXForm.prototype.items.block = {
_index: false,
render: function(item, data) {
item._type = "bl";
item._width = data.width;
item._enabled = true;
item._checked = true; // required for authoCheck
item.className = "block_"+data.position+(typeof(data.className)=="string"?" "+data.className:"");
var b = document.createElement("DIV");
b.className = "dhxform_obj_"+item.getForm().skin+" dhxform_block";
b.style.fontSize = item.getForm().cont.style.fontSize;
if (data.style) b.style.cssText = data.style;
if (typeof(data.id) != "undefined") b.id = data.id;
item.appendChild(b);
if (!isNaN(data.inputLeft)) b.style.left = parseInt(data.inputLeft)+"px";
if (!isNaN(data.inputTop)) b.style.top = parseInt(data.inputTop)+"px";
if (data.inputWidth != "auto") if (!isNaN(data.inputWidth)) b.style.width = parseInt(data.inputWidth)+"px";
if (!isNaN(data.blockOffset)) {
item._ofsNested = data.blockOffset;
}
item._addSubListNode = function() {
var t = document.createElement("DIV");
t._inBlcok = true;
if (typeof(this._ofsNested) != "undefined") t._ofsNested = this._ofsNested;
this.childNodes[0].appendChild(t);
return t;
}
if (data.hidden == true) this.hide(item);
if (data.disabled == true) this.userDisable(item);
return this;
},
_setCss: function(item, skin, fontSize) {
item.firstChild.className = "dhxform_obj_"+skin+" dhxform_block";
item.firstChild.style.fontSize = fontSize;
}
};
(function(){
for (var a in {enable:1,disable:1,isEnabled:1,setWidth:1,getWidth:1,doUnloadNestedLists:1,destruct:1})
dhtmlXForm.prototype.items.block[a] = dhtmlXForm.prototype.items.fieldset[a];
})();
/* new column */
dhtmlXForm.prototype.items.newcolumn = {
_index: false
};
/* template */
dhtmlXForm.prototype.items.template = {
render: function(item, data) {
var ta = (!isNaN(data.rows));
item._type = "tp";
item._enabled = true;
if (data.format != null) {
if (typeof(data.format) == "function") {
item.format = data.format;
} else if (typeof(data.format) == "string" && typeof(window[data.format]) == "function") {
item.format = window[data.format];
}
}
if (item.format == null) {
item.format = function(name, value) { return value; }
}
this.doAddLabel(item, data);
this.doAddInput(item, data, "DIV", null, true, true, "dhxform_item_template");
this.setValue(item, data.value||"");
return this;
},
destruct: function(item) {
item.format = null;
this.d2(item);
item = null;
},
setValue: function(item, value) {
item._value = value;
item.childNodes[item._ll?1:0].childNodes[0].innerHTML = item.format(item._idd, item._value);
},
getValue: function(item) {
return item._value;
},
enable: function(item) {
if (String(item.className).search("disabled") >= 0) item.className = String(item.className).replace(/disabled/gi,"");
item._enabled = true;
},
disable: function(item) {
if (String(item.className).search("disabled") < 0) item.className += " disabled";
item._enabled = false;
}
};
(function(){
dhtmlXForm.prototype.items.template.d2 = dhtmlXForm.prototype.items.input.destruct;
for (var a in {doAddLabel:1,doAddInput:1,doUnloadNestedLists:1,setText:1,getText:1,isEnabled:1,setWidth:1})
dhtmlXForm.prototype.items.template[a] = dhtmlXForm.prototype.items.select[a];
})();
//loading from UL list
dhtmlXForm.prototype._ulToObject = function(ulData, a) {
var obj = [];
for (var q=0; q= 0) this.cont.className = String(this.cont.className).replace(/dhxform_rtl/gi,"");
}
};
_dhxForm_doClick = function(obj, evType) {
if (typeof(evType) == "object") {
var t = evType[1];
evType = evType[0];
}
if (document.createEvent) {
var e = document.createEvent("MouseEvents");
e.initEvent(evType, true, false);
obj.dispatchEvent(e);
} else if (document.createEventObject) {
var e = document.createEventObject();
e.button = 1;
obj.fireEvent("on"+evType, e);
}
if (t) window.setTimeout(function(){_dhxForm_doClick(obj,t);},100);
}
dhtmlXForm.prototype.setFormData = function(t) {
for (var a in t) {
var r = this.getItemType(a);
switch (r) {
case "checkbox":
this[t[a]==true||parseInt(t[a])==1||t[a]=="true"||t[a]==this.getItemValue(a, "realvalue")?"checkItem":"uncheckItem"](a);
break;
case "radio":
this.checkItem(a,t[a]);
break;
case "input":
case "textarea":
case "password":
case "select":
case "multiselect":
case "hidden":
case "template":
case "combo":
case "calendar":
case "colorpicker":
case "editor":
this.setItemValue(a,t[a]);
break;
default:
if (this["setFormData_"+r]) {
// check for custom cell
this["setFormData_"+r](a,t[a]);
} else {
// if item with specified name not found, keep value in userdata
if (!this.hId) this.hId = this._genStr(12);
this.setUserData(this.hId, a, t[a]);
}
break;
}
}
};
dhtmlXForm.prototype.getFormData = function(p0, only_fields) {
var r = {};
var that = this;
for (var a in this.itemPull) {
var i = this.itemPull[a]._idd;
var t = this.itemPull[a]._type;
if (t == "ch") r[i] = (this.isItemChecked(i)?this.getItemValue(i):0);
if (t == "ra" && !r[this.itemPull[a]._group]) r[this.itemPull[a]._group] = this.getCheckedValue(this.itemPull[a]._group);
if (t in {se:1,ta:1,pw:1,hd:1,tp:1,fl:1,calendar:1,combo:1,editor:1,colorpicker:1}) r[i] = this.getItemValue(i,p0);
// check for custom cell
if (this["getFormData_"+t]) r[i] = this["getFormData_"+t](i);
// merge with files/uploader
if (t == "up") {
var r0 = this.getItemValue(i);
for (var a0 in r0) r[a0] = r0[a0];
}
//
if (this.itemPull[a]._list) {
for (var q=0; q ky) ky = this.base[q].offsetHeight;
}
// check if layout
var isLayout = false;
try {
isLayout = (this.cont.parentNode.parentNode.parentNode.parentNode._isCell==true);
if (isLayout) var layoutCell = this.cont.parentNode.parentNode.parentNode.parentNode;
} catch(e){};
if (isLayout && typeof(layoutCell) != "undefined") {
if (kx > 0) layoutCell.setWidth(kx+10);
if (ky > 0) layoutCell.setHeight(ky+layoutCell.firstChild.firstChild.offsetHeight+5);
isLayout = layoutCell = null;
return;
}
// check if window
var isWindow = false;
try {
isWindow = (this.cont.parentNode.parentNode.parentNode._isWindow == true);
if (isWindow) {
var winCell = this.cont.parentNode.parentNode;
if (typeof(winCell.callEvent) == "function") {
this.cont.style.display = "none";
winCell.callEvent("_setCellSize", [kx+15,ky+15]);
this.cont.style.display = "";
}
}
} catch(e){};
};
// dataproc
dhtmlXForm.prototype.reset = function() {
if (this.callEvent("onBeforeReset", [this.formId, this.getFormData()])) {
if (this._last_load_data) this.setFormData(this._last_load_data);
this.callEvent("onAfterReset", [this.formId]);
}
};
dhtmlXForm.prototype.send = function(url, mode, callback, skipValidation) {
if (typeof mode == "function") {
callback = mode;
mode = "post";
} else {
mode = (mode=="get"?"get":"post");
}
if (skipValidation !== true && !this.validate()) return;
var formData = this.getFormData(true);
var data = [];
for (var key in formData) data.push(key+"="+encodeURIComponent(formData[key]));
var afterload = function(loader) {
if (callback) callback.call(this, loader, loader.xmlDoc.responseText);
};
if (mode == "get") {
window.dhx4.ajax.get(url+(url.indexOf("?")==-1?"?":"&")+data.join("&"), afterload);
} else {
window.dhx4.ajax.post(url, data.join("&"), afterload);
}
};
dhtmlXForm.prototype.save = function(url, type){};
dhtmlXForm.prototype.dummy = function(){};
dhtmlXForm.prototype._changeFormId = function(oldid, newid) {
this.formId = newid;
};
dhtmlXForm.prototype._dp_init = function(dp) {
dp._methods = ["dummy", "dummy", "_changeFormId", "dummy"];
dp._getRowData = function(id, pref) {
var data = this.obj.getFormData(true);
data[this.action_param] = this.obj.getUserData(id, this.action_param);
return data;
};
dp._clearUpdateFlag = function(){};
dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag){
if (action == "inserted" || action == "updated" || action == "error" || action == "invalid")
this.obj.resetDataProcessor("updated");
if (action == "inserted" || action == "updated")
this.obj._last_load_data = this.obj.getFormData(true);
this.obj.callEvent("onAfterSave",[this.obj.formId, tag]);
return true;
});
dp.autoUpdate = false;
dp.setTransactionMode("POST", true);
this.dp = dp;
this.formId = (new Date()).valueOf();
this.resetDataProcessor("inserted");
this.save = function(){
if (!this.callEvent("onBeforeSave", [this.formId, this.getFormData()])) return;
if (!this.validate()) return;
dp.sendData();
};
};
dhtmlXForm.prototype.resetDataProcessor = function(mode){
if (!this.dp) return;
this.dp.updatedRows = []; this.dp._in_progress = [];
this.dp.setUpdated(this.formId, true, mode);
};
// cc listener
dhtmlXForm.prototype._ccActivate = function(id, inp, val) {
if (!this._formLS) this._formLS = {};
if (!this._formLS[id]) this._formLS[id] = {input: inp, value: val};
if (!this._ccActive) {
this._ccActive = true;
this._ccDo();
}
inp = null;
};
dhtmlXForm.prototype._ccDeactivate = function(id) {
if (this._ccTm) window.clearTimeout(this._ccTm);
this._ccActive = false;
if (this._formLS != null && this._formLS[id] != null) {
this._formLS[id].input = null;
this._formLS[id] = null;
delete this._formLS[id];
}
};
dhtmlXForm.prototype._ccDo = function() {
if (this._ccTm) window.clearTimeout(this._ccTm);
for (var a in this._formLS) {
var inp = this._formLS[a].input;
if (String(inp.tagName).toLowerCase() == "select") {
var v = "";
if (inp.selectedIndex >= 0 && inp.selectedIndex < inp.options.length) v = inp.options[inp.selectedIndex].value;
} else {
var v = inp.value;
}
if (v != this._formLS[a].value) {
this._formLS[a].value = v;
this.callEvent("onInputChange",[inp._idd,v,this]);
}
inp = null;
}
if (this._ccActive) {
var t = this;
this._ccTm = window.setTimeout(function(){t._ccDo();t=null;},100);
}
};
dhtmlXForm.prototype._ccReload = function(id, value) { // update item's value while item have focus
if (this._formLS && this._formLS[id]) {
this._formLS[id].value = value;
}
};
dhtmlXForm.prototype._checkDim = function(formNode, inpObj) {
var testNode = document.createElement("DIV");
testNode.className = "dhxform_obj_"+this.skin;
testNode.style.cssText += (dhx4.isIE6==true?"visibility:hidden;":"position:absolute;left:-2000px;top:-1000px;");
document.body.appendChild(testNode);
var pNode = formNode.parentNode;
var sNode = formNode.nextSibling;
testNode.appendChild(formNode);
var w = parseInt(inpObj.style.width);
var w2 = (dhx4.isFF || dhx4.isIE || dhx4.isChrome || dhx4.isOpera ? inpObj.offsetWidth : inpObj.clientWidth);
var dim = w2-w;
if (sNode != null) pNode.insertBefore(formNode, sNode); else pNode.appendChild(formNode);
testNode.parentNode.removeChild(testNode);
pNode = sNode = testNode = formNode = inpObj = null;
return dim;
};
(function(){
var a = [
"ftype", "name", "value", "label", "check", "checked", "disabled", "text", "rows", "select", "selected", "width", "style", "className",
"labelWidth", "labelHeight", "labelLeft", "labelTop", "inputWidth", "inputHeight", "inputLeft", "inputTop", "position", "size", "hidden"
];
dhtmlXForm.prototype.loadStructHTML = function(el){
var el = typeof el === "string" ? document.getElementById(el) : el;
this.loadStruct(this._ulToObject(el, a))
}
dhtmlXForm.prototype._autoload = function() {
var k = document.getElementsByTagName("UL");
var u = [];
for (var q=0; q