/** * Created by Pensare Software. * User: Theo Weijmer * Date: 22/12/2017 * Time: 13:22 */ $( function () { dbo.menuModel = { pages : ko.observable(), initialized : ko.observable( false ), hidePasswordinput: ko.observable(true), newPassword : ko.observable(), validPassword : ko.observable(), init: function () { var vm = dbo.menuModel; dbo.pageDataservice.getAppPages( function ( data ) { vm.pages = data; //create for each page an observable $.each( data, function ( i, p ) { vm[p.pageurl] = ko.observable( false ); } ); // first page will be visible vm[data[0].pageurl]( true ); ko.applyBindings( dbo.menuModel, document.getElementById( "dbois-app" ) ); vm.initialized( true ); } ); }, checkPassword: function () { var vm = dbo.menuModel; if ( vm.newPassword().length >= 8 ) { vm.validPassword( true ); } else { vm.validPassword( false ); } }, logOut: function () { dbo.userDataService.logOut( function () { location.reload(); } ); }, togglePasswordinput: function () { if ( dbo.menuModel.hidePasswordinput() == true ) { var tellMeOptions = { title : 'Wijzig wachtwoord', message : 'Uw gewijzigde wachtwoord dient uit tenminste 8 tekens te bestaan', modalClass: 'modal-warning' } tellMe( tellMeOptions ) } dbo.menuModel.hidePasswordinput( !dbo.menuModel.hidePasswordinput() ); }, savePassword: function () { var vm = dbo.menuModel; dbo.userDataService.savePassword( vm.newPassword, function () { var tellMeOptions = { title : 'Uw wachtwoord is gewijzigd', message : 'U kunt nu met uw gewijzigde wachtwoord inloggen', modalClass: 'modal-warning' } tellMe( tellMeOptions ); dbo.menuModel.hidePasswordinput( !dbo.menuModel.hidePasswordinput() ); } ) }, setPage: function ( page ) { var vm = dbo.menuModel; $.each( vm.pages, function ( i, p ) { vm[p.pageurl]( false ); } ); vm[page]( true ); var func = page.toLowerCase() + 'Init'; window.dbo[func](); }, openSubmenu: function () { } } dbo.menuModel.init(); $( ".open-submenu" ).click( function () { $( "#sub-" + $( this ).attr( 'id' ) ).slideToggle( 'slow' ); } ); } );