function Nota(project_id,pagina_id,value){
this.project_id = project_id;
this.project_ids = new Array();
this.pagina_id = pagina_id;
this.pagina_ids = new Array();
this.value = value;
//vaste elementen
this.inputName = 'nota';
this.inputId = this.id = project_id+"_"+pagina_id;
this.classUrl = '/scripts/classes/starters/startsimulator/Nota.jsp';
this.notaResults = 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.getPaginaId = function(){
return this.pagina_id;
}
this.setPaginaId = function(pagina_id){
this.pagina_id = pagina_id;
}
//searcher
this.setPaginaIds = function(pagina_id){
this.pagina_ids.push(pagina_id);
}
this.resetPaginaIds = function(){
this.pagina_ids = new Array();
}
this.getValue = function(){
return this.value;
}
this.setValue = function(value){
this.value = value;
}
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+'&pagina_id='+this.pagina_id+'&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('nota')[index];
this.setProjectId(this.getNodeValue(root,'project_id'));
this.setPaginaId(this.getNodeValue(root,'pagina_id'));
this.setValue(this.getNodeValue(root,'value'));
}
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 && t.getId()!=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+= escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'project_id').value) : params+=this.getProjectId();
params+= "&pagina_id="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'pagina_id'))? params+= escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'pagina_id').value) : params+=this.getPaginaId();
params+= "&value="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'value'))? params+= escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'value').value) : params+=this.getValue();
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.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('notas')[0];
var items = root.getElementsByTagName('nota');
t.notaResults = new Array();
for (var i = 0 ; i < items.length ; i++) {
var _nota = new Nota();
_nota.loadXML(root,i);
t.notaResults.push(_nota);
}
if (func) eval(func);
}
}
}
}
var params = "";
if (this.project_ids.length != 0) params+= "&project_ids="+Object.toJSON(this.project_ids);
if (this.pagina_ids.length != 0) params+= "&pagina_ids="+Object.toJSON(this.pagina_ids);
if (this.value != "") params+= "&value="+this.value;
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+'.'+'pagina_id')) document.getElementById(this.inputName+'.'+from+'.'+'pagina_id').id=this.inputName+'.'+to+'.'+'pagina_id';
if (document.getElementById(this.inputName+'.'+from+'.'+'value')) document.getElementById(this.inputName+'.'+from+'.'+'value').id=this.inputName+'.'+to+'.'+'value';
this.inputId = to;
}
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+'.'+'pagina_id')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'pagina_id').value=this.pagina_id;
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'value')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'value').value=this.value;
}
this.getNodeValue = function (el,name){
if (el.getElementsByTagName(name)[0].firstChild == null) return '';
else return el.getElementsByTagName(name)[0].firstChild.nodeValue;
}
}
