Subversion Repositories SmartDukaan

Rev

Rev 24087 | Rev 26218 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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