340 lines
10 KiB
JavaScript
340 lines
10 KiB
JavaScript
$(function(){
|
|
|
|
ls.initVersiesModel = function(){
|
|
var timeout;
|
|
|
|
function fAddModule(p){
|
|
this.sysnr = p.sysnr;
|
|
this.naam = p.naam;
|
|
}
|
|
function fAddVersie(p){
|
|
this.id = p.id;
|
|
this.naam = ko.observable(p.naam);
|
|
this.ingang = ko.observable(p.ingangsdatum);
|
|
this.systemnorm = ko.observable(p.systemnorm);
|
|
this.deleteok = ko.observable(p.deleteok);
|
|
}
|
|
function fAddIJkpunt(p){
|
|
var dit = this;
|
|
this.id = p.id;
|
|
this.nummer = ko.observable(p.nummer);
|
|
this.omschrijving = ko.observable(p.omschrijving);
|
|
this.toelichting = ko.observable(p.toelichting);
|
|
this.indicatoren = ko.observableArray([]);
|
|
if (p.indicatoren){
|
|
$.each(p.indicatoren, function(j,k){
|
|
dit.indicatoren.push(new fAddIndicator(k));
|
|
});
|
|
}
|
|
this.toonindics = ko.observable(false);
|
|
this.disabled = ko.observable(false)
|
|
if(p.disabled == 'T') this.disabled(true);
|
|
}
|
|
function fAddIndicator(k){
|
|
this.id = k.id;
|
|
this.nummer = ko.observable(k.nummer);
|
|
this.gewicht = ko.observable(k.gewicht);
|
|
this.omschrijving1 = ko.observable(k.omschrijving1);
|
|
this.omschrijving2 = ko.observable(k.omschrijving2);
|
|
this.inspectie = ko.observable(k.inspectie);
|
|
this.deleteok = k.deleteok;
|
|
}
|
|
|
|
if (ls.VersiesModel !== undefined){
|
|
ls.VersiesModel.initModel();
|
|
}
|
|
else {
|
|
ls.VersiesModel = {
|
|
|
|
autonivo : ko.observable(0),
|
|
|
|
versies : ko.observableArray([]),
|
|
selectedVersie : ko.observable(''),
|
|
newVersieNaam : ko.observable(''),
|
|
ijkpunten : ko.observableArray([]),
|
|
newIJkpunt : ko.observable({nummer: ko.observable(0), naam:ko.observable(''), toelichting: ko.observable('')}),
|
|
selectedIJkpunt : ko.observable(''),
|
|
newIndicator : ko.observable({id : null,
|
|
ijkpunt_id : null,
|
|
nummer : ko.observable(0),
|
|
gewicht : ko.observable(1),
|
|
omschrijving1 : ko.observable(),
|
|
omschrijving2 : ko.observable(),
|
|
inspectie : ko.observable(),
|
|
deleteok : ko.observable(true) }),
|
|
modules : ko.observableArray([]),
|
|
selectedModule : ko.observable(''),
|
|
|
|
initBindings :function(){
|
|
var self = ls.VersiesModel;
|
|
|
|
if (!ko.dataFor(document.getElementById('pagVersies')) ) {
|
|
ko.applyBindings(ls.VersiesModel, document.getElementById("pagVersies"));
|
|
}
|
|
|
|
$.post("index.php/monpas/beheer/getmodules", function(result){
|
|
self.modules.removeAll();
|
|
|
|
if (result){
|
|
$.each(result, function(i,p){
|
|
self.modules.push(new fAddModule(p));
|
|
});
|
|
self.selectedModule(self.modules[0]);
|
|
}; // if rsult
|
|
self.initModel();
|
|
},'json');
|
|
},
|
|
initModel: function(){
|
|
var self = ls.VersiesModel;
|
|
$.post("index.php/shared/autorisatienivos/getautorisatie", function(result){
|
|
self.autonivo(result)
|
|
// self.fGetVersies();
|
|
},'json');
|
|
},
|
|
|
|
fGetVersies : function(){
|
|
var self =ls.VersiesModel;
|
|
$.post("index.php/monpas/beheer/getversies/" + self.selectedModule().sysnr, function(data){
|
|
self.versies.removeAll();
|
|
self.ijkpunten.removeAll();
|
|
if (data) {
|
|
$.each(data,function(i,p){
|
|
self.versies.push(new fAddVersie(p));
|
|
});
|
|
self.selectedVersie(self.versies()[0] );
|
|
}
|
|
},'json');
|
|
},
|
|
fChangeModule: function(){
|
|
var self =ls.VersiesModel;
|
|
self.fGetVersies();
|
|
},
|
|
fMaakNieuweVersie: function(){
|
|
var self = ls.VersiesModel;
|
|
self.newVersieNaam('');
|
|
$("#modNieuweVersie").modal('show');
|
|
},
|
|
fUpdateVersie: function(){
|
|
var self = ls.VersiesModel;
|
|
var dit = this;
|
|
if (timeout){
|
|
clearTimeout(timeout)
|
|
timeout ==null;
|
|
}
|
|
timeout=setTimeout(function(){
|
|
var submitData = { id : dit.id,
|
|
naam : dit.naam(),
|
|
ingangsdatum : dit.ingang(),
|
|
systemnorm : dit.systemnorm()}
|
|
$.post("index.php/monpas/beheer/updateversie",submitData, function(){})
|
|
},700);
|
|
|
|
},
|
|
fSaveVersie: function(){
|
|
var self = ls.VersiesModel;
|
|
if (!self.selectedModule()) {
|
|
apprise("Er is geen instrument geselecteerd. De lijst kan niet worden aangemaakt.");
|
|
return;
|
|
}
|
|
var submitData= {nieuwnaam : self.newVersieNaam(),
|
|
module : self.selectedModule().sysnr}
|
|
$.post("index.php/monpas/beheer/insertversie/" ,submitData, function(result){
|
|
if (result) {
|
|
self.versies.push(new fAddVersie(result));
|
|
$.each(self.versies(), function(i,p){
|
|
if (p.id == result.id){self.selectedVersie(p); return false;}
|
|
})
|
|
} ; // if result
|
|
self.ijkpunten.removeAll();
|
|
},'json');
|
|
},
|
|
fDeleteVersie: function(){
|
|
var self=ls.VersiesModel;
|
|
$.post("index.php/monpas/beheer/deleteversie/" + self.selectedVersie().id, function(result){
|
|
if (result.length > 0){
|
|
apprise(resulterrortekst);
|
|
}
|
|
else{
|
|
self.versies.remove(self.selectedVersie());
|
|
}
|
|
},'json')
|
|
},
|
|
fChangeVersie: function(){
|
|
var self=ls.VersiesModel;
|
|
self.ijkpunten.removeAll();
|
|
if (self.selectedVersie() == undefined) return;
|
|
$.post("index.php/monpas/beheer/getijkpunten/"+ self.selectedVersie().id, function(data){
|
|
self.ijkpunten.removeAll();
|
|
if (data){
|
|
$.each(data, function(i,p){
|
|
self.ijkpunten.push(new fAddIJkpunt(p));
|
|
});
|
|
}
|
|
},'json');
|
|
},
|
|
fNieuwIJkpunt: function(){
|
|
var self = ls.VersiesModel;
|
|
var num = 0;
|
|
var i=self.ijkpunten().length;
|
|
var i = parseInt(i) - 1;
|
|
if (i >= 0) {
|
|
num = self.ijkpunten()[i].nummer();
|
|
};
|
|
self.newIJkpunt().nummer(parseInt(num)+ 1);
|
|
self.newIJkpunt().naam('');
|
|
self.newIJkpunt().toelichting('');
|
|
$("#modNieuwIJkpunt").modal('show');
|
|
},
|
|
fSaveIJkpunt: function(){
|
|
var self=ls.VersiesModel;
|
|
|
|
var submitData={versie_id : self.selectedVersie().id,
|
|
nummer : self.newIJkpunt().nummer(),
|
|
omschrijving : self.newIJkpunt().naam(),
|
|
toelichting : self.newIJkpunt().toelichting()};
|
|
$.post("index.php/monpas/beheer/insertijkpunt", submitData, function(data){
|
|
if (data){
|
|
self.ijkpunten.push(new fAddIJkpunt(data));
|
|
$.each(self.ijkpunten(), function(i,p){
|
|
if (p.id == data.id){
|
|
self.selectedIJkpunt(p);
|
|
return false;
|
|
}
|
|
});
|
|
}
|
|
else { apprise("Er is een fout opgetreden bij opslaan."); };
|
|
},'json');
|
|
},
|
|
|
|
fToggleIndicatoren: function(){
|
|
var self= ls.VersiesModel;
|
|
self.selectedIJkpunt(null);
|
|
self.selectedIJkpunt(this);
|
|
this.toonindics(!this.toonindics());
|
|
},
|
|
fUpdateIJkpunt: function(){
|
|
var self= ls.VersiesModel;
|
|
var dit = this;
|
|
if(dit.disabled()) return;
|
|
if (timeout){
|
|
clearTimeout(timeout)
|
|
timeout ==null;
|
|
}
|
|
timeout=setTimeout(function(){
|
|
|
|
var submitData={id : dit.id,
|
|
nummer : dit.nummer(),
|
|
versie_id : self.selectedVersie().id,
|
|
omschrijving : dit.omschrijving(),
|
|
toelichting : dit.toelichting()}
|
|
|
|
$.post("index.php/monpas/beheer/updateijkpunt",submitData, function(){})
|
|
},800);
|
|
},
|
|
|
|
fDisableIJkpunt: function(){
|
|
var self = ls.VersiesModel;
|
|
var dit = this;
|
|
|
|
dit.disabled(! dit.disabled())
|
|
var disabled = 'F';
|
|
if(dit.disabled()) disabled = 'T';
|
|
var submitData = {
|
|
'id' : dit.id,
|
|
'disabled' : disabled
|
|
}
|
|
|
|
$.post("index.php/monpas/beheer/disableijkpunt", submitData, function(){
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fDeleteIJkpunt:function(){
|
|
var self =ls.VersiesModel;
|
|
var id = this.id;
|
|
var dit = this;
|
|
if ( self.ijkpunten().indicatoren !== undefined && self.ijkpunten().indicatoren().length > 0) {
|
|
apprise('Er zijn nog indicatoren. IJkpunt mag niet verwijderd worden');
|
|
return;
|
|
}
|
|
else{
|
|
apprise("Weet u zeker dat u " + this.omschrijving() + " wilt verwijderen? " ,
|
|
{verify: true, textYes: 'ja', textNo: 'nee'}, function(ans){
|
|
if (ans){
|
|
$.post("index.php/monpas/beheer/deleteijkpunt/" + id);
|
|
self.ijkpunten.remove(dit);
|
|
}
|
|
}); // apprise
|
|
}
|
|
},
|
|
fNieuweIndicator: function(){
|
|
var self = ls.VersiesModel;
|
|
var num =0
|
|
var dit = this;
|
|
if(dit.disabled()) return;
|
|
self.selectedIJkpunt(this);
|
|
$.each(self.selectedIJkpunt().indicatoren(), function(j,k){
|
|
num=k.nummer();
|
|
})
|
|
self.newIndicator().nummer(parseInt(num) + 1);
|
|
self.newIndicator().gewicht(1);
|
|
self.newIndicator().ijkpunt_id= self.selectedIJkpunt().id;
|
|
self.newIndicator().omschrijving1('');
|
|
self.newIndicator().omschrijving2('');
|
|
self.newIndicator().inspectie('');
|
|
self.newIndicator().deleteok(true);
|
|
$("#modNieuwIndicator").modal('show');
|
|
},
|
|
fSaveIndicator: function(){
|
|
var self=ls.VersiesModel;
|
|
|
|
var submitData={ ijkpunt_id : self.newIndicator().ijkpunt_id,
|
|
nummer : self.newIndicator().nummer(),
|
|
omschrijving1 : self.newIndicator().omschrijving1(),
|
|
omschrijving2 : self.newIndicator().omschrijving2(),
|
|
inspectie : self.newIndicator().inspectie(),
|
|
gewicht : self.newIndicator().gewicht};
|
|
$.post("index.php/monpas/beheer/insertindicator", submitData, function(data){
|
|
if (data){
|
|
self.selectedIJkpunt().indicatoren.push(new fAddIndicator(data));
|
|
}
|
|
else { apprise("Er is een fout opgetreden bij opslaan."); };
|
|
},'json');
|
|
},
|
|
fUpdateIndicator: function(){
|
|
var self = ls.VersiesModel;
|
|
var dit =this;
|
|
if (timeout){
|
|
clearTimeout(timeout);
|
|
timeout = null;
|
|
}
|
|
timeout = setTimeout(function(){
|
|
var submitData ={ id : dit.id,
|
|
nummer : dit.nummer(),
|
|
omschrijving1 : dit.omschrijving1(),
|
|
omschrijving2 : dit.omschrijving2(),
|
|
inspectie : dit.inspectie(),
|
|
gewicht : dit.gewicht()}
|
|
$.post("index.php/monpas/beheer/updateindicator", submitData);
|
|
},700);
|
|
},
|
|
fDeleteIndicator: function($parent, $data){
|
|
var self = ls.VersiesModel;
|
|
var dit = $data;
|
|
|
|
apprise ("Weet u zeker dat u <i>" + dit.omschrijving1() + "</i> wilt verwijderen?",
|
|
{verify:true, textYes:'ja',textNo:'nee'}, function(ans){
|
|
if (ans){
|
|
$.post('index.php/monpas/beheer/deleteindicator/' + dit.id,function(result){
|
|
$parent.indicatoren.remove(dit);
|
|
},'json');
|
|
}
|
|
}); // apprise
|
|
}
|
|
|
|
} ; // definition van model
|
|
ls.VersiesModel.initBindings();
|
|
}; // else
|
|
}// function initVersiesModel
|
|
}); |