var customer = function(data) { var self = this; self.id = ko.observable(); self.first_name = ko.observable(); self.middle_name = ko.observable(); self.last_name = ko.observable(); self.address = ko.observable(); self.contact = ko.observable(); self.nationality = ko.observable(); self.date_of_birth = ko.observable(); self.source_of_income = ko.observable(); self.birth_place = ko.observable(); self.occupation = ko.observable(); self.id_type = ko.observable(); self.id_number = ko.observable(); self.id_expiry = ko.observable(); self.id_place_of_issue = ko.observable(); self.address_region = ko.observable(); self.address_province = ko.observable(); self.address_city = ko.observable(); self.address_zipcode = ko.observable(); self.address_street = ko.observable(); self.address_ref_num = ko.observable(); self.address_nationality = ko.observable(); self.address_birth_place = ko.observable(); self.address_source_of_income = ko.observable(); self.address_occupation = ko.observable(); self.id_expiry_formated = ko.computed(function() { if (self.id_expiry() != undefined) { console.log("formating"); var dob = new Date(self.id_expiry()); dob = ((dob.getMonth() > 8) ? (dob.getMonth() + 1) : ('0' + (dob.getMonth() + 1))) + '/' + ((dob.getDate() > 9) ? dob.getDate() : ('0' + dob.getDate())) + '/' + dob.getFullYear(); return dob; } return ''; }, this); if (data) { self.update(data); } } customer.prototype.update = function(data) { this.id(data.id); this.first_name(data.first_name); this.middle_name(data.middle_name); this.last_name(data.last_name); this.address(data.address); this.contact(data.contact); this.nationality(data.nationality); this.date_of_birth(data.date_of_birth); this.source_of_income(data.source_of_income); this.birth_place(data.birth_place); this.occupation(data.occupation); this.id_type(data.id_type); this.id_number(data.id_number); this.id_expiry(data.id_expiry); this.id_place_of_issue(data.id_place_of_issue); this.address_region(data.id_place_of_issue); this.address_province(data.province); this.address_city(data.address_city); this.address_zipcode(data.address_zipcode); this.address_street(data.address_street); this.address_ref_num(data.address_ref_num); this.address_nationality(data.address_nationality); this.address_birth_place(data.address_birth_place); this.address_source_of_income(data.address_source_of_income); this.address_occupation(data.address_occupation); };