Files
dbois/public/js/lib/modules/beheer/authorisationModule.js
2018-07-29 10:11:02 +02:00

81 lines
2.4 KiB
JavaScript

/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 20/06/2018
* Time: 14:11
*/
dbo.authorisationInit = function () {
if ( dbo.authorisationModel !== undefined ) {
dbo.authorisationModel.refreshPageAuthorisations();
} else {
dbo.authorisationModel = {
roles : ko.observableArray([]) ,
init: function () {
var self = dbo.authorisationModel;
self.refreshPageAuthorisations();
},
refreshPageAuthorisations: function () {
var vm = dbo.authorisationModel;
vm.initPages = true;
vm.roles.removeAll();
dbo.authorisationDataService.getRoleAuthorisations( function ( data ) {
_.each( data, function ( p ) {
vm.roles.push( new vm.Role( p ) );
} )
} );
},
Role: function ( data ) {
var vm = dbo.authorisationModel;
var self = this;
self.roleID = data.id;
self.rolename = data.rolename;
self.pages = ko.observableArray( [] );
_.each( data.pagesAccess, function ( p ) {
self.pages.push( new vm.Page( p, self.pages() ) );
} );
vm.initPages = false;
},
Page: function ( data, pages ) {
var vm = dbo.authorisationModel;
var self = this;
if ( vm.initPages ) {
self.pageID = data.id;
self.pagename = data.pagename;
self.typePage = data.typepage;
self.pageAccess = ko.observableArray( [] );
self.pageAccess.push( {access: ko.observable( data.pageaccess == 'T' ? true : false )} );
}else{
_.each(pages, function(p){
console.log( pages );
console.log( data.id, '- -', p.pageID );
if( data.id == p.pageID) {
p.pageAccess.push( {access: ko.observable( data.pageaccess == 'T' ? true : false )} );
}
})
}
}
};
dbo.authorisationModel.init();
ko.applyBindings( dbo.authorisationModel, document.getElementById( 'AUTHORISATION' ) );
}
};