projecten
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* Customer: Theo Weijmer
|
||||
* Date: 25/12/2017
|
||||
* Time: 17:32
|
||||
*/
|
||||
|
||||
$( function () {
|
||||
dbo.editCustomerModal = {
|
||||
|
||||
id : null,
|
||||
name : ko.observable(),
|
||||
address : ko.observable(),
|
||||
postcode : ko.observable(),
|
||||
place : ko.observable(),
|
||||
contactperson: ko.observable(),
|
||||
email : ko.observable(),
|
||||
website : ko.observable(),
|
||||
remarks : ko.observable(),
|
||||
callback : null,
|
||||
|
||||
init: function () {
|
||||
|
||||
},
|
||||
|
||||
newEditCustomer: function ( customer, callback ) {
|
||||
var vm = dbo.editCustomerModal;
|
||||
vm.callback = typeof(callback) == 'function' ? callback : null;
|
||||
|
||||
vm.showCustomerModal();
|
||||
|
||||
vm.setCustomer( customer );
|
||||
},
|
||||
|
||||
saveCustomer: function () {
|
||||
var vm = dbo.editCustomerModal;
|
||||
|
||||
if ( vm.formValid == false ) return;
|
||||
|
||||
var submitDATA = {
|
||||
id : vm.id,
|
||||
name : vm.name(),
|
||||
address : vm.address(),
|
||||
postcode : vm.postcode(),
|
||||
place : vm.place(),
|
||||
contactperson: vm.contactperson(),
|
||||
email : vm.email(),
|
||||
website : vm.website(),
|
||||
remarks : vm.remarks(),
|
||||
}
|
||||
|
||||
dbo.customerDataService.saveCustomer( submitDATA, function ( data ) {
|
||||
if ( data.success ) {
|
||||
tellMe( {
|
||||
title : 'opdrachtgever aangemaakt',
|
||||
message : 'opdrachtgever is succesvol opgeslagen',
|
||||
modalClass: 'modal-success'
|
||||
}, function () {
|
||||
vm.hideCustomerModal();
|
||||
|
||||
if ( typeof(vm.callback) == 'function' ) vm.callback();
|
||||
} );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var errorMessage = '<ul>';
|
||||
$.each( data.messages, function ( i, p ) {
|
||||
if ( p[0] ) {
|
||||
errorMessage += '<li>' + i + ': ' + p[0] + '</li>';
|
||||
}
|
||||
} );
|
||||
errorMessage += '</ul>';
|
||||
tellMe( {
|
||||
title : 'fout aanmaken opdrachtgever',
|
||||
message : errorMessage,
|
||||
modalClass: 'modal-danger'
|
||||
} );
|
||||
} );
|
||||
},
|
||||
|
||||
setCustomer: function ( customer ) {
|
||||
var vm = dbo.editCustomerModal;
|
||||
|
||||
vm.id = customer.id || 0;
|
||||
vm.name( customer.name || '' );
|
||||
vm.address( customer.address || '' );
|
||||
vm.postcode( customer.postcode || '' );
|
||||
vm.place( customer.place || '' );
|
||||
vm.contactperson( customer.contactperson || '' );
|
||||
vm.email( customer.email || '' );
|
||||
vm.website( customer.website || '' );
|
||||
vm.remarks( customer.remarks || '' );
|
||||
},
|
||||
|
||||
showCustomerModal: function () {
|
||||
$( "#customer-modal" ).modal( 'show' );
|
||||
},
|
||||
|
||||
hideCustomerModal: function () {
|
||||
$( "#customer-modal" ).modal( 'hide' );
|
||||
}
|
||||
};
|
||||
|
||||
dbo.editCustomerModal.init();
|
||||
|
||||
dbo.editCustomerModal.nameInvalid = ko.pureComputed( function () {
|
||||
if ( !this.name() ) return true;
|
||||
|
||||
if ( this.name().length < 2 ) return true;
|
||||
|
||||
return false;
|
||||
}, dbo.editCustomerModal );
|
||||
|
||||
dbo.editCustomerModal.emailInvalid = ko.pureComputed( function () {
|
||||
if ( !this.email() ) return false;
|
||||
|
||||
return !dbo.helpers.validateEmail( this.email() );
|
||||
}, dbo.editCustomerModal );
|
||||
|
||||
dbo.editCustomerModal.formValid = ko.pureComputed( function () {
|
||||
if ( this.nameInvalid() ) return false;
|
||||
if ( this.emailInvalid() ) return false;
|
||||
|
||||
return true;
|
||||
}, dbo.editCustomerModal )
|
||||
|
||||
ko.applyBindings( dbo.editCustomerModal, document.getElementById( 'customer-modal' ) );
|
||||
|
||||
} );
|
||||
Reference in New Issue
Block a user