AIM = {
frame : function(c) {
var n = 'f' + Math.floor(Math.random() * 99999);
var d = document.createElement('DIV');
d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
document.body.appendChild(d);
var i = document.getElementById(n);
if (c && typeof(c.onComplete) == 'function') {
i.onComplete = c.onComplete;
}
return n;
},
form : function(f, name) {
f.setAttribute('target', name);
},
submit : function(f, c) {
AIM.form(f, AIM.frame(c));
if (c && typeof(c.onStart) == 'function') {
return c.onStart();
} else {
return true;
}
},
loaded : function(id) {
var i = document.getElementById(id);
if (i.contentDocument) {
var d = i.contentDocument;
} else if (i.contentWindow) {
var d = i.contentWindow.document;
} else {
var d = window.frames[id].document;
}
if (d.location.href == "about:blank") {
return;
}
if (typeof(i.onComplete) == 'function') {
i.onComplete(d.body.innerHTML);
}
}
};
function UploadPlan(project_id,filename,ext){
this.project_id = project_id;
this.project_ids = new Array();
this.filename = filename;
this.ext = ext;
//vaste elementen
this.inputName = 'uploadplan';
this.inputId = this.project_id+'_'+this.filename+''+this.ext;
this.classUrl = '/scripts/classes/starters/startsimulator/UploadPlan.jsp';
this.uploadplanResults = new Array();
//getters and setters
this.getProjectId = function(){
return this.project_id;
};
this.setProjectId = function(project_id){
this.project_id = project_id;
};
//searcher
this.setProjectIds = function(project_id){
this.project_ids.push(project_id);
};
this.resetProjectIds = function(){
this.project_ids = new Array();
};
this.getFilename = function(){
return this.filename;
};
this.setFilename = function(filename){
this.filename = filename;
};
this.getExt = function(){
return this.ext;
};
this.setExt = function(ext){
this.ext = ext;
};
this.getFullFilename = function(){
return this.filename+'.'+this.ext;
};
this.getSrc = function(){
return this.project_id+'_'+this.getFullFilename();
}
this.load = function(func){
var t = this;
var req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
var xml = req.responseXML;
if (xml.documentElement) {
t.loadXML(xml,0);
if (func) eval(func);
}
}
}
}
req.open('GET', this.classUrl+'?ac=load&project_id='+this.project_id+'&filename='+this.filename+'&ext='+this.ext+'&noCache='+new Date().getTime()); //asynchroon
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-15');
req.send(null);
};
this.loadXML = function(xml,index){
var root = xml.getElementsByTagName('uploadplan')[index];
this.setProjectId(this.getNodeValue(root,'project_id'));
this.setFilename(this.getNodeValue(root,'filename'));
this.setExt(this.getNodeValue(root,'ext'));
};
this.save = function(func){
var t = this;
var req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
var xml = req.responseXML;
if (xml.documentElement) {
t.loadXML(xml,0);
if (t.inputId == 0){
//rename id's
//t.renameForm(0,t.getId());
}
if (func) eval(func);
}
}
}
}
var params = "";
params+= "&project_id="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'project_id'))? params+= document.getElementById(this.inputName+'.'+this.inputId+'.'+'project_id').value : params+=this.getProjectId();
params+= "&filename="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'filename'))? params+= this.escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'filename').value) : params+=this.escape(this.getFilename());
params+= "&ext="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'ext'))? params+= this.escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'ext').value) : params+=this.escape(this.getExt());
req.open('GET', this.classUrl+'?ac=save'+params+'&noCache='+new Date().getTime()); //asynchroon
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-15');
req.send(null);
};
this.remove = function(func){
var t = this;
var req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
var xml = req.responseXML;
if (xml.documentElement) {
//t.loadXML(xml,0);
if (func) eval(func);
}
}
}
}
var params = "";
params+= "&project_id="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'project_id'))? params+= document.getElementById(this.inputName+'.'+this.inputId+'.'+'project_id').value : params+=this.getProjectId();
params+= "&filename="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'filename'))? params+= this.escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'filename').value) : params+=this.escape(this.getFilename());
params+= "&ext="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'ext'))? params+= this.escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'ext').value) : params+=this.escape(this.getExt());
req.open('GET', this.classUrl+'?ac=remove'+params+'&noCache='+new Date().getTime()); //asynchroon
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-15');
req.send(null);
};
this.getResult = function(func){
var t = this;
var req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
var xml = req.responseXML;
if (xml.documentElement) {
var root = xml.getElementsByTagName('uploadplans')[0];
var items = root.getElementsByTagName('uploadplan');
t.uploadplanResults = new Array();
for (var i = 0 ; i < items.length ; i++) {
var _uploadplan = new UploadPlan();
_uploadplan.loadXML(root,i);
t.uploadplanResults.push(_uploadplan);
}
if (func) eval(func);
}
}
}
}
var params = "";
if (this.project_ids.length != 0) params+= "&project_ids="+Object.toJSON(this.project_ids);
if (this.filename != "") params+= "&filename="+this.escape(this.filename);
if (this.ext != "") params+= "&ext="+this.escape(this.ext);
req.open('GET', this.classUrl+'?ac=getResult'+params+'&noCache='+new Date().getTime()); //asynchroon
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-15');
req.send(null);
};
this.renameForm = function(from, to){
if (document.getElementById(this.inputName+'.'+from+'.'+'project_id')) document.getElementById(this.inputName+'.'+from+'.'+'project_id').id=this.inputName+'.'+to+'.'+'project_id';
if (document.getElementById(this.inputName+'.'+from+'.'+'filename')) document.getElementById(this.inputName+'.'+from+'.'+'filename').id=this.inputName+'.'+to+'.'+'filename';
if (document.getElementById(this.inputName+'.'+from+'.'+'ext')) document.getElementById(this.inputName+'.'+from+'.'+'ext').id=this.inputName+'.'+to+'.'+'ext';
this.inputId = to;
};
this.escape = function(str){ return escape(str).replace(/\+/gi,'%2B');}
this.fillForm = function(){
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'project_id')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'project_id').value=this.project_id;
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'filename')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'filename').value=this.filename;
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'ext')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'ext').value=this.ext;
};
this.getNodeValue = function (el,name){
if (el.getElementsByTagName(name)[0].firstChild == null) return '';
else return el.getElementsByTagName(name)[0].firstChild.nodeValue;
};
}
