Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arrival date for change date to today and show error for duplicate rego #356

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions parkstay/frontend/parkstay/src/components/booking/addbooking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@
</div>
</div>
</div>
<div class="row" v-for="v in parkEntryVehicles">
<div class="row" v-for="(v, index) in parkEntryVehicles">
<div class="col-md-6">
<div class="form-group">
<label class="required">{{v.description}}</label>
<input type="text" class="form-control" name="vehicleRego" required="required" v-model="v.rego" @change="validateRego">
<input type="text" class="form-control" v-bind:name="'vehicleRego_'+index" required="required" v-model="v.rego" @change="validateRego">
</div>
</div>
<div class="col-md-6">
Expand Down Expand Up @@ -995,13 +995,12 @@ export default {
let vm =this;
return ($(vm.bookingForm).valid());
},
validateParkEntry:function () {
noDuplicateRego: function(source) {
let vm = this;
var validRegos = vm.parkEntryVehicles.reduce(function (acc, el) {
return acc + (el.rego ? 1 : 0);
}, 0);

return (validRegos == vm.parkEntryVehicles.length);
var listRego = vm.parkEntryVehicles.filter(function(el){
return el.rego == source.value;
});
return listRego.length <= 1;
},
overrideChargeReason:function () {
let vm = this;
Expand All @@ -1014,7 +1013,7 @@ export default {
},
addFormValidations: function() {
let vm=this;
$(vm.bookingForm).validate({
var options = {
rules: {
arrival: "required",
departure: "required",
Expand All @@ -1030,25 +1029,17 @@ export default {
postcode: "required",
country: "required",
price_level: "required",
open_reason: "required",
vehicleRego: {
required:{
depends: function(el){
return vm.validateParkEntry;
}
}
},
open_reason: "required",
overrideReason:{
required:{
depends: function(el){
return vm.overrideChargeReason;
return vm.overrideChargeReason(el);
}
}
}
},
messages: {
firstname: "Fill in all details",
vehicleRego: "Fill vehicle details",
},
showErrors: function(errorMap, errorList) {
$.each(this.validElements(), function(index, element) {
Expand All @@ -1068,7 +1059,23 @@ export default {
.parents('.form-group').addClass('has-error');
}
}
};
for (var i =0; i<vm.booking.parkEntry.vehicles; i++) {
options.rules['vehicleRego_'+i] = {
required: true,
noDuplicateRego: true
};
options.messages['vehicleRego_'+i] = {
required: 'Fill in vehicle details',
noDuplicateRego: 'Rego must be a unique set'
};
}
var form = $(vm.bookingForm);
form.data('validator', null);
$.validator.addMethod('noDuplicateRego', function (value, el){
return vm.noDuplicateRego(el);
});
form.validate(options);
},
addVehicleCount:function (park_entry) {
let vm = this;
Expand All @@ -1085,6 +1092,7 @@ export default {
vm.booking.price = vm.booking.price - vm.booking.entryFees.entry_fee;
vm.updateParkEntryPrices();
vm.booking.price = vm.booking.price + vm.booking.entryFees.entry_fee;
vm.addFormValidations();
},
removeVehicleCount:function (park_entry) {
let vm = this;
Expand All @@ -1109,15 +1117,16 @@ export default {
vm.booking.price = vm.booking.price - vm.booking.entryFees.entry_fee;
vm.updateParkEntryPrices();
vm.booking.price = vm.booking.price + vm.booking.entryFees.entry_fee;
vm.addFormValidations();
},
},
mounted:function () {
let vm = this;
vm.bookingForm = document.forms.bookingForm;
vm.fetchCampground();
vm.fetchCountries();
vm.addFormValidations();
vm.generateGuestCountText();
vm.addFormValidations();
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,8 @@ export default {
vm.arrivalPicker = $(vm.bookingForm.arrival).closest('.date');
vm.departurePicker = $(vm.bookingForm.departure).closest('.date');
vm.arrivalPicker.datetimepicker({
//defaultDate: Moment(vm.selected_arrival,"DD/MM/YYYY"),
format: 'DD/MM/YYYY',
minDate: new Date(),
//maxDate: Moment().add(parseInt(vm.campground.max_advance_booking), 'days')
minDate: Moment().startOf('day'),
});
vm.departurePicker.datetimepicker({
format: 'DD/MM/YYYY',
Expand Down Expand Up @@ -559,22 +557,6 @@ export default {
});
// Set the initial minimum departure date for the booking
vm.departurePicker.data("DateTimePicker").minDate(Moment(vm.selected_arrival,"DD/MM/YYYY").add(1,'days'));

// TODO implement price widget when the dates are changed
/*vm.$http.get(api_endpoints.campgroundCampsites(vm.campground.id)).then((response) => {
var campsites = response.body;
vm.$http.get(api_endpoints.campsite_current_price(campsites[0].id,Moment().format("YYYY-MM-DD"),Moment().add(1,'days').format("YYYY-MM-DD"))).then((response)=>{
vm.priceHistory = null;
vm.priceHistory = response.body;
vm.loading.splice('updating prices',1);
},(error)=>{
console.log(error);
vm.loading.splice('updating prices',1);
});
}, (error) => {
console.log(error);
});*/

},
addGuestCount: function(guest) {
let vm = this;
Expand Down
2 changes: 1 addition & 1 deletion parkstay/static/parkstay/js/parkstay.js

Large diffs are not rendered by default.