| 7272 |
amit.gupta |
1 |
$(function(){
|
|
|
2 |
jQuery.validator.addMethod("rechargeordernumber", function(value, element) {
|
|
|
3 |
|
|
|
4 |
return this.optional(element) || /^([a-zA-Z]?)+[0-9]+$/.test(value);
|
|
|
5 |
});
|
|
|
6 |
var dropdownContent = {
|
|
|
7 |
reasonToReturn: ['Wrong product delivered', 'Product received in damaged condition'],
|
|
|
8 |
|
|
|
9 |
deliveryProblem:[
|
|
|
10 |
'Packet received in damaged condition',
|
|
|
11 |
'Seal tampered',
|
|
|
12 |
'Delivery not received',
|
|
|
13 |
'Delivery person asking for Extra shipping/Octroi Charges'
|
|
|
14 |
]
|
|
|
15 |
};
|
|
|
16 |
|
|
|
17 |
var utils = {
|
|
|
18 |
lastQueryType: -1,
|
|
|
19 |
|
|
|
20 |
removeSubjectInput: function() {
|
|
|
21 |
$('#lblSubject').siblings('input, select').each(function(){
|
|
|
22 |
$(this).remove();
|
|
|
23 |
});
|
|
|
24 |
},
|
|
|
25 |
|
|
|
26 |
addSubjectDropdown: function(listOptions) {
|
|
|
27 |
html = '<select name="subject">\n';
|
|
|
28 |
|
|
|
29 |
for(index in listOptions) {
|
|
|
30 |
html += '<option value="' + listOptions[index] + '">' + listOptions[index] + '</option>\n';
|
|
|
31 |
}
|
|
|
32 |
html += '</select>';
|
|
|
33 |
$('#lblSubject').after(html);
|
|
|
34 |
},
|
|
|
35 |
|
|
|
36 |
addSubjectTextbox: function() {
|
|
|
37 |
$('#lblSubject').after('<input type="text" name="subject" />');
|
|
|
38 |
},
|
|
|
39 |
|
|
|
40 |
addReasonSelector: function() {
|
|
|
41 |
$('#lblSubject').after('<select name="subject">'
|
|
|
42 |
+ '<option value="recharge-failed">Payment successful/Recharge failed</option>'
|
|
|
43 |
+ '<option value="recharge-pending">Recharge successful but pending</option>'
|
|
|
44 |
+ '<option value="recharge-wallet-realated">Recharge wallet related</option>'
|
|
|
45 |
+ '<option value="recharge-other">Other recharge problem</option>'
|
|
|
46 |
+ '</select>');
|
|
|
47 |
},
|
|
|
48 |
|
|
|
49 |
disableAllComponents: function(){
|
|
|
50 |
$('div.contact-form-component').hide().find("input, select, textarea").attr("disable", "disable");
|
|
|
51 |
},
|
|
|
52 |
|
|
|
53 |
enableComponents: function(className){
|
|
|
54 |
$('div.' + className).show().find("input, select, textarea").removeAttr('disable');
|
|
|
55 |
},
|
|
|
56 |
|
|
|
57 |
setLabelSubject:function(label) {
|
|
|
58 |
$('#lblSubject').text(label);
|
|
|
59 |
},
|
|
|
60 |
|
|
|
61 |
resetProductSelector: function() {
|
|
|
62 |
$('#product').html('<option value="-1">Select Product</option>').attr('disabled', 'true');
|
|
|
63 |
},
|
|
|
64 |
resetForm: function() {
|
|
|
65 |
$('#communication_category').val("-1");
|
|
|
66 |
this.resetProductSelector();
|
|
|
67 |
this.disableAllComponents();
|
|
|
68 |
$('label.error').remove();
|
|
|
69 |
$('#submit, #resetFormButton').attr('disabled', 'disabled');
|
|
|
70 |
},
|
|
|
71 |
activateResetButton: function() {
|
|
|
72 |
$('#resetFormButton').removeAttr('disabled');
|
|
|
73 |
},
|
|
|
74 |
addOrderIdSelector: function(selectorType, errMsg) {
|
|
|
75 |
var methodToCall = 'all_orders';
|
|
|
76 |
|
|
|
77 |
if (selectorType == 'returnable') {
|
|
|
78 |
methodToCall = 'to_return';
|
|
|
79 |
}
|
|
|
80 |
else if (selectorType == 'cancellable') {
|
|
|
81 |
methodToCall = 'to_cancel';
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
jQuery.ajax({
|
|
|
85 |
type: "GET",
|
|
|
86 |
url: "/contact-us/" + methodToCall,
|
|
|
87 |
success: function(data) {
|
|
|
88 |
if($.trim(data) == "<option value='-1'>No Orders Found</option>") {
|
|
|
89 |
alert(errMsg);
|
|
|
90 |
utils.resetForm();
|
|
|
91 |
}
|
|
|
92 |
else {
|
|
|
93 |
html = '<select name="order_id" id="order_id">\n';
|
|
|
94 |
html += data + '\n';
|
|
|
95 |
html += '</select>';
|
|
|
96 |
$("#orderComponent").append(html);
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
});
|
|
|
100 |
},
|
|
|
101 |
addRechargeSelectors : function(){
|
|
|
102 |
$('#deviceComponent').find('input').attr('name', 'deviceNumber');
|
|
|
103 |
$('#rechargeOrderComponent').find('input').attr('name', 'rechargeOrderNumber');
|
|
|
104 |
},
|
|
|
105 |
removeOrderIdSelector: function() {
|
|
|
106 |
$('#order_id').remove();
|
|
|
107 |
},
|
|
|
108 |
removeRechargeSelectors: function() {
|
|
|
109 |
$('#deviceComponent').find('input').attr('name', 'adeviceNumber');
|
|
|
110 |
$('#rechargeOrderComponent').find('input').attr('name', 'arechargeOrderNumber');
|
|
|
111 |
}
|
|
|
112 |
};
|
|
|
113 |
|
|
|
114 |
$('#resetFormButton').click(function() {
|
|
|
115 |
utils.resetForm();
|
|
|
116 |
});
|
|
|
117 |
|
|
|
118 |
$('#communication_category').change(function(){
|
|
|
119 |
utils.disableAllComponents();
|
|
|
120 |
$('label.error').remove();
|
|
|
121 |
$('#frmContactUs input[name="submit"]').removeAttr('disabled');
|
|
|
122 |
utils.resetProductSelector();
|
|
|
123 |
utils.activateResetButton();
|
|
|
124 |
utils.removeSubjectInput();
|
|
|
125 |
utils.removeOrderIdSelector();
|
|
|
126 |
utils.removeRechargeSelectors();
|
|
|
127 |
|
|
|
128 |
switch(parseInt($(this).val())) {
|
|
|
129 |
|
|
|
130 |
case 1:
|
|
|
131 |
utils.enableComponents('return-product');
|
|
|
132 |
utils.addOrderIdSelector('returnable', 'You do not have any completed orders to return');
|
|
|
133 |
utils.addSubjectDropdown(dropdownContent.reasonToReturn);
|
|
|
134 |
utils.setLabelSubject('Reason');
|
|
|
135 |
|
|
|
136 |
utils.lastQueryType = 1;
|
|
|
137 |
break;
|
|
|
138 |
|
|
|
139 |
case 2:
|
|
|
140 |
utils.enableComponents('cancel-order');
|
|
|
141 |
utils.addOrderIdSelector('cancellable', 'You do not have any completed orders to cancel');
|
|
|
142 |
utils.addSubjectTextbox();
|
|
|
143 |
utils.setLabelSubject('Reason');
|
|
|
144 |
|
|
|
145 |
utils.lastQueryType = 2;
|
|
|
146 |
break;
|
|
|
147 |
|
|
|
148 |
case 3:
|
|
|
149 |
utils.enableComponents('delivery-problem');
|
|
|
150 |
utils.addOrderIdSelector('all', 'You do not have any orders');
|
|
|
151 |
utils.addSubjectDropdown(dropdownContent.deliveryProblem);
|
|
|
152 |
utils.setLabelSubject('Problem Type');
|
|
|
153 |
|
|
|
154 |
utils.lastQueryType = 3;
|
|
|
155 |
break;
|
|
|
156 |
|
|
|
157 |
case 4:
|
|
|
158 |
utils.enableComponents('payment-status');
|
|
|
159 |
utils.addOrderIdSelector('all', 'You do not have any orders');
|
|
|
160 |
|
|
|
161 |
utils.lastQueryType = 4;
|
|
|
162 |
break;
|
|
|
163 |
|
|
|
164 |
case 5:
|
|
|
165 |
utils.enableComponents('order-status');
|
|
|
166 |
utils.addOrderIdSelector('all', 'You do not have any orders');
|
|
|
167 |
|
|
|
168 |
utils.lastQueryType = 5;
|
|
|
169 |
break;
|
|
|
170 |
|
|
|
171 |
case 6:
|
|
|
172 |
utils.enableComponents('product-request');
|
|
|
173 |
utils.addSubjectTextbox();
|
|
|
174 |
utils.setLabelSubject('Product Name');
|
|
|
175 |
|
|
|
176 |
utils.lastQueryType = 6;
|
|
|
177 |
break;
|
|
|
178 |
|
|
|
179 |
case 7:
|
|
|
180 |
utils.enableComponents('recharge-related');
|
|
|
181 |
utils.addReasonSelector();
|
|
|
182 |
utils.setLabelSubject('Reason');
|
|
|
183 |
utils.addRechargeSelectors();
|
|
|
184 |
utils.lastQueryType = 7;
|
|
|
185 |
break;
|
|
|
186 |
|
|
|
187 |
case 8:
|
|
|
188 |
utils.enableComponents('other');
|
|
|
189 |
utils.addSubjectTextbox();
|
|
|
190 |
utils.setLabelSubject('Subject');
|
|
|
191 |
|
|
|
192 |
utils.lastQueryType = 8;
|
|
|
193 |
break;
|
|
|
194 |
|
|
|
195 |
default:
|
|
|
196 |
utils.resetForm();
|
|
|
197 |
break;
|
|
|
198 |
}
|
|
|
199 |
});
|
|
|
200 |
|
|
|
201 |
$('#order_id').live('change', function(){
|
|
|
202 |
var orderId = parseInt($(this).val());
|
|
|
203 |
|
|
|
204 |
if(isNaN(orderId)) {
|
|
|
205 |
alert("Order Id must be an integer");
|
|
|
206 |
} else {
|
|
|
207 |
jQuery.ajax({
|
|
|
208 |
type: "GET",
|
|
|
209 |
url: "/contact-us/" + orderId + "",
|
|
|
210 |
success: function(data) {
|
|
|
211 |
if (! $('#productComponent').is(':hidden')) {
|
|
|
212 |
$("#product").removeAttr('disabled').html(data);
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
});
|
|
|
216 |
}
|
|
|
217 |
});
|
|
|
218 |
|
|
|
219 |
$('form[name="frmContactUs"]').validate({
|
|
|
220 |
rules: {
|
|
|
221 |
email: {
|
|
|
222 |
required: true,
|
|
|
223 |
email: true
|
|
|
224 |
},
|
|
|
225 |
order_id: {
|
|
|
226 |
required: true,
|
|
|
227 |
digits: true
|
|
|
228 |
},
|
|
|
229 |
subject: {
|
|
|
230 |
required: true
|
|
|
231 |
},
|
|
|
232 |
deviceNumber : {
|
|
|
233 |
required: true
|
|
|
234 |
},
|
|
|
235 |
rechargeOrderNumber: {
|
|
|
236 |
rechargeordernumber : true
|
|
|
237 |
}
|
|
|
238 |
},
|
|
|
239 |
messages: {
|
|
|
240 |
order_id: {
|
|
|
241 |
digits: "Order ID must be a valid number"
|
|
|
242 |
},
|
|
|
243 |
rechargeOrderNumber : "Please enter valid order number",
|
|
|
244 |
deviceNumber : "DHT/Mobile number is required"
|
|
|
245 |
}
|
|
|
246 |
});
|
|
|
247 |
});
|