Subversion Repositories SmartDukaan

Rev

Rev 23434 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
23419 ashik.ali 1
$().ready(function() {
2
        // validate the comment form when it is submitted
3
        $('#create-prebooking-listing-form').validate({
4
		rules:{
5
			advanceAmount:{
6
				required:true
7
			},
8
			tentativeAmount:{
9
				required:true
10
			}
11
		},
12
		messages:{
13
			advanceAmount:{
14
				required: "Please enter advance amount"
15
			},
16
			tentativeAmount:{
17
				required: "Please enter the tentative amount"
18
			}
19
		},
20
		submitHandler: function (form, event) {
21
			event.preventDefault();
22
			if(validatePrebookingListingDetails()){
23
				alert("Please fix errors");
24
				return false;
25
			}
26
			var json = prebookingListingDetailsJson();
27
			console.log("prebookingListingJson = " + json);
28
			if(confirm("Are you sure you want to create Prebooking Listing!") == true){
29
				doAjaxRequestWithJsonHandler(context+"/createPrebookingListing", "POST", json, function(response){
30
					$('#main-content').html(response);
31
				});
32
	             return false; // required to block normal submit since you used ajax
33
			}
34
         }
35
	});
36
 
37
});
38
 
39
 
40
function validatePrebookingListingDetails(){
41
	console.log("validating prebooking listing Details...");
42
	var error = false;
43
 
44
	var advanceAmount = $("form#create-prebooking-listing-form input[name=advanceAmount]").val();
45
	console.log("advanceAmount = " + advanceAmount);
46
	$("#advanceAmount").removeClass("border-highlight");
47
	if(advanceAmount == ""){
48
		$("form#create-prebooking-listing-form input[name=advanceAmount]").val();
49
	}else if(advanceAmount <= 0){
50
		alert("Tentative Amount should be greater than 0");
51
		$("#advanceAmount").addClass("border-highlight");
52
		error = true;
53
		return error;
54
	}
55
 
56
	var tentativeAmount = $("form#create-prebooking-listing-form input[name=tentativeAmount]").val();
57
	console.log("tentativeAmount = " + tentativeAmount);
58
	$("#tentativeAmount").removeClass("border-highlight");
59
	if (tentativeAmount == ""){
60
		$("form#create-scheme-form input[name=tentativeAmount]").val(0);
61
	}else if(tentativeAmount <= 0){
62
		alert("Tentative Amount should be greater than 0");
63
		$("#tentativeAmount").addClass("border-highlight");
64
		error = true;
65
		return error;
66
	}
67
 
68
	//$('#brand-value').text($(this).text());
69
	$("#brand-value").removeClass("border-highlight");
70
	if($("#brand-value").text() == "Brands"){
71
		alert("Please choose Brand");
72
		$("#brand-value").addClass("border-highlight");
73
		error = true;
74
		return error;
75
	}
76
 
77
	$("#itemsDescription").removeClass("border-hightlight");
78
	var itemIdsString = $("#itemsDescription").val();
79
	if(itemIdsString == null){
80
		alert("Please choose items");
81
		$("#itemsDescription").addClass("border-highlight");
82
		error = true;
83
		return error;
84
	}
85
 
86
	console.log("validation prebooking listing error = " + error);
87
	return error;
88
}
89
 
90
function prebookingListingDetailsJson(){
91
	console.log("prebookingListingDetailsJson")
92
	var prebookingListingObject = {};
93
	prebookingListingObject['advanceAmount'] = $("#advanceAmount").val();
94
	prebookingListingObject['tentativeAmount'] = $('#tentativeAmount').val();
95
	prebookingListingObject['itemId'] = parseInt($("#itemsDescription").val());
96
	return JSON.stringify(prebookingListingObject);
97
}