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) {
28
			var deviceNumberInput = $('.inputbox[name=number]')
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
			}
7068 anupam.sin 40
			var deviceNumberInput = $('.inputbox[name=number]')
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
							});
81
							console.log($('div.mk_discount_row').append('<div id="discountText" style="text-align: left;font-size: 15px;width: 340px;color: blue;" class="text"></div>'));
82
						} else {
83
							$('div.mk_amount_row .input-div').html('<input type="text" name="amount" class="inputbox rupee padding48">');
84
							$('#discountText').remove();
85
						}
86
					}
87
				});
88
			}
89
		}
90
	});
7073 anupam.sin 91
 
7125 amit.gupta 92
	$("#newConDis").live('change', function(){
93
		if(this.selectedIndex == 0){
94
			$('div.mk_discount_row :last').html('');
95
			$('#rechargeDetailsForm [name="amount"]').show().val('');	
96
		}else {
97
			var discount = $(this).find(":selected").attr("disc");
98
			$('#rechargeDetailsForm [name="amount"]').val($(this).val()).hide();	
7151 amit.gupta 99
			$('div.mk_discount_row :last').html('Discount more than rupees' + discount + 'is not allowed');
7125 amit.gupta 100
		}
101
	});
7151 amit.gupta 102
 
103
	$("#dateselector").change(function() {
104
		if($(this).val()=="3"){
105
			$("#daterange").show();
106
		}else {
107
			$("#daterange").hide();
108
		}
109
	});
110
 
7073 anupam.sin 111
	function getRechargeProvider(deviceNumber, deviceType){
112
		return $.ajax({
113
			type: "POST",
7096 anupam.sin 114
			url: "/rch/home!getServiceProvider?deviceNumber=" + deviceNumber + "&deviceType=" + deviceType,
7073 anupam.sin 115
			success:function(msg){
116
				if(msg != ""){
117
					var deviceNumberInfo = msg.split(":");
7125 amit.gupta 118
					if($.trim(deviceNumberInfo[0]) == -1) {
119
						alert ("Service not reachable or invalid number");
120
					}
121
					if($('input.rechargetype:checked').val() == "2"){
122
						if(storeCircleCode != $.trim(deviceNumberInfo[1])){
123
							$('input[name="number"]').val("");
124
							alert('This number does not belong to your circle');
125
							return false;
126
						}
127
					}
7073 anupam.sin 128
					$('#rechargeDetailsForm select[name="mobileOperator"]').val($.trim(deviceNumberInfo[0]));
7096 anupam.sin 129
					$('#circlecode').val($.trim(deviceNumberInfo[1]));
7073 anupam.sin 130
					$('#mobileSelector').trigger('change');
7125 amit.gupta 131
					oldValue = deviceNumber;
7073 anupam.sin 132
				}
7125 amit.gupta 133
			},
134
			complete : function(){
135
				$('#rechargeDetailsForm input[name="number"]').bind('keyup blur', function(){
136
					var numvalue = $(this).val().substring(0,4);
137
					var count = $(this).val().length;
138
					if(count==10 && oldValue != numvalue){
139
						getRechargeProvider(numvalue, 1);
140
					}
141
				});
142
			},
143
			beforeSend : function(){
144
				$('#rechargeDetailsForm input[name="number"]').unbind('keyup blur');
7073 anupam.sin 145
			}
146
		});
147
	}
7096 anupam.sin 148
});
149
 
150
function validateAllFields() {
151
	var rechargeType = $('input.rechargetype:checked').val();
152
	//1 is for Normal
153
	//2 for New Connection(FRC)
154
	var devicetype = $('input.devicetype:checked').val();
155
	//1 is for Mobile
156
	//2 for DTH
157
	if($('input[name=number]').val() === ""){
158
		alert('Please enter device number');
159
		return false;
160
	}
161
	if($('input[name=name]').val() === ""){
162
		alert('Please enter customer name');
163
		return false;
164
	}
7151 amit.gupta 165
	if($('input[name=number]').val() != $('input[name=repeat]').val()){
166
		alert('Please confirm the device number.');
167
		return false;
168
	}
7096 anupam.sin 169
	if($('input[name=amount]').val() === ""){
170
		alert('Please enter amount');
171
		return false;
172
	}
7073 anupam.sin 173
 
7096 anupam.sin 174
	if(deviceType == 1 && $('#mobileSelector').val() === 0) {
175
		alert('Please select operator');
176
		return false;
177
	}
178
 
179
	if(deviceType == 2 && $('#dthSelector').val() === 0) {
180
		alert('Please select operator');
181
		return false;
182
	}
183
 
184
	if(rechargeType == 2) {
185
		if($('input[name=sim]').val() === ""){
186
			alert('Please enter SIM number');
7073 anupam.sin 187
			return false;
188
		}
7096 anupam.sin 189
		if($('input[name=caf]').val() === ""){
190
			alert('Please enter CAF number');
7073 anupam.sin 191
			return false;
192
		}
7096 anupam.sin 193
		if($('input[name=alternate]').val() === ""){
194
			alert('Please enter alternate number');
7073 anupam.sin 195
			return false;
196
		}
197
	}
7096 anupam.sin 198
}