Files
monpas/public/js/monpas/models/portalmodel.js
T

241 lines
9.2 KiB
JavaScript

$( function () {
ls.initPortalModel = function () {
var timeout;
function fAddBericht( b ) {
var dit = this;
this.berichtid = b.id;
this.kort = ko.observable( b.samenvatting );
this.lang = ko.observable( b.inhoud );
this.langPopUp = ko.observable(b.inhoud);
if(b.inhoud.length > 600){
dit.langPopUp(b.inhoud.slice(0,600)+"...");
}
this.startdatum = ko.observable( b.startdatum );
}
function shadeColor( color, percent ) {
var f = parseInt( color.slice( 1 ), 16 ), t = percent < 0 ? 0 : 255,
p = percent < 0 ? percent * -1 : percent, R = f >> 16, G = f >> 8 & 0x00FF, B = f & 0x0000FF;
return "#" + (0x1000000 + (Math.round( (t - R) * p ) + R) * 0x10000 + (Math.round( (t - G) * p ) + G) * 0x100 + (Math.round( (t - B) * p ) + B)).toString( 16 ).slice( 1 );
}
function fAddLicentie( p, id ) {
//clusters en ongeclusterde instrumenten
this.cluster_id = p.cluster_id; //id van cluster of clusterid waartoe instrument behoort
this.sysnr = p.sysnr;
this.naam = p.naam;
this.naamkort = p.naamkort;
//this.k1="radial-gradient('"+p.kleur1 + "' , '" + p.kleur2 + "'))";
this.k1 = "radial-gradient(#ffffff,#000000)"
this.k2 = "radial-gradient(#ffffff,#dddddd)"
kleur1 = '#ffffff';
kleur2 = '#000000'
if ( p.kleur1 ) kleur1 = p.kleur1
if ( p.kleur2 ) kleur2 = p.kleur2
this.k1 = 'radial-gradient(' + kleur1 + ',' + kleur2 + ')';
this.k2 = 'radial-gradient(' + shadeColor( kleur1, 0.2 ) + ',' + kleur2 + ' )';
var dit = this;
if ( p.wasNiveau2 == 'T' ) {
if ( p.cluster_id && p.cluster_id > 0 )
this.k2 = 'radial-gradient(' + kleur1 + ',' + shadeColor( kleur2, 0.5 ) + ')';
}
this.isCluster = ko.computed( function () {//cluster of instrument
var cluster = false;
if ( p.isCluster == 'T' ) {
cluster = true;
}
return cluster;
} )
this.selectie = ko.computed( function () {// geslecteerde instrumentn
var toon = false;
if ( id ) {
if ( id == dit.cluster_id ) {
toon = true;
}
return toon;
}
} )
this.geopend = ko.observable( false );
this.bolletjes = ko.observableArray();
if ( p.sub ) {
$.each( p.sub, function ( i, k ) {
dit.bolletjes.push( new fAddBolletje( i, k, id, kleur1, kleur2 ) )
} );
}
}
function fAddBolletje( i, b, id, kleur1, kleur2 ) {
this.bolletjeId = b.id;
this.sysnr = b.sysnr;
this.cluster_id = b.cluster_id;//instrumenten die onder cluster hangen
this.naam = b.naam;
this.naamkort = b.naamkort;
this.isCluster = ko.observable( false );
this.kleur = ko.observable( 'defaultBol' );
if ( b.cluster_id ) this.kleur = 'instrument' + b.cluster_id;
//this.k1="radial-gradient(#ffffff,#777777)"
//this.k2="radial-gradient(#ffffff,#dddddd)"
//if (kleur1 && kleur2) {
this.k1 = 'radial-gradient(' + shadeColor( kleur1, 0.5 ) + ',' + shadeColor( kleur2, 0.5 ) + ')';
this.k2 = this.k1;
// }
this.zindex = ko.computed( function () {// om bollen onder cluster te laren vallen
var teller = 19 - i;
return teller;
} )
this.naarBoven = ko.computed( function () {// om bollen onder cluster te schuiven
var schuif = -175 * (i + 1);
return schuif + 'px';
} )
var opGaand = this.naarBoven();
this.marge = ko.observable( opGaand );
}
if ( ls.PortalModel !== undefined ) {
ls.PortalModel.initModel();
}
else {
ls.PortalModel = {
licenties : ko.observableArray( [] ),
mededelingen : ko.observableArray( [] ),
gekozen : ko.observable( false ),
bezig : ko.observable( false ),
initBindings: function () {
var self = ls.PortalModel;
if ( !ko.dataFor( document.getElementById( 'pagportal' ) ) ) {
ko.applyBindings( ls.PortalModel, document.getElementById( "pagportal" ) );
}
self.bezig( true );
self.initModel();
},
initModel : function () {
var self = ls.PortalModel;
self.fToonPopup();
$.post( "index.php/shared/portal/getlicenties", function ( result ) {
self.licenties.removeAll();
if ( result ) {
$.each( result, function ( i, p ) {
var clusterid = '';
self.licenties.push( new fAddLicentie( p, clusterid ) );
} ); // each
}
; // if result
self.bezig( false );
}, 'json' );
},
fToonPopup: function () {
var self = ls.PortalModel;
$.post( "index.php/monpas/berichten/getberichtenVoorpagina/", function (data) {
self.mededelingen.removeAll();
if ( data ) {
$( '#popupBericht' ).modal( 'show' );
$.each( data, function ( i, b ) {
self.mededelingen.push( new fAddBericht( b ) );
} );// each
}
; //if
}, 'json' );
},
fOpenBericht: function () {
var self = ls.PortalModel;
var anker = this.berichtid;
// $.each( ls.MenuModel.menuitems(), function ( i, p ) {
// if ( p.naam == 'berichten' ) {
// p.gekozen( true );
//
// }
// else {
// p.gekozen( false )
// }
// } );
$( '#popupBericht' ).modal( 'hide' );
$( '#pagportal' ).fadeOut( function () {
$( '#pagberichten' ).fadeIn( 500 );
} );
mh.initBerichtenModel();
},
fMeerBerichten: function () {
var self = ls.PortalModel;
$.each( ls.MenuModel.menuitems(), function ( i, p ) {
if ( p.naam == 'berichten' ) {
p.gekozen( true );
}
else {
p.gekozen( false )
}
} ),
$( '#pagportal' ).fadeOut();
$( '#pagberichten' ).fadeIn( 500 );
mh.initBerichtenModel( 0 );
},
fNaarModule: function () {
var self = ls.PortalModel;
var dit = this;
if ( !this.isCluster() ) {// Verwijzen direct naar een instrument.
$.post( "index.php/shared/portal/naarmodule/" + this.sysnr, function () {
location.reload();
} );
}
else {
self.gekozen( true );
dit.geopend( !dit.geopend() );
var clusterid = dit.cluster_id;
$.post( "index.php/shared/portal/kiesCluster/" + clusterid, function ( result ) {//haalt alles opnieuw op.
// De instrumenten bij het gekozen array worden naast het cluster op rij getoond
self.licenties.removeAll();
if ( result ) {
$.each( result, function ( i, p ) {
self.licenties.push( new fAddLicentie( p, clusterid ) );
} );
}
}, 'json' );
}
},
fSluitCluster: function () {
var self = ls.PortalModel;
self.gekozen( false );
this.geopend( !this.geopend() )
self.initModel();
}
}; // definition van model
ls.PortalModel.initBindings();
}
; // else
}// function initPortalModel
} );