а

System Migration problem


#1

Hi.

I am migrating a system with dhtmlx version 2.5 to 5 and i have a couple of functions that I do not know how to put their equivalence (since the dtmlXMLLoaderObject does not exist in the new version).

Annex the functions:

dtmlXMLLoaderObject.__eventListener = [];

dtmlXMLLoaderObject.attachEvent = function(name, catcher, callObj) {
name = ‘ev_’ + name.toLowerCase();
if (!dtmlXMLLoaderObject.__eventListener[name])
dtmlXMLLoaderObject.__eventListener[name] = new dtmlXMLLoaderObject.eventCatcher(callObj || dtmlXMLLoaderObject);

return (name + ':' + dtmlXMLLoaderObject.__eventListener[name].addEvent(catcher))

};

dtmlXMLLoaderObject.detachEvent = function(id) {
if (id != false) {
var list = id.split(’:’);
dtmlXMLLoaderObject.__eventListener[list[0]].removeEvent(list[1])
}
}

dtmlXMLLoaderObject.callEvent = function(name, arg0) {
name = ‘ev_’ + name.toLowerCase();
if (dtmlXMLLoaderObject.__eventListener[name])
return dtmlXMLLoaderObject.__eventListener[name].apply(this, arg0);

return true

};

dtmlXMLLoaderObject.checkEvent = function(name) {
return (!!dtmlXMLLoaderObject._eventListener['ev’ + name.toLowerCase()])
};

dtmlXMLLoaderObject.eventCatcher = function(obj) {
var dhx_catch = [];
var z = function() {
var res = true;
for (var i = 0; i < dhx_catch.length; i++) {
if (dhx_catch[i] != null) {
var zr = dhx_catch[i].apply(obj, arguments);
res = res && zr
}
};
return res
};
z.addEvent = function(ev) {
if (typeof (ev) != “function”)
ev = eval(ev);
if (ev)
return dhx_catch.push(ev) - 1;
return false
};
z.removeEvent = function(id) {
dhx_catch[id] = null
};
return z
};

dtmlXMLLoaderObject.prototype.waitLoadFunction = function(dhtmlObject) {
var waitLoadFunction = dtmlXMLLoaderObject.prototype.__waitLoadFunction.apply(this, arguments);
var once = [];
return function() {
if (dhtmlObject.xmlDoc != null) {
if (dhtmlObject.xmlDoc.readyState) {
if (!once[dhtmlObject.xmlDoc.readyState]) {
once[dhtmlObject.xmlDoc.readyState] = true;
var args = [dhtmlObject, dhtmlObject.xmlDoc];
switch (dhtmlObject.xmlDoc.readyState) {
case 1: //Open
dtmlXMLLoaderObject.callEvent(“openRequest”, args);
break;
case 2: //Sent
dtmlXMLLoaderObject.callEvent(“beginRequest”, args);
break;
case 3: //Retrieving
dtmlXMLLoaderObject.callEvent(“receivingRequest”, args);
break;
case 4: //Ok
dtmlXMLLoaderObject.callEvent(“endRequest”, args);
break;
}
}
}
}

    return waitLoadFunction();
};

};

dtmlXMLLoaderObject.prototype.__loadXML = dtmlXMLLoaderObject.prototype.loadXML;

dtmlXMLLoaderObject.prototype.loadXML = function(filePath, postMode, postVars, rpc) {
var tmpFilePath = filePath;
if (this.rSeed)
tmpFilePath += ((tmpFilePath.indexOf("?") != -1) ? “&” : “?”) + “a_dhx_rSeed=” + (new Date()).valueOf();

this.filePath = tmpFilePath;

var args = [this, this.xmlDoc];
dtmlXMLLoaderObject.callEvent("initializeRequest", args);
if (!this.async) {
    dtmlXMLLoaderObject.callEvent("beginRequest", args);
}

return dtmlXMLLoaderObject.prototype.__loadXML.apply(this, arguments);

};

dtmlXMLLoaderObject.prototype.getFileExtension = function() {
var filePath = this.filePath;
var index = filePath.indexOf("?");
if (index > 0) {
filePath = filePath.substring(0, index);
}

index = filePath.lastIndexOf(".");
if (index > 0 && index < filePath.length - 1) {
    filePath = filePath.substring(index + 1);
}    
return filePath;

};

Does anyone know how to do it?


#2

Unfortunately as there is no dtmlXMLLoaderObject anymore the similar integration is not available.
Your may place all your custom events in the “_call” function. It can be found in the dhtmlxcommon.js source file.
as about the “getFileExtension” function - such function creation is not available now.


#3

Thanks for your answer sematik.
Do you have any examples that can help me?

Best regards.