288 lines
10 KiB
JavaScript
288 lines
10 KiB
JavaScript
$( function () {
|
|
var timer;
|
|
var timeout = null;
|
|
|
|
function fAddBericht( b ) {
|
|
var dit = this;
|
|
this.berichtid = b.id;
|
|
this.kort = ko.observable( '' );
|
|
if ( b.samenvatting ) {
|
|
dit.kort( b.samenvatting );
|
|
}
|
|
this.lang = ko.observable( '' );
|
|
this.textarea = ko.observable();
|
|
if ( b.inhoud ) {
|
|
this.lang( b.inhoud );
|
|
}
|
|
this.startdatum = ko.observable( b.datum );
|
|
this.froalaDirty = ko.observable( false );
|
|
this.nogOverKort = ko.pureComputed( function ( i, k ) {
|
|
if ( dit.kort() ) {
|
|
return 140 - dit.kort().length;
|
|
}
|
|
else {
|
|
return 140;
|
|
}
|
|
} );
|
|
this.kleurKop = ko.pureComputed( function ( i, k ) {
|
|
if ( dit.nogOverKort() < 0 ) {
|
|
return 'red';
|
|
}
|
|
if ( dit.nogOverKort() > 136 ) {
|
|
return 'blue';
|
|
}
|
|
else {
|
|
return 'black';
|
|
}
|
|
} );
|
|
}
|
|
|
|
function fAddCluster( c ) {
|
|
var dit = this;
|
|
this.clusterid = c.clusterid;
|
|
this.cluster = c.naam;
|
|
this.aantalm = ko.observable( c.aantalm );
|
|
this.bezig = ko.observable( false );
|
|
this.modules = ko.observableArray( [] );
|
|
if ( c.modules ) {
|
|
dit.bezig( true );
|
|
$.each( c.modules, function ( i, m ) {
|
|
dit.modules.push( new fAddModule( m ) );
|
|
} )
|
|
dit.bezig( false );
|
|
}
|
|
if ( !dit.bezig() ) {
|
|
this.aangevinkt = ko.pureComputed( function ( i, b ) {
|
|
if ( dit.modules() ) {
|
|
var gevinkt = false;
|
|
var teller = 0;
|
|
$.each( dit.modules(), function ( i, v ) {
|
|
if ( v.vinkje() == true ) {
|
|
teller++;
|
|
}
|
|
} )
|
|
if ( teller == dit.modules().length ) {
|
|
gevinkt = true
|
|
}
|
|
return gevinkt;
|
|
}
|
|
} );
|
|
|
|
this.allesaanvinken = ko.observable( dit.aangevinkt() );
|
|
}
|
|
this.allesaanvinken = ko.observable( dit.aangevinkt() );
|
|
}
|
|
|
|
function fAddModule( m ) {
|
|
var teller = 0;
|
|
var gekoppeld = 0;
|
|
var dit = this;
|
|
this.moduleid = m.modulenr;
|
|
this.module = m.naam;
|
|
this.vinkje = ko.observable( false );
|
|
if ( m.vinkje == 'T' ) {
|
|
dit.vinkje( true );
|
|
}
|
|
|
|
this.cluster = 0;
|
|
if ( m.clusterid ) {
|
|
this.cluster = m.clusterid;
|
|
}
|
|
}
|
|
|
|
mh.initBerichtBeheerModel = function () {
|
|
if ( mh.BerichtBeheerModel !== undefined ) {
|
|
mh.BerichtBeheerModel.initModel();
|
|
}
|
|
else {
|
|
mh.BerichtBeheerModel = {
|
|
nieuwtjes : ko.observableArray( [] ),
|
|
clusters : ko.observableArray( [] ),
|
|
admin : ko.observable(true),
|
|
selectedBericht: ko.observable( '' ),
|
|
bezig : ko.observable(false),
|
|
|
|
froalaOptions : {
|
|
key : 'zc1QXIa2QZe1UOXATEX==',
|
|
toolbarButtons: ['bold', 'italic', 'underline', 'subscript', 'superscript', 'outdent', 'indent', 'formatOL', 'formatUL', 'html']
|
|
},
|
|
|
|
initBindings: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
|
|
|
|
if ( !ko.dataFor( document.getElementById( 'pagberichtbeheer' ) ) ) {
|
|
ko.applyBindings( mh.BerichtBeheerModel, document.getElementById( "pagberichtbeheer" ) );
|
|
}
|
|
self.initModel();
|
|
},
|
|
|
|
initModel: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
self.fCheckAdmin();
|
|
},
|
|
|
|
fCheckAdmin: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
$.post( "index.php/monpas/berichten/checkrechten/", function ( data ) {
|
|
if ( data ) {
|
|
self.admin( data);
|
|
}
|
|
}, 'json' ).always(function(){
|
|
self.fGetAdminBerichten()
|
|
});
|
|
},
|
|
|
|
fGetAdminBerichten: function(){
|
|
var self = mh.BerichtBeheerModel;
|
|
if ( !self.admin() ) {
|
|
return;
|
|
}
|
|
|
|
var timeout = null;
|
|
|
|
$.post( "index.php/monpas/berichten/getAdminBerichten/", function ( data ) {
|
|
self.nieuwtjes.removeAll();
|
|
if ( data ) {
|
|
$.each( data, function ( i, p ) {
|
|
initFroalaEditor( '.froala-editor' );
|
|
self.nieuwtjes.push( new fAddBericht( p ) );
|
|
} );// each
|
|
}
|
|
}, 'json' );
|
|
|
|
},
|
|
|
|
fMaakBericht: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
if ( ! self.admin() ) {
|
|
return;
|
|
}
|
|
$.get( 'index.php/monpas/berichten/create_empty_bericht', function () {
|
|
self.fGetAdminBerichten();
|
|
} );
|
|
},
|
|
|
|
fBewaarBericht: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
var dit = this;
|
|
if ( !self.admin() ) {
|
|
return;
|
|
}
|
|
dit.froalaDirty( true );
|
|
if ( timeout ) {
|
|
clearTimeout( timeout );
|
|
timeout = null;
|
|
}
|
|
timeout = setTimeout( function () {
|
|
if ( dit.kort().length < 4 || dit.kort().length > 137 ) return;
|
|
if ( dit.lang().length < 9 ) return;
|
|
|
|
var submitDATA = {
|
|
inhoud : dit.lang(),
|
|
samenvatting: dit.kort(),
|
|
datum : dit.startdatum()
|
|
};
|
|
$.post( 'index.php/monpas/berichten/saveBericht/' + dit.berichtid, submitDATA, function () {
|
|
dit.froalaDirty( false );
|
|
} );
|
|
}, 700 );
|
|
},
|
|
|
|
fOpenModuleKoppeling: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
self.selectedBericht( this );
|
|
if ( !self.admin() ) {
|
|
return;
|
|
}
|
|
$( '#popupBerichtModule' ).modal( 'show' );
|
|
$.post( "index.php/monpas/berichten/getmodules/" + this.berichtid, function ( data ) {
|
|
if ( data ) {
|
|
self.clusters.removeAll();
|
|
$.each( data, function ( i, b ) {
|
|
self.clusters.push( new fAddCluster( b ) );
|
|
} );// each
|
|
}; //if
|
|
}, 'json' );
|
|
},
|
|
|
|
fEditModuleKeuze: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
var dit = this;
|
|
if ( !self.admin() ) {
|
|
return;
|
|
}
|
|
var keuze = 'F';
|
|
if ( dit.vinkje() ) {
|
|
keuze = 'T';
|
|
}
|
|
|
|
$.each( self.clusters(), function ( i, c ) {
|
|
if ( c.clusterid == dit.cluster ) {
|
|
c.allesaanvinken( c.aangevinkt() );
|
|
}
|
|
});
|
|
|
|
var submitData = {
|
|
"modulevinkje": keuze,
|
|
"berichtid" : self.selectedBericht().berichtid,
|
|
"moduleid" : this.moduleid,
|
|
}
|
|
$.post( "index.php/monpas/berichten/koppelmodule", submitData, function ( data ) {
|
|
}, 'json' );
|
|
},
|
|
|
|
fEditClusterKeuze: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
var dit = this;
|
|
if ( !self.admin() ) {
|
|
return;
|
|
}
|
|
var keuze;
|
|
if ( dit.allesaanvinken() ) {
|
|
keuze = 'T';
|
|
$.each( dit.modules(), function ( i, b ) {
|
|
b.vinkje( true );
|
|
} );// each
|
|
}
|
|
else{
|
|
keuze = 'F';
|
|
$.each( dit.modules(), function ( i, b ) {
|
|
b.vinkje( false );
|
|
} );
|
|
}
|
|
|
|
var submitData = {
|
|
"clustervinkje": keuze,
|
|
"berichtid" : self.selectedBericht().berichtid,
|
|
"clusterid" : dit.clusterid,
|
|
}
|
|
$.post( "index.php/monpas/berichten/koppelcluster", submitData, function ( data ) {
|
|
}, 'json' );
|
|
},
|
|
|
|
fVerwijderBericht: function () {
|
|
var self = mh.BerichtBeheerModel;
|
|
var dit = this;
|
|
if ( !self.admin() ) {
|
|
return;
|
|
}
|
|
apprise("Weet je zeker dat je dit bericht wilt verwijderen? Deze wijziging kan niet ongedaangemaakt worden.",
|
|
{'verify':true, textYes: "ja", textNo: "nee"}, function(answer) {
|
|
if (answer) {
|
|
$.post("index.php/monpas/berichten/berichtomwegtegooien/" + dit.berichtid, function (data) {
|
|
if (data) {
|
|
self.fGetAdminBerichten()
|
|
}
|
|
}, 'json');
|
|
}
|
|
})
|
|
},
|
|
|
|
}; // definition van model
|
|
|
|
mh.BerichtBeheerModel.initBindings();
|
|
}
|
|
; // else
|
|
}// function initBerichtBeheerModel
|
|
} ); |