138 lines
3.8 KiB
JavaScript
138 lines
3.8 KiB
JavaScript
$(function(){
|
|
|
|
ls.initLijstenModel = function(){
|
|
|
|
function fAddSWV(result, targetorgid){
|
|
var dit = this;
|
|
if (typeof result.naam != 'undefined'){
|
|
this.naam = result.naam;
|
|
}
|
|
this.geopend= ko.observable(true);
|
|
this.kamers = ko.observableArray();
|
|
if (result.kamers){
|
|
$.each(result.kamers, function(i,p){
|
|
dit.kamers.push(new fAddKamer(p,targetorgid));
|
|
}); //each
|
|
}; // if result
|
|
}
|
|
function fAddKamer(p,targetorgid){
|
|
var dit = this;
|
|
if (typeof p.naam != 'undefined'){
|
|
this.naam= p.naam
|
|
this.geopend = ko.observable(false);
|
|
if (targetorgid == p.id) this.geopend(true);
|
|
}
|
|
else this.geopend = ko.observable(true);
|
|
this.bgs = ko.observableArray();
|
|
if (p.bgs){
|
|
$.each(p.bgs, function(j,k){
|
|
dit.bgs.push(new fAddBG(k,targetorgid));
|
|
}); // each
|
|
}; // if bgs
|
|
};
|
|
function fAddBG(k, targetorgid){
|
|
var dit = this;
|
|
if (typeof k.naam != 'undefined'){
|
|
this.naam = k.naam;
|
|
this.geopend= ko.observable(false);
|
|
if (targetorgid == k.id) this.geopend(true);
|
|
} // if not undefined
|
|
else this.geopend = ko.observable(true);
|
|
this.scholen = ko.observableArray();
|
|
if (k.scholen){
|
|
$.each(k.scholen, function(i,p){
|
|
dit.scholen.push(new fAddSchool(p, targetorgid));
|
|
}); //each
|
|
}; // if scholen
|
|
};
|
|
|
|
function fAddSchool(p,targetorgid){
|
|
this.id = p.id;
|
|
this.naam = p.naam
|
|
this. selected =ko.observable(false);
|
|
if (this.id == targetorgid){
|
|
this.selected(true);
|
|
ls.LijstenModel.selectedSchool(this);
|
|
}
|
|
}
|
|
function fAddLijst(p){
|
|
this.fvid = p.fvid;
|
|
this.periode = p.periodenummer;
|
|
this.vorm = p.vorm;
|
|
this.vanaf = p.geldigvanaf
|
|
this.tm = p.geldigtm
|
|
this.naam = p. naam;
|
|
this.usernaam = p.usernaam;
|
|
}
|
|
if (ls.LijstenModel !== undefined){
|
|
ls.LijstenModel.initModel();
|
|
}
|
|
else {
|
|
ls.LijstenModel = {
|
|
|
|
selectedSchool : ko.observable(null),
|
|
swv : ko.observable(),
|
|
lijsten : ko.observableArray(),
|
|
|
|
initBindings :function(){
|
|
var self = ls.LijstenModel;
|
|
if (!ko.dataFor(document.getElementById('paglijsten')) ) {
|
|
ko.applyBindings(ls.LijstenModel, document.getElementById("paglijsten"));
|
|
}
|
|
self.initModel();
|
|
},
|
|
initModel: function(){
|
|
var self = ls.LijstenModel;
|
|
$.post("index.php/monpas/lijsten/getorganisaties", function(result){
|
|
self.swv(null);
|
|
if (result.swv){
|
|
self.swv(new fAddSWV(result.swv,result.targetorg.id));
|
|
if (self.selectedSchool()) self.fGetLijsten();
|
|
}; // if result
|
|
},'json');
|
|
},
|
|
fToggle: function(){
|
|
this.geopend(!this.geopend());
|
|
},
|
|
fSetSelected: function(){
|
|
var self = ls.LijstenModel;
|
|
if (this == self.selectedSchool){
|
|
return;
|
|
};
|
|
if (self.selectedSchool()) self.selectedSchool().selected(false);
|
|
self.selectedSchool(this);
|
|
self.selectedSchool().selected(true);
|
|
self.fGetLijsten();
|
|
},
|
|
fGetLijsten: function(){
|
|
var self = ls.LijstenModel;
|
|
if (!self.selectedSchool()) return;
|
|
$.post("index.php/monpas/lijsten/getlijsten/" + self.selectedSchool().id, function(result){
|
|
self.lijsten.removeAll();
|
|
if (result){
|
|
$.each(result, function(i,p){
|
|
self.lijsten.push(new fAddLijst(p));
|
|
}); // each
|
|
}
|
|
},'json');
|
|
},
|
|
fDeleteLijst: function(){
|
|
var self =ls.LijstenModel;
|
|
var dit = this;
|
|
var naam = "de school ";
|
|
if (dit.vorm ==2) naam= dit.usernaam
|
|
apprise("Weet u zeker dat u de lijst <i> " + dit.naam + "</i> ingevuld door " + naam + " wilt verwijderen? ",
|
|
{verify:true, textYes: 'ja' , textNo: 'nee'}, function(ans){
|
|
if (ans){
|
|
$.post("index.php/monpas/lijsten/deletelijst/" + dit.fvid, function(){
|
|
self.lijsten.remove(dit);
|
|
},'json');
|
|
}
|
|
}); // apprise
|
|
}
|
|
|
|
} ; // definition van model
|
|
ls.LijstenModel.initBindings();
|
|
}; // else
|
|
}// function initLijstenModel
|
|
}); |