function Memo(inputId){
this.id = 0;
this.ids = new Array();
this.persoon_id = 0;
this.persoon_ids = new Array();
this.titel = "";
this.omschrijving = "";
//vaste elementen
this.inputName = 'memo';
this.inputId = this.id = inputId;
this.classUrl = '/scripts/classes/starters/startsimulator/Memo.jsp';
this.memoResults = new Array();
//getters and setters
this.getId = function(){
return this.id;
}
this.setId = function(id){
this.id = id;
}
//searcher
this.setIds = function(id){
this.ids.push(id);
}
this.resetIds = function(){
this.ids = new Array();
}
this.getPersoonId = function(){
return this.persoon_id;
}
this.setPersoonId = function(persoon_id){
this.persoon_id = persoon_id;
}
//searcher
this.setPersoonIds = function(persoon_id){
this.persoon_ids.push(persoon_id);
}
this.resetPersoonIds = function(){
this.persoon_ids = new Array();
}
this.getTitel = function(){
return this.titel;
}
this.setTitel = function(titel){
this.titel = titel;
}
this.getOmschrijving = function(){
return this.omschrijving;
}
this.setOmschrijving = function(omschrijving){
this.omschrijving = omschrijving;
}
this.getMemos = function(){
return this.memoResults;
}
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&id='+this.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('memo')[index];
this.setId(this.getNodeValue(root,'id'));
this.setPersoonId(this.getNodeValue(root,'persoon_id'));
this.setTitel(this.getNodeValue(root,'titel'));
this.setOmschrijving(this.getNodeValue(root,'omschrijving'));
}
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+= "&id="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'id'))? params+= escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'id').value) : params+=this.getId();
params+= "&persoon_id="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'persoon_id'))? params+= escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'persoon_id').value) : params+=this.getPersoonId();
params+= "&titel="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'titel'))? params+= escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'titel').value) : params+=this.getTitel();
params+= "&omschrijving="; (document.getElementById(this.inputName+'.'+this.inputId+'.'+'omschrijving'))? params+= escape(document.getElementById(this.inputName+'.'+this.inputId+'.'+'omschrijving').value) : params+=this.getOmschrijving();
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('memos')[0];
var items = root.getElementsByTagName('memo');
t.memoResults = new Array();
for (var i = 0 ; i < items.length ; i++) {
var _memo = new Memo();
_memo.loadXML(root,i);
t.memoResults.push(_memo);
}
if (func) eval(func);
}
}
}
}
var params = "";
if (this.ids.length != 0) params+= "&ids="+Object.toJSON(this.ids);
if (this.persoon_ids.length != 0) params+= "&persoon_ids="+Object.toJSON(this.persoon_ids);
if (this.titel != "") params+= "&titel="+this.titel;
if (this.omschrijving != "") params+= "&omschrijving="+this.omschrijving;
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+'.'+'id')) document.getElementById(this.inputName+'.'+from+'.'+'id').id=this.inputName+'.'+to+'.'+'id';
if (document.getElementById(this.inputName+'.'+from+'.'+'persoon_id')) document.getElementById(this.inputName+'.'+from+'.'+'persoon_id').id=this.inputName+'.'+to+'.'+'persoon_id';
if (document.getElementById(this.inputName+'.'+from+'.'+'titel')) document.getElementById(this.inputName+'.'+from+'.'+'titel').id=this.inputName+'.'+to+'.'+'titel';
if (document.getElementById(this.inputName+'.'+from+'.'+'omschrijving')) document.getElementById(this.inputName+'.'+from+'.'+'omschrijving').id=this.inputName+'.'+to+'.'+'omschrijving';
this.inputId = to;
}
this.fillForm = function(){
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'id')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'id').value=this.id;
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'persoon_id')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'persoon_id').value=this.persoon_id;
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'titel')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'titel').value=this.titel;
if (document.getElementById(this.inputName+'.'+this.inputId+'.'+'omschrijving')) document.getElementById(this.inputName+'.'+this.inputId+'.'+'omschrijving').value=this.omschrijving;
}
this.getNodeValue = function (el,name){
if (el.getElementsByTagName(name)[0].firstChild == null) return '';
else return el.getElementsByTagName(name)[0].firstChild.nodeValue;
}
}
