Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7068 anupam.sin 1
$(function() {
7125 amit.gupta 2
	oldValue = "";
3
	$('.rechargetype').click(function (){
4
		$('div.mk_amount_row .input-div').html('<input type="text" name="amount" class="inputbox rupee padding48">');
5
		$('#discountText').remove();
7068 anupam.sin 6
		var rechargeType = $('input.rechargetype:checked').val();
7
		//1 is for Normal
8
		//2 for New Connection(FRC)
9
		if(rechargeType == 1) {
10
			$('#frc-div').slideUp(100);
11
		}
12
		if(rechargeType == 2) {
7096 anupam.sin 13
			if($('input.devicetype:checked').val() == 2) {
14
				$('input.rechargetype:unchecked').attr('checked', 'checked');
15
				alert('New DTH Connections are not supported');
16
				return false;
17
			} else {
18
				$('#frc-div').slideDown(100);
19
			}
7068 anupam.sin 20
		}
21
	});
22
 
23
	$('.devicetype').change(function (){
24
		var devicetype = $('input.devicetype:checked').val();
25
		//1 is for Mobile
26
		//2 for DTH
27
		if(devicetype == 1) {
7236 anupam.sin 28
			var deviceNumberInput = $('.inputbox[name=number], .inputbox[name=repeat]');
7068 anupam.sin 29
			deviceNumberInput.removeClass('padding15');
30
			deviceNumberInput.addClass('num-prefix padding48');
7289 anupam.sin 31
			deviceNumberInput.attr('maxlength', '10');
7073 anupam.sin 32
			$('#dthSelector').hide();
33
			$('#mobileSelector').show();
7068 anupam.sin 34
		}
35
		if(devicetype == 2) {
7096 anupam.sin 36
			if($('input.rechargetype:checked').val() == 2) {
37
				$('input.devicetype:unchecked').attr('checked', 'checked');
38
				alert('New DTH Connections are not supported');
39
				return false;
40
			}
7236 anupam.sin 41
			var deviceNumberInput = $('.inputbox[name=number], .inputbox[name=repeat]')
7068 anupam.sin 42
			deviceNumberInput.removeClass('num-prefix padding48');
43
			deviceNumberInput.addClass('padding15');
7289 anupam.sin 44
			deviceNumberInput.removeAttr('maxlength');
7073 anupam.sin 45
			$('#mobileSelector').hide();
46
			$('#dthSelector').show();
7068 anupam.sin 47
		}
48
	});
7073 anupam.sin 49
 
7080 anupam.sin 50
	$('#recharge-button').click(function() {
7096 anupam.sin 51
		$('#confirmForm').attr('action', '/rch/confirm!createRecharge');
7080 anupam.sin 52
		$('#confirmForm').submit();
53
	});
54
 
7151 amit.gupta 55
	/*$('#edit-button').click(function() {
7096 anupam.sin 56
		$('#confirmForm').attr('action', '/rch/home!editRecharge');
7080 anupam.sin 57
		$('#confirmForm').submit();
7151 amit.gupta 58
	});*/
7080 anupam.sin 59
 
7073 anupam.sin 60
	$('#rechargeDetailsForm input[name="number"]').unbind('keyup blur').bind('keyup blur', function(){
61
		var numvalue = $(this).val().substring(0,4);
62
		var count = $(this).val().length;
63
		if(count==10 && oldValue != numvalue){
64
			getRechargeProvider(numvalue, 1);
65
			//$(this).unbind('keyup');
66
		}
67
	});
7125 amit.gupta 68
	$('#mobileSelector').change(function(){
69
		var selectedOperator = $('#mobileSelector').val();
70
		if($('input.rechargetype:checked').val() == "2") {
71
			if(selectedOperator != 0) {
72
				return $.ajax({
73
					type: "POST",
74
					dataType:"json",
75
					url: "/rch/home!getFRC?operatorId=" + selectedOperator,
76
					success:function(msg) {
77
						if(msg.length != 0) {
7140 amit.gupta 78
							$('div.mk_amount_row .input-div').html('<select id="newConDis" style="height:30px;font-size:18px;"><option>Custom</option></select>' +
7125 amit.gupta 79
				    				'<input type="text" name="amount" class="inputbox rupee padding48" style="width:120px">');
80
							$.each(msg,function(index,obj){
81
								$("#newConDis").append('<option disc="' + obj.maxDiscount + '" >' + obj.denomination +'</option>');
82
							});
7176 anupam.sin 83
							$('div.mk_discount_row').append('<div id="discountText" style="text-align: left;font-size: 15px;width: 340px;color: blue;" class="text"></div>');
84
							$("#newConDis").change(function(){
85
								if(this.selectedIndex == 0){
86
									$('div.mk_discount_row :last').html('');
87
									$('#rechargeDetailsForm [name="amount"]').show().val('');	
88
								}else {
89
									var discount = $(this).find(":selected").attr("disc");
90
									$('#rechargeDetailsForm [name="amount"]').val($(this).val()).hide();	
91
									$('div.mk_discount_row :last').html('Discount more than rupees ' + discount + ' is not allowed');
92
								}
93
							});
7125 amit.gupta 94
						} else {
95
							$('div.mk_amount_row .input-div').html('<input type="text" name="amount" class="inputbox rupee padding48">');
96
							$('#discountText').remove();
97
						}
98
					}
99
				});
100
			}
101
		}
102
	});
7073 anupam.sin 103
 
7151 amit.gupta 104
 
7176 anupam.sin 105
 
7151 amit.gupta 106
	$("#dateselector").change(function() {
107
		if($(this).val()=="3"){
108
			$("#daterange").show();
109
		}else {
110
			$("#daterange").hide();
111
		}
112
	});
113
 
7073 anupam.sin 114
	function getRechargeProvider(deviceNumber, deviceType){
115
		return $.ajax({
116
			type: "POST",
7096 anupam.sin 117
			url: "/rch/home!getServiceProvider?deviceNumber=" + deviceNumber + "&deviceType=" + deviceType,
7073 anupam.sin 118
			success:function(msg){
119
				if(msg != ""){
120
					var deviceNumberInfo = msg.split(":");
7125 amit.gupta 121
					if($.trim(deviceNumberInfo[0]) == -1) {
122
						alert ("Service not reachable or invalid number");
123
					}
124
					if($('input.rechargetype:checked').val() == "2"){
125
						if(storeCircleCode != $.trim(deviceNumberInfo[1])){
126
							$('input[name="number"]').val("");
127
							alert('This number does not belong to your circle');
128
							return false;
129
						}
130
					}
7073 anupam.sin 131
					$('#rechargeDetailsForm select[name="mobileOperator"]').val($.trim(deviceNumberInfo[0]));
7096 anupam.sin 132
					$('#circlecode').val($.trim(deviceNumberInfo[1]));
7073 anupam.sin 133
					$('#mobileSelector').trigger('change');
7125 amit.gupta 134
					oldValue = deviceNumber;
7073 anupam.sin 135
				}
7125 amit.gupta 136
			},
137
			complete : function(){
138
				$('#rechargeDetailsForm input[name="number"]').bind('keyup blur', function(){
139
					var numvalue = $(this).val().substring(0,4);
140
					var count = $(this).val().length;
141
					if(count==10 && oldValue != numvalue){
142
						getRechargeProvider(numvalue, 1);
143
					}
144
				});
145
			},
146
			beforeSend : function(){
147
				$('#rechargeDetailsForm input[name="number"]').unbind('keyup blur');
7073 anupam.sin 148
			}
149
		});
150
	}
7176 anupam.sin 151
 
152
	$(document).ready(function(){
153
		var rechargeType = $('input.rechargetype:checked').val();
154
		if(rechargeType == 2) {
155
			$('#frc-div').show();
156
			$('#mobileSelector').trigger('change');
157
			//$('#rechargeDetailsForm input[name="number"]').keyup();
158
		}
7236 anupam.sin 159
 
160
		$('.devicetype').trigger('change');
7176 anupam.sin 161
	});
162
 
7096 anupam.sin 163
});
164
 
7189 anupam.sin 165
function isNumber(n) {
166
	/****
167
	 * http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/1830844#1830844
168
	 ****/
169
	var result = n.match(/^\d*$/);
170
	if(result == null || result.length == 0) {
171
		return false;
172
	}
173
	return true;
174
 
175
	//return !isNaN(parseFloat(n)) && isFinite(n);
176
}
177
 
178
//$('input[name=repeat]').bind('contextmenu', function(e){
179
//    e.preventDefault();
180
//    alert('Right click disabled');
181
//    return false;
182
//});
183
 
184
$(document).ready(function(){
185
    $('input[name=number]').bind("cut copy paste",function(e) {
186
        e.preventDefault();
187
    });
188
});
189
 
7096 anupam.sin 190
function validateAllFields() {
191
	var rechargeType = $('input.rechargetype:checked').val();
192
	//1 is for Normal
193
	//2 for New Connection(FRC)
194
	var devicetype = $('input.devicetype:checked').val();
195
	//1 is for Mobile
196
	//2 for DTH
7189 anupam.sin 197
 
7096 anupam.sin 198
	if($('input[name=number]').val() === ""){
199
		alert('Please enter device number');
200
		return false;
201
	}
7189 anupam.sin 202
 
203
	if(devicetype == 1) {
204
		if($('input[name=number]').val().length != 10) {
205
			alert('Please enter a 10 digit number');
206
			return false;
207
		}
208
 
209
		if(!isNumber($('input[name=number]').val())) {
210
			alert('Please enter a valid number');
211
			return false;
212
		}
213
	}
214
 
7096 anupam.sin 215
	if($('input[name=name]').val() === ""){
216
		alert('Please enter customer name');
217
		return false;
218
	}
7151 amit.gupta 219
	if($('input[name=number]').val() != $('input[name=repeat]').val()){
7189 anupam.sin 220
		alert('Device number and confirmation number do not match.');
7151 amit.gupta 221
		return false;
222
	}
7096 anupam.sin 223
	if($('input[name=amount]').val() === ""){
224
		alert('Please enter amount');
225
		return false;
226
	}
7073 anupam.sin 227
 
7189 anupam.sin 228
	if(devicetype == 1 && $('#mobileSelector').val() === 0) {
7096 anupam.sin 229
		alert('Please select operator');
230
		return false;
231
	}
232
 
7189 anupam.sin 233
	if(devicetype == 2 && $('#dthSelector').val() === 0) {
7096 anupam.sin 234
		alert('Please select operator');
235
		return false;
236
	}
237
 
238
	if(rechargeType == 2) {
7189 anupam.sin 239
		if($('input[name=simNum]').val() === ""){
7096 anupam.sin 240
			alert('Please enter SIM number');
7073 anupam.sin 241
			return false;
242
		}
7189 anupam.sin 243
 
244
		if($('input[name=simNum]').val().length != 5) {
245
			alert('Please enter the last 5 digits of SIM');
7073 anupam.sin 246
			return false;
247
		}
7189 anupam.sin 248
 
249
		if(!isNumber($('input[name=simNum]').val())) {
250
			alert('Please enter the last 5 digits of SIM');
7073 anupam.sin 251
			return false;
252
		}
7189 anupam.sin 253
 
254
		if($('input[name=cafNum]').val() === ""){
255
			alert('Please enter CAF number');
256
			return false;
257
		}
7073 anupam.sin 258
	}
7096 anupam.sin 259
}