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