Blame | Last modification | View Log | RSS feed
$(function(){jQuery.validator.addMethod("rechargeordernumber", function(value, element) {return this.optional(element) || /^([a-zA-Z]?)+[0-9]+$/.test(value);});var dropdownContent = {reasonToReturn: ['Wrong product delivered', 'Product received in damaged condition'],deliveryProblem:['Packet received in damaged condition','Seal tampered','Delivery not received','Delivery person asking for Extra shipping/Octroi Charges']};var utils = {lastQueryType: -1,removeSubjectInput: function() {$('#lblSubject').siblings('input, select').each(function(){$(this).remove();});},addSubjectDropdown: function(listOptions) {html = '<select name="subject">\n';for(index in listOptions) {html += '<option value="' + listOptions[index] + '">' + listOptions[index] + '</option>\n';}html += '</select>';$('#lblSubject').after(html);},addSubjectTextbox: function() {$('#lblSubject').after('<input type="text" name="subject" />');},addReasonSelector: function() {$('#lblSubject').after('<select name="subject">'+ '<option value="recharge-failed">Payment successful/Recharge failed</option>'+ '<option value="recharge-pending">Recharge successful but pending</option>'+ '<option value="recharge-wallet-realated">Recharge wallet related</option>'+ '<option value="recharge-other">Other recharge problem</option>'+ '</select>');},disableAllComponents: function(){$('div.contact-form-component').hide().find("input, select, textarea").attr("disable", "disable");},enableComponents: function(className){$('div.' + className).show().find("input, select, textarea").removeAttr('disable');},setLabelSubject:function(label) {$('#lblSubject').text(label);},resetProductSelector: function() {$('#product').html('<option value="-1">Select Product</option>').attr('disabled', 'true');},resetForm: function() {$('#communication_category').val("-1");this.resetProductSelector();this.disableAllComponents();$('label.error').remove();$('#submit, #resetFormButton').attr('disabled', 'disabled');},activateResetButton: function() {$('#resetFormButton').removeAttr('disabled');},addOrderIdSelector: function(selectorType, errMsg) {var methodToCall = 'all_orders';if (selectorType == 'returnable') {methodToCall = 'to_return';}else if (selectorType == 'cancellable') {methodToCall = 'to_cancel';}jQuery.ajax({type: "GET",url: "/contact-us/" + methodToCall,success: function(data) {if($.trim(data) == "<option value='-1'>No Orders Found</option>") {alert(errMsg);utils.resetForm();}else {html = '<select name="order_id" id="order_id">\n';html += data + '\n';html += '</select>';$("#orderComponent").append(html);}}});},addRechargeSelectors : function(){$('#deviceComponent').find('input').attr('name', 'deviceNumber');$('#rechargeOrderComponent').find('input').attr('name', 'rechargeOrderNumber');},removeOrderIdSelector: function() {$('#order_id').remove();},removeRechargeSelectors: function() {$('#deviceComponent').find('input').attr('name', 'adeviceNumber');$('#rechargeOrderComponent').find('input').attr('name', 'arechargeOrderNumber');}};$('#resetFormButton').click(function() {utils.resetForm();});$('#communication_category').change(function(){utils.disableAllComponents();$('label.error').remove();$('#frmContactUs input[name="submit"]').removeAttr('disabled');utils.resetProductSelector();utils.activateResetButton();utils.removeSubjectInput();utils.removeOrderIdSelector();utils.removeRechargeSelectors();switch(parseInt($(this).val())) {case 1:utils.enableComponents('return-product');utils.addOrderIdSelector('returnable', 'You do not have any completed orders to return');utils.addSubjectDropdown(dropdownContent.reasonToReturn);utils.setLabelSubject('Reason');utils.lastQueryType = 1;break;case 2:utils.enableComponents('cancel-order');utils.addOrderIdSelector('cancellable', 'You do not have any completed orders to cancel');utils.addSubjectTextbox();utils.setLabelSubject('Reason');utils.lastQueryType = 2;break;case 3:utils.enableComponents('delivery-problem');utils.addOrderIdSelector('all', 'You do not have any orders');utils.addSubjectDropdown(dropdownContent.deliveryProblem);utils.setLabelSubject('Problem Type');utils.lastQueryType = 3;break;case 4:utils.enableComponents('payment-status');utils.addOrderIdSelector('all', 'You do not have any orders');utils.lastQueryType = 4;break;case 5:utils.enableComponents('order-status');utils.addOrderIdSelector('all', 'You do not have any orders');utils.lastQueryType = 5;break;case 6:utils.enableComponents('product-request');utils.addSubjectTextbox();utils.setLabelSubject('Product Name');utils.lastQueryType = 6;break;case 7:utils.enableComponents('recharge-related');utils.addReasonSelector();utils.setLabelSubject('Reason');utils.addRechargeSelectors();utils.lastQueryType = 7;break;case 8:utils.enableComponents('other');utils.addSubjectTextbox();utils.setLabelSubject('Subject');utils.lastQueryType = 8;break;default:utils.resetForm();break;}});$('#order_id').live('change', function(){var orderId = parseInt($(this).val());if(isNaN(orderId)) {alert("Order Id must be an integer");} else {jQuery.ajax({type: "GET",url: "/contact-us/" + orderId + "",success: function(data) {if (! $('#productComponent').is(':hidden')) {$("#product").removeAttr('disabled').html(data);}}});}});$('form[name="frmContactUs"]').validate({rules: {email: {required: true,email: true},order_id: {required: true,digits: true},subject: {required: true},deviceNumber : {required: true},rechargeOrderNumber: {rechargeordernumber : true}},messages: {order_id: {digits: "Order ID must be a valid number"},rechargeOrderNumber : "Please enter valid order number",deviceNumber : "DHT/Mobile number is required"}});});