Files
dbois/public/js/lib/modules/modals/offerModal.js
T
2018-01-05 16:59:17 +01:00

111 lines
3.5 KiB
JavaScript

/**
* Created by Pensare Software.
* Offerte: Theo Weijmer
* Date: 25/12/2017
* Time: 17:32
*/
$( function () {
dbo.editOfferteModal = {
id : null,
offertes : ko.observableArray( [] ),
projects : ko.observableArray( [] ),
offerte_id : ko.observable(),
project_id : ko.observable(),
startdate : ko.observable(),
acceptance_chance: ko.observable(),
accepteddate : ko.observable(),
rejectdate : ko.observable(),
init: function () {
var vm = dbo.editOfferteModal;
dbo.customerDataService.getAllCustomers( 'F', function ( data ) {
vm.customers( data );
} );
},
newEditOfferte: function ( offerte, callback ) {
var vm = dbo.editOfferteModal;
vm.callback = typeof(callback) == 'function' ? callback : null;
vm.showOfferteModal();
vm.setOfferte( offerte );
},
saveOfferte: function () {
var vm = dbo.editOfferteModal;
if ( vm.formValid == false ) return;
var submitDATA = {
id : vm.id,
offertes : vm.offertes(),
projects : vm.projects(),
offerte_id : vm.offerte_id(),
project_id : vm.project_id(),
startdate : vm.startdate(),
acceptance_chance: vm.acceptance_chance(),
accepteddate : vm.accepteddate(),
rejectdate : vm.rejectdate()
}
dbo.offerteDataService.saveOfferte( submitDATA, function ( data ) {
if ( data.success ) {
tellMe( {
title : 'offerte aangemaakt',
message : 'de offerte is succesvol opgeslagen',
modalClass: 'modal-success'
}, function () {
vm.hideOfferteModal();
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 offerte',
message : errorMessage,
modalClass: 'modal-danger'
} );
} );
},
setOfferte: function ( offerte ) {
var vm = dbo.editOfferteModal;
vm.id = offerte.id;
vm.name( offerte.name || '' );
vm.address( offerte.address || '' );
vm.postcode( offerte.postcode || '' );
vm.place( offerte.place || '' );
vm.contactperson( offerte.contactperson || '' );
vm.email( offerte.email || '' );
vm.website( offerte.website || '' );
vm.remarks( offerte.remarks || '' );
},
showOfferteModal: function () {
$( "#offerte-modal" ).modal( 'show' );
},
hideOfferteModal: function () {
$( "#offerte-modal" ).modal( 'hide' );
}
};
dbo.editOfferteModal.init();
ko.applyBindings( dbo.editOfferteModal, document.getElementById( 'offer-modal' ) );
} );