Subversion Repositories SmartDukaan

Rev

Rev 24087 | Rev 26218 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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