| 23783 |
ashik.ali |
1 |
$().ready(function() {
|
|
|
2 |
$("form#create-warehouse-form input").each(function(){
|
|
|
3 |
$(this).attr('autocomplete', 'off');
|
|
|
4 |
});
|
|
|
5 |
});
|
|
|
6 |
$().ready(function() {
|
|
|
7 |
// validate the comment form when it is submitted
|
|
|
8 |
$('#create-warehouse-form').validate({
|
|
|
9 |
rules:{
|
|
|
10 |
warehouseName:{
|
|
|
11 |
required:true
|
|
|
12 |
},
|
|
|
13 |
contactPersonName:{
|
|
|
14 |
required:true
|
|
|
15 |
},
|
|
|
16 |
gstNumber:{
|
|
|
17 |
required:true
|
|
|
18 |
},
|
|
|
19 |
pinCode:{
|
|
|
20 |
required:true
|
|
|
21 |
},
|
|
|
22 |
city:{
|
|
|
23 |
required:true
|
|
|
24 |
},
|
|
|
25 |
state:{
|
|
|
26 |
required:true
|
|
|
27 |
}
|
|
|
28 |
},
|
|
|
29 |
messages:{
|
|
|
30 |
warehouseName:{
|
|
|
31 |
required:"Please enter the name"
|
|
|
32 |
},
|
|
|
33 |
contactPersonName:{
|
|
|
34 |
required:"Please enter contact person name"
|
|
|
35 |
},
|
|
|
36 |
gstNumber:{
|
|
|
37 |
require: "Please enter gst number"
|
|
|
38 |
},
|
|
|
39 |
pinCode:{
|
|
|
40 |
require: "Please choose pin code"
|
|
|
41 |
},
|
|
|
42 |
city:{
|
|
|
43 |
required: "Please choose city"
|
|
|
44 |
},
|
|
|
45 |
state:{
|
|
|
46 |
required: "Please enter state"
|
|
|
47 |
}
|
|
|
48 |
},
|
|
|
49 |
submitHandler: function (form, event) {
|
|
|
50 |
event.preventDefault();
|
|
|
51 |
if(validateWarehouseDetails()){
|
|
|
52 |
alert("Please fix errors");
|
|
|
53 |
return false;
|
|
|
54 |
}
|
|
|
55 |
var json = warehouseDetailsJson();
|
|
|
56 |
console.log("warehouseJson = " + json);
|
|
|
57 |
if(confirm("Are you sure you want to create Warehouse!") == true){
|
|
|
58 |
doPostAjaxRequestWithJsonHandler(context+"/createWarehouse", json, function(response){
|
|
|
59 |
$('#main-content').html(response);
|
|
|
60 |
});
|
|
|
61 |
return false; // required to block normal submit since you used ajax
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
});
|
|
|
65 |
|
|
|
66 |
});
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
function validateWarehouseDetails(){
|
|
|
70 |
console.log("validating warehouse Details...");
|
|
|
71 |
var error = false;
|
|
|
72 |
var name = $("form#create-warehouse-form input[name=warehouseName]").val();
|
|
|
73 |
console.log("warehouseName = " + name);
|
|
|
74 |
$("#warehouseName").removeClass("border-highlight");
|
|
|
75 |
if(name == ""){
|
|
|
76 |
alert("Name is required");
|
|
|
77 |
$("#warehouseName").addClass("border-highlight");
|
|
|
78 |
error = true;
|
|
|
79 |
return error;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
var contactPersonName = $("form#create-warehouse-form input[name=contactPersonName]").val();
|
|
|
83 |
console.log("contactPersonName = " + contactPersonName);
|
|
|
84 |
$("#contactPersonName").removeClass("border-highlight");
|
|
|
85 |
if(contactPersonName == ""){
|
|
|
86 |
alert("Contact Person Name is required");
|
|
|
87 |
$("#contactPersonName").addClass("border-highlight");
|
|
|
88 |
error = true;
|
|
|
89 |
return error;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
var line1 = $("form#create-warehouse-form input[name=line1]").val();
|
|
|
93 |
console.log("line1 = " + line1);
|
|
|
94 |
$("#line1").removeClass("border-highlight");
|
|
|
95 |
if(line1 == ""){
|
|
|
96 |
alert("Line1 is required");
|
|
|
97 |
$("#line1").addClass("border-highlight");
|
|
|
98 |
error = true;
|
|
|
99 |
return error;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
var line2 = $("form#create-warehouse-form input[name=line2]").val();
|
|
|
103 |
console.log("line2 = " + line2);
|
|
|
104 |
$("#line2").removeClass("border-highlight");
|
|
|
105 |
if(line2 == ""){
|
|
|
106 |
alert("Line2 is required");
|
|
|
107 |
$("#line2").addClass("border-highlight");
|
|
|
108 |
error = true;
|
|
|
109 |
return error;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
var pinCode = $("form#create-warehouse-form input[name=pinCode]").val();
|
|
|
113 |
console.log("pinCode = " + pinCode);
|
|
|
114 |
$("#pinCode").removeClass("border-highlight");
|
|
|
115 |
if(pinCode == ""){
|
|
|
116 |
alert("Pin Code is required");
|
|
|
117 |
$("#pinCode").addClass("border-highlight");
|
|
|
118 |
error = true;
|
|
|
119 |
return error;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
var city = $("form#create-warehouse-form input[name=city]").val();
|
|
|
123 |
console.log("city = " + city);
|
|
|
124 |
$("#city").removeClass("border-highlight");
|
|
|
125 |
if(city == ""){
|
|
|
126 |
alert("City is required");
|
|
|
127 |
$("#city").addClass("border-highlight");
|
|
|
128 |
error = true;
|
|
|
129 |
return error;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
var state = $("#state option:selected").val();
|
|
|
133 |
console.log("state = " + state);
|
|
|
134 |
$("#state").removeClass("border-highlight");
|
|
|
135 |
if(state == ""){
|
|
|
136 |
alert("Please choose State");
|
|
|
137 |
$("#state").addClass("border-highlight");
|
|
|
138 |
error = true;
|
|
|
139 |
return error;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
console.log("validation warehouse error = " + error);
|
|
|
143 |
return error;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
function warehouseDetailsJson(){
|
|
|
147 |
console.log("warehouseDetailsJson");
|
|
|
148 |
var warehouseObject = {};
|
|
|
149 |
warehouseObject['name'] = $("form#create-warehouse-form input[name=warehouseName]").val();
|
|
|
150 |
warehouseObject['contactPersonName'] = $("form#create-warehouse-form input[name=contactPersonName]").val();
|
|
|
151 |
warehouseObject['gstNumber'] = $("form#create-warehouse-form input[name=gstNumber]").val();
|
|
|
152 |
var address = {};
|
|
|
153 |
address['name'] = $("form#create-warehouse-form input[name=warehouseName]").val();
|
|
|
154 |
address['line1'] = $("form#create-warehouse-form input[name=line1]").val();
|
|
|
155 |
address['line2'] = $("form#create-warehouse-form input[name=line2]").val();
|
|
|
156 |
address['landmark'] = $("form#create-warehouse-form input[name=landmark]").val();
|
|
|
157 |
address['city'] = $("form#create-warehouse-form input[name=city]").val();
|
|
|
158 |
address['pinCode'] = $("form#create-warehouse-form input[name=pinCode]").val();
|
|
|
159 |
address['state'] = $("#state option:selected").val();
|
|
|
160 |
address['country'] = "India";
|
|
|
161 |
address['phoneNumber'] = $("form#create-warehouse-form input[name=mobileNumber]").val();
|
|
|
162 |
warehouseObject['address'] = address;
|
|
|
163 |
return JSON.stringify(warehouseObject);
|
|
|
164 |
}
|