83 lines
3.1 KiB
JavaScript
83 lines
3.1 KiB
JavaScript
$(function(){
|
|
|
|
ls.initCommunicatie = function(){
|
|
|
|
Mail = function(data){
|
|
var self = this;
|
|
self.id = data.id;
|
|
self.naam = data.naam;
|
|
self.uitleg = data.uitleg;
|
|
self.adresses = ko.observableArray([]);
|
|
$.each(data.adresses, function(i,p){
|
|
self.adresses.push(new Adress(p, data.id));
|
|
});
|
|
};
|
|
|
|
Adress = function(data, mailID){
|
|
var self = this;
|
|
self.id = data.id;
|
|
self.mailID = mailID;
|
|
self.adress = ko.observable(data.adress);
|
|
self.validEmail = ko.computed(function(item){
|
|
return checkEmail(self.adress());
|
|
});
|
|
};
|
|
|
|
setMails = function(data){
|
|
var self = ls.communicatieModel;
|
|
|
|
self.mailNotifies.removeAll();
|
|
|
|
$.each(data, function(i,p){
|
|
self.mailNotifies.push(new Mail(p));
|
|
}); // each
|
|
};
|
|
|
|
if(ls.communicatieModel!==undefined){
|
|
ls.communicatieModel.communicatieInit();
|
|
}
|
|
else{
|
|
ls.communicatieModel = {
|
|
mailNotifies : ko.observableArray([]),
|
|
|
|
communicatieInit : function(){
|
|
var self = ls.communicatieModel;
|
|
$.getJSON('index.php/ijkpartituur/communicatie', function(data){
|
|
setMails(data.mails);
|
|
},'json');
|
|
} ,
|
|
|
|
saveAdress : function(data, e){
|
|
var self = ls.communicatieModel;
|
|
|
|
if(e.keyCode === 13 || e.keyCode === 9){
|
|
if(!checkEmail(this.adress())){
|
|
apprise('e-mail adres is niet correct en wordt niet opgeslagen', {animate:true});
|
|
}else{
|
|
var submitDATA= {adress:this.adress()};
|
|
var submitURL = 'index.php/ijkpartituur/communicatie/save_email/' + this.mailID + '/' + this.id;
|
|
$.post(submitURL, submitDATA, function(data){
|
|
setMails(data.mails);
|
|
}, 'json');
|
|
}
|
|
}
|
|
} ,
|
|
|
|
addAddress : function(){
|
|
this.adresses.push(new Adress({adress:'', id:0}, this.id));
|
|
} ,
|
|
|
|
deleteAdress : function(){
|
|
var self = ls.communicatieModel;
|
|
|
|
$.getJSON('index.php/ijkpartituur/communicatie/delete_adress/' + this.id, function(data){
|
|
setMails(data.mails);
|
|
});
|
|
}
|
|
} // modeldefinitie
|
|
}; //else
|
|
|
|
ls.communicatieModel.communicatieInit();
|
|
ko.applyBindings(ls.communicatieModel, document.getElementById("communicatie-page"));
|
|
}; // init
|
|
}); |