Users ready

This commit is contained in:
2017-12-29 14:44:18 +01:00
parent f73e20d0bc
commit cb0567d3f3
32 changed files with 1298 additions and 201 deletions
@@ -0,0 +1,55 @@
/**
* Created by Pensare Software.
* Customer: Theo Weijmer
* Date: 25/12/2017
* Time: 09:50
*/
dbo.customerDataService = {
getAllCustomers: function ( archive = 'F', callback ) {
$.getJSON( 'index.php/beheer/customersController/getAllCustomers/' + archive )
.done( function ( data ) {
callback( data );
} );
},
getCustomer: function ( userID, callback ) {
$.getJSON( 'index.php/beheer/customersController/getCustomer/' + userID )
.done( function ( data ) {
callback( data );
} );
},
checkCustomername: function ( username, callback ) {
$.post( 'index.php/beheer/userController/checkCustomername', 'json' )
.done( function ( data ) {
console.log( data );
callback( data );
} );
},
saveCustomer: function ( submitDATA, callback ) {
$.post( 'index.php/beheer/customersController/saveCustomer', submitDATA, function () {
}, 'json' )
.done( function ( data ) {
callback( data );
} );
},
archiveCustomer: function(userID, status, callback){
$.get('index.php/beheer/customersController/archiveCustomer/' + userID + '/' + status)
.done(function(){
callback();
});
},
removeCustomer: function ( userID, callback ) {
$.getJSON( 'index.php/beheer/customersController/removeCustomer/' + userID )
.done( function ( data ) {
callback( data );
} );
}
}
+18 -3
View File
@@ -26,14 +26,29 @@ dbo.userDataService = {
.done( function ( data ) {
console.log( data );
callback( data );
} )
} );
},
saveUser: function ( submitDATA, callback ) {
$.post( 'index.php/beheer/usersController/saveUser', submitDATA, 'json' )
$.post( 'index.php/beheer/usersController/saveUser', submitDATA, function () {
}, 'json' )
.done( function ( data ) {
callback( data );
} )
} );
},
archiveUser: function(userID, status, callback){
$.get('index.php/beheer/usersController/archiveUser/' + userID + '/' + status)
.done(function(){
callback();
});
},
removeUser: function ( userID, callback ) {
$.getJSON( 'index.php/beheer/usersController/removeUser/' + userID )
.done( function ( data ) {
callback( data );
} );
}
+6 -8
View File
@@ -7,7 +7,7 @@
var dbo = {};
$(function(){
$( function () {
ko.bindingHandlers.stopBinding = {
init: function () {
@@ -18,17 +18,15 @@ $(function(){
ko.virtualElements.allowedBindings.stopBinding = true;
ko.bindingHandlers.fadeVisible = {
init: function(element, valueAccessor) {
init : function ( element, valueAccessor ) {
var shouldDisplay = valueAccessor();
$(element).toggle(shouldDisplay);
$( element ).toggle( shouldDisplay );
},
update: function(element, valueAccessor) {
update: function ( element, valueAccessor ) {
// On update, fade in/out
var shouldDisplay = valueAccessor();
shouldDisplay ? $(element).fadeIn(750) : $(element).fadeOut(750);
shouldDisplay ? $( element ).fadeIn( 750 ) : $( element ).fadeOut( 750 );
}
};
});
} );
@@ -0,0 +1,113 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 29/12/2017
* Time: 14:19
*/
dbo.customersInit = function (){
if ( dbo.customersModel !== undefined ) {
} else {
dbo.customersModel = {
customers : ko.observableArray( [] ),
customer : ko.observable(),
archive: ko.observable( true ),
init: function () {
var vm = dbo.customersModel;
vm.refreshCustomers();
},
newCustomer: function () {
var vm = dbo.customersModel;
dbo.editCostomerModal.newEditCostumer( false, function () {
vm.refreshCostumers();
} );
},
toggleArchive: function () {
var vm = dbo.customersModel;
vm.archive( !vm.archive() );
vm.refreshCostumers();
},
editCostumer: function () {
var customer = this;
var vm = dbo.customersModel;
dbo.editCostumerModal.newEditCostumer( customer, function () {
vm.refreshCostumers();
} );
},
archiveCustomer: function () {
var vm = dbo.customersModel;
var self = this;
var status = self.archive == 'F' ? 'T' : 'F';
dbo.customerDataService.archiveCostumer( self.id, status, function () {
vm.refreshCostumers();
} );
},
removeCostumer: function () {
var vm = dbo.customersModel;
var self = this;
tellMe( {
title : 'verwijderen opdrachtgever',
message : 'weet u zeker dat u de opdrachtgever wilt verwijderen, dit kan niet ongedaan worden gemaakt',
notify : true,
noText : 'nee verwijder de opdrachtgever niet',
yesText : 'ja verwijder de opdrachtgever',
modalClass: 'modal-warning'
}, function ( response ) {
console.log( response );
if ( response ) {
dbo.customerDataService.removeUser( self.id, function ( data ) {
if ( data.result ) {
tellMe( {
title : 'opdrachtgever verwijderd',
message : 'de opdrachtgever is succesvol verwijderd',
modalClass: 'modal-success'
}, function () {
vm.refreshCostumers();
} );
} else {
tellMe( {
title : 'fout bij verwijderen opdrachtgever',
message : 'de opdrachtgever kan niet worden verwijderd',
modalClass: 'modal-danger'
} );
}
} );
}
} );
},
refreshCustomers: function () {
var vm = dbo.customersModel;
dbo.customerDataService.getAllCustomers( vm.archive() ? 'T' : 'F', function ( data ) {
vm.customers( data );
} );
}
};
dbo.customersModel.init();
ko.applyBindings( dbo.customersModel, document.getElementById( 'CUSTOMERS' ) );
}
}
+80 -8
View File
@@ -13,16 +13,15 @@ dbo.usersInit = function () {
} else {
dbo.usersModel = {
users: ko.observableArray( [] ),
user : ko.observable(),
roles: ko.observableArray( [] ),
users : ko.observableArray( [] ),
user : ko.observable(),
roles : ko.observableArray( [] ),
archive: ko.observable( true ),
init: function () {
var vm = dbo.usersModel;
dbo.userDataService.getAllUsers( 'F', function ( data ) {
vm.users( data );
} );
vm.refreshUsers();
dbo.rolesDataservice.getAllRoles( 'F', function ( data ) {
vm.roles( data );
@@ -30,9 +29,82 @@ dbo.usersInit = function () {
},
newUser: function () {
$( "#user-modal" ).modal( 'show' );
var vm = dbo.usersModel;
dbo.editUserModal.newUser();
dbo.editUserModal.newEditUser( false, function () {
vm.refreshUsers();
} );
},
toggleArchive: function () {
var vm = dbo.usersModel;
vm.archive( !vm.archive() );
vm.refreshUsers();
},
editUser: function () {
var user = this;
var vm = dbo.usersModel;
dbo.editUserModal.newEditUser( user, function () {
vm.refreshUsers();
} );
},
archiveUser: function () {
var vm = dbo.usersModel;
var self = this;
var status = self.archive == 'F' ? 'T' : 'F';
dbo.userDataService.archiveUser( self.id, status, function () {
vm.refreshUsers();
} );
},
removeUser: function () {
var vm = dbo.usersModel;
var self = this;
tellMe( {
title : 'verwijderen gebruiker',
message : 'weet u zeker dat u de gebruiker wilt verwijderen, dit kan niet ongedaan worden gemaakt',
notify : true,
noText : 'nee verwijder de gebruiker niet',
yesText : 'ja verwijder de gebruiker',
modalClass: 'modal-warning'
}, function ( response ) {
console.log( response );
if ( response ) {
dbo.userDataService.removeUser( self.id, function ( data ) {
if ( data.result ) {
tellMe( {
title : 'gebruiker verwijderd',
message : 'de gebruiker is succesvol verwijderd',
modalClass: 'modal-success'
}, function () {
vm.refreshUsers();
} );
} else {
tellMe( {
title : 'fout bij verwijderen gebruiker',
message : 'de gebruiker kan niet worden verwijderd',
modalClass: 'modal-danger'
} );
}
} );
}
} );
},
refreshUsers: function () {
var vm = dbo.usersModel;
dbo.userDataService.getAllUsers( vm.archive() ? 'T' : 'F', function ( data ) {
vm.users( data );
} );
}
+36 -16
View File
@@ -16,6 +16,7 @@ $( function () {
username : ko.observable(),
email : ko.observable(),
role : ko.observable(),
callback : null,
init: function () {
var vm = dbo.editUserModal;
@@ -25,10 +26,13 @@ $( function () {
} );
},
newUser: function () {
newEditUser: function ( user, callback ) {
var vm = dbo.editUserModal;
vm.callback = typeof(callback) == 'function' ? callback : null;
vm.setUser();
vm.showUserModal();
vm.setUser( user );
},
setRole: function () {
@@ -42,8 +46,6 @@ $( function () {
if ( vm.formValid == false ) return;
dbo.userDataService.checkUsername()
var submitDATA = {
id : vm.id,
firstname : vm.firstname(),
@@ -55,35 +57,54 @@ $( function () {
}
dbo.userDataService.saveUser( submitDATA, function ( data ) {
if ( data.succes ) {
if ( data.success ) {
tellMe( {
title : 'gebruiker aangemaakt',
message : 'gebuiker is succesvol aangemaakt',
message : 'gebuiker is succesvol opgeslagen',
modalClass: 'modal-success'
}, function(){
vm.hideUserModal();
if( typeof(vm.callback) == 'function') vm.callback();
} );
return;
}
tellMe({
var errorMessage = '<ul>';
$.each( data.messages, function ( i, p ) {
if ( p[0] ) {
errorMessage += '<li>' + i + ': ' + p[0] + '</li>';
}
} );
errorMessage += '</ul>';
tellMe( {
title : 'fout aanmaken gebruiker',
message : data.errorMessages,
message : errorMessage,
modalClass: 'modal-danger'
});
} )
} );
} );
},
setUser: function ( user = false ) {
setUser: function ( user ) {
var vm = dbo.editUserModal;
var role = isNaN( user.role ) ? null : user.role;
vm.id = user.id || 0;
vm.firstname( user.firstname || '' );
vm.lastname( user.firstname || '' );
vm.middlename( user.firstname || '' );
vm.lastname( user.lastname || '' );
vm.middlename( user.middlename || '' );
vm.username( user.username || '' );
vm.email( user.email || '' );
vm.role( user.role || null );
},
showUserModal: function () {
$( "#user-modal" ).modal( 'show' );
},
hideUserModal: function () {
$( "#user-modal" ).modal( 'hide' );
}
};
@@ -91,7 +112,6 @@ $( function () {
dbo.editUserModal.lastnameInvalid = ko.pureComputed( function () {
if ( !this.lastname() ) return true;
console.log( this.lastname() );
if ( this.lastname().length < 2 ) return true;
@@ -1,67 +0,0 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 13/12/2017
* Time: 17:08
*/
var tellMe = function ( options, callback ) {
dbo.notifyModel.init( options, callback );
}
dbo.notifyModel = {
title : ko.observable( null ),
message : ko.observable( null ),
notify : ko.observable( false ),
alert : ko.observable( false ),
noText : ko.observable( null ),
yesText : ko.observable( null ),
closeText : ko.observable( null ),
modalClass: ko.observable( null ),
callback : null,
init: function ( options, callback ) {
var vm = dbo.notifyModel;
vm.callback = callback;
vm.setOptions( options );
$( "#notify-me" ).modal( 'show' );
},
setOptions: function ( options ) {
var vm = dbo.notifyModel;
vm.title( options.title || '' );
vm.message( options.message || '' );
vm.notify( options.notify || false );
vm.noText( options.noText || 'Nee' );
vm.yesText( options.yesText || 'Ja' );
vm.closeText( options.closeText || 'ok' );
vm.modalClass( options.modalClass || 'modal-primary' )
},
closeNo: function () {
if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback( false );
},
closeYes: function () {
if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback( true );
},
closeOk: function () {
if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback();
},
close: function () {
if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback();
}
}
ko.applyBindings( dbo.notifyModel, document.getElementById( "notify-me" ) );
@@ -0,0 +1,88 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 13/12/2017
* Time: 17:08
*/
var tellMe = function ( options, callback ) {
dbo.tellmeModel.init( options, callback );
}
dbo.tellmeModel = {
title : ko.observable( null ),
message : ko.observable( null ),
notify : ko.observable( false ),
alert : ko.observable( false ),
noText : ko.observable( null ),
yesText : ko.observable( null ),
closeText : ko.observable( null ),
modalClass: ko.observable( null ),
callback : null,
init: function ( options, callback ) {
var vm = dbo.tellmeModel;
vm.callback = callback;
vm.setOptions( options );
$( "#tell-me" ).modal({
show:true
} );
},
setOptions: function ( options ) {
var vm = dbo.tellmeModel;
vm.title( options.title || '' );
vm.message( options.message || '' );
vm.notify( options.notify || false );
vm.noText( options.noText || 'Nee' );
vm.yesText( options.yesText || 'Ja' );
vm.closeText( options.closeText || 'ok' );
vm.modalClass( options.modalClass || 'modal-primary' )
},
closeNo: function () {
var vm = dbo.tellmeModel;
if ( typeof( vm.callback ) == 'function' ) vm.callback( false );
vm.closeTellme();
},
closeYes: function () {
var vm = dbo.tellmeModel;
if ( typeof( vm.callback ) == 'function' ) vm.callback( true );
vm.closeTellme();
},
closeOk: function () {
var vm = dbo.tellmeModel;
if ( typeof( vm.callback ) == 'function' ) vm.callback();
vm.closeTellme();
},
close: function () {
var vm = dbo.tellmeModel;
if ( typeof( vm.callback ) == 'function' ) vm.callback();
},
closeTellme: function(){
$( "#tell-me" ).modal( 'hide');
}
}
ko.applyBindings( dbo.tellmeModel, document.getElementById( "tell-me" ) );
$(document).on('show.bs.modal', '.modal', function (event) {
var zIndex = 1040 + (10 * $('.modal:visible').length);
$(this).css('z-index', zIndex);
setTimeout(function() {
$('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
}, 0);
});