Files
dbois/public/js/lib/modules/beheer/vatModule.js
T
2018-05-06 20:39:59 +02:00

76 lines
1.9 KiB
JavaScript

/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 05/05/2018
* Time: 20:15
*/
dbo.vatInit = function () {
var timeout;
if ( dbo.vatModel !== undefined ) {
} else {
dbo.vatModel = {
vats: ko.observableArray( [] ),
init: function () {
var vm = dbo.vatModel;
vm.refreshVat();
},
addVat: function () {
var vm = dbo.vatModel;
dbo.vatDataService.addVat( function () {
vm.refreshVat();
} );
},
refreshVat: function () {
var vm = dbo.vatModel;
dbo.vatDataService.getVats( 'F', function ( data ) {
vm.vats.removeAll();
_.each( data, function ( p ) {
vm.vats.push( new vm.Vat( p ) );
} )
} );
},
toggleEdit: function () {
this.inEdit( !this.inEdit() );
},
validateNumber: function ( field ) {
var self = this;
self[field]( dbo.helpers.validateNumber( self[field](), true ) );
if ( timeout ) {
clearTimeout( timeout );
timeout = null;
}
timeout = setTimeout( function () {
dbo.vatDataService.saveVat( self.id, self.vatrate() );
}, 700 );
},
Vat: function ( data, inEdit = false ) {
this.id = data.id;
this.vatrate = ko.observable( data.vatrate || 0 );
this.inEdit = ko.observable( inEdit );
},
removeVat: function () {
}
}
dbo.vatModel.init();
ko.applyBindings( dbo.vatModel, document.getElementById( 'VAT' ) );
}
};