Subversion Repositories SmartDukaan

Rev

Rev 4148 | Rev 5572 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4148 Rev 5145
Line 119... Line 119...
119
 
119
 
120
/**
120
/**
121
	Invoked on "Make Primary Address" btn click
121
	Invoked on "Make Primary Address" btn click
122
*/
122
*/
123
function makePriAddress(sourceId){
123
function makePriAddress(sourceId){
124
	//alert("ajax to make primary "+ sourceId.substring(7,sourceId.length));
-
 
125
	ajaxMakePrimary(sourceId.substring(7,sourceId.length));
124
	ajaxMakePrimary(sourceId.substring(7,sourceId.length));
126
    var destId="";
125
    var destId="";
127
    var destAddress="";
126
    var destAddress="";
128
	// if primary address is present then take backup of primary id and address
127
	// if primary address is present then take backup of primary id and address
129
	if($(".noAddress1:visible").length != 1){
128
	if($(".noAddress1:visible").length != 1){
Line 134... Line 133...
134
	var sourceIdParentId 	= $("#" + sourceId).parent().attr("id");
133
	var sourceIdParentId 	= $("#" + sourceId).parent().attr("id");
135
	var sourceAddress 		= $("#" + sourceId + " .address").html();
134
	var sourceAddress 		= $("#" + sourceId + " .address").html();
136
	
135
	
137
	// if primary address is present then swap address
136
	// if primary address is present then swap address
138
	if($(".noAddress1:visible").length != 1){
137
	if($(".noAddress1:visible").length != 1){
139
	
-
 
140
		//alert("ids before swaping\n primary address id '" + destId + "' & \n other address id '" + sourceId + "'");
-
 
141
		
-
 
142
		// Replace destination Id and its content with source
138
		// Replace destination Id and its content with source
143
		$("#A1 #" + destId).attr("id", sourceId);
139
		$("#A1 #" + destId).attr("id", sourceId);
144
		$("#A1 #" + sourceId + " .address").html(sourceAddress);
140
		$("#A1 #" + sourceId + " .address").html(sourceAddress);
145
		
141
		
146
		// Replace primary address delete button parameter with source id
142
		// Replace primary address delete button parameter with source id
Line 160... Line 156...
160
		
156
		
161
		// Replace other address delete button parameter with destination id
157
		// Replace other address delete button parameter with destination id
162
		var delBtn = "<input type='button' class='button' value='Delete' onClick=delAddress('" + destId + "') />";
158
		var delBtn = "<input type='button' class='button' value='Delete' onClick=delAddress('" + destId + "') />";
163
		$("#" + sourceIdParentId + " #" + destId + " .addressButton .imgDeleteButton").html("");
159
		$("#" + sourceIdParentId + " #" + destId + " .addressButton .imgDeleteButton").html("");
164
		$("#" + sourceIdParentId + " #" + destId + " .addressButton .imgDeleteButton").html(delBtn);
160
		$("#" + sourceIdParentId + " #" + destId + " .addressButton .imgDeleteButton").html(delBtn);
165
		
-
 
166
		//alert("'" + sourceId + "' id is now primary & \n'" + destId + "' id become other address");
-
 
167
	}else{
161
	}else{
168
		// if no primary address is present then add new primary address
162
		// if no primary address is present then add new primary address
169
		addNewPriAddress(sourceId, sourceAddress);
163
		addNewPriAddress(sourceId, sourceAddress);
170
 
164
 
171
		// Delete clicked swapping other address
165
		// Delete clicked swapping other address
Line 175... Line 169...
175
 
169
 
176
/**
170
/**
177
	Invoked on "Delete" btn click of both primary and other address
171
	Invoked on "Delete" btn click of both primary and other address
178
*/
172
*/
179
function delAddress(sourceId){
173
function delAddress(sourceId){
180
	//alert("ajax to DELETE "+ sourceId.substring(7,sourceId.length));
-
 
181
	ajaxDeleteAddress(sourceId.substring(7,sourceId.length));
174
	ajaxDeleteAddress(sourceId.substring(7,sourceId.length));
182
 
175
 
183
	
176
	
184
	var sourceIdParentId = $("#" + sourceId).parent().attr("id");
177
	var sourceIdParentId = $("#" + sourceId).parent().attr("id");
185
	
178
	
Line 212... Line 205...
212
			// Replace primary address delete button parameter with source id
205
			// Replace primary address delete button parameter with source id
213
			var priDelBtn = "<input onclick=delAddress('" + sourceId + "') value='Delete' class='button' type='button' />";
206
			var priDelBtn = "<input onclick=delAddress('" + sourceId + "') value='Delete' class='button' type='button' />";
214
			$("#A1 #" + sourceId + " .addressButton .imgDeleteButton .left .right").html("");
207
			$("#A1 #" + sourceId + " .addressButton .imgDeleteButton .left .right").html("");
215
			$("#A1 #" + sourceId + " .addressButton .imgDeleteButton .left .right").html(priDelBtn);
208
			$("#A1 #" + sourceId + " .addressButton .imgDeleteButton .left .right").html(priDelBtn);
216
			
209
			
217
			
-
 
218
			//alert("Ajax call make primary" + sourceId.substring(7,sourceId.length));
-
 
219
			ajaxMakePrimary(sourceId.substring(7,sourceId.length));
210
			ajaxMakePrimary(sourceId.substring(7,sourceId.length));
220
			// Remove first other address
211
			// Remove first other address
221
			removeOtherAddress(sourceIdParentId);
212
			removeOtherAddress(sourceIdParentId);
222
		}
213
		}
223
	}else{
214
	}else{
224
		removeOtherAddress(sourceIdParentId);
215
		removeOtherAddress(sourceIdParentId);
225
		
-
 
226
		//alert("Ajax call to delete" + sourceId);
-
 
227
	}
216
	}
228
}
217
}
229
 
218
 
230
/**
219
/**
231
	Invoked from delAddress() function
220
	Invoked from delAddress() function
Line 331... Line 320...
331
		// Replace primary address delete button parameter with new primary id
320
		// Replace primary address delete button parameter with new primary id
332
		var priDelBtn = "<input onclick=delAddress('" + newPriAddressID + "') value='Delete' class='button' type='button' />";
321
		var priDelBtn = "<input onclick=delAddress('" + newPriAddressID + "') value='Delete' class='button' type='button' />";
333
		$("#A1 #" + newPriAddressID + " .addressButton .imgDeleteButton .left .right").html("");
322
		$("#A1 #" + newPriAddressID + " .addressButton .imgDeleteButton .left .right").html("");
334
		$("#A1 #" + newPriAddressID + " .addressButton .imgDeleteButton .left .right").html(priDelBtn);
323
		$("#A1 #" + newPriAddressID + " .addressButton .imgDeleteButton .left .right").html(priDelBtn);
335
		
324
		
336
		//alert("Ajax call to add new primary address" + newPriAddressID);
-
 
337
		
-
 
338
 
-
 
339
		ajaxAddAddress("true", priName, priAdd1, priAdd2, priCity, priState, priPinCode, priPhone, priEmail);
325
		ajaxAddAddress("true", priName, priAdd1, priAdd2, priCity, priState, priPinCode, priPhone, priEmail);
340
		
326
		
341
		// shift old primary address to make first other address
327
		// shift old primary address to make first other address
342
		addOtherAddress("", priAddressID, priAddress);
328
		addOtherAddress("", priAddressID, priAddress);
343
	}else{
329
	}else{
Line 354... Line 340...
354
		> condition = save	// for saving other address only
340
		> condition = save	// for saving other address only
355
		> id 				// for old primary id
341
		> id 				// for old primary id
356
		> address 			// for old primary address
342
		> address 			// for old primary address
357
*/
343
*/
358
function addOtherAddress(condition, id, address){
344
function addOtherAddress(condition, id, address){
359
	//alert(condition +"id"+ id +  "add"+address);
-
 
360
	var newContainerID 	= "A" + (++lastContainerID);
345
	var newContainerID 	= "A" + (++lastContainerID);
361
	var newAddressID	= (condition == "save") ? "address" + (++lastAddressID) : id;
346
	var newAddressID	= (condition == "save") ? "address" + (++lastAddressID) : id;
362
	var container 		= "";
347
	var container 		= "";
363
	
348
	
364
	if(condition == "save"){
349
	if(condition == "save"){
Line 370... Line 355...
370
		var otherState 		= $("#shippingAddress #state option:selected").val();
355
		var otherState 		= $("#shippingAddress #state option:selected").val();
371
		var otherPhone 	= $("#shippingAddress #txtPhone").val();
356
		var otherPhone 	= $("#shippingAddress #txtPhone").val();
372
		var otherEmail = "";
357
		var otherEmail = "";
373
		var otherAddress = otherName + "<br />" + otherAdd1 + "<br />" + otherAdd2 + "<br />" + otherCity + "<br />" + otherPinCode + "<br />" + otherState + "<br /> Phone: " + otherPhone;
358
		var otherAddress = otherName + "<br />" + otherAdd1 + "<br />" + otherAdd2 + "<br />" + otherCity + "<br />" + otherPinCode + "<br />" + otherState + "<br /> Phone: " + otherPhone;
374
	
359
	
375
		//alert("before ajax");
-
 
376
		ajaxAddAddress("false", otherName, otherAdd1, otherAdd2, otherCity, otherState, otherPinCode, otherPhone, otherEmail);
360
		ajaxAddAddress("false", otherName, otherAdd1, otherAdd2, otherCity, otherState, otherPinCode, otherPhone, otherEmail);
377
		
361
		
378
	}else{
362
	}else{
379
		otherAddress = address;
363
		otherAddress = address;
380
	}
364
	}
Line 431... Line 415...
431
		$(".noAddress2").hide();
415
		$(".noAddress2").hide();
432
	}
416
	}
433
	
417
	
434
	otherAddressCount++;
418
	otherAddressCount++;
435
	
419
	
436
	//alert("ajax to add in other address"+ newAddressID);
-
 
437
	
-
 
438
	
420
	
439
}
421
}
440
 
422
 
441
 
423
 
442
/**
424
/**
Line 467... Line 449...
467
		
449
		
468
	container += '</div>';
450
	container += '</div>';
469
	
451
	
470
	$("#A1").append(container);
452
	$("#A1").append(container);
471
	
453
	
472
	//alert("AJAX to  id is now primary" + id);
-
 
473
	
-
 
474
}
454
}
475
 
455
 
476
/**
456
/**
477
	Add address for Shipping Address page
457
	Add address for Shipping Address page
478
*/
458
*/
Line 484... Line 464...
484
	// Hide second addAddress button
464
	// Hide second addAddress button
485
	$("#addAddress2").hide();
465
	$("#addAddress2").hide();
486
	
466
	
487
	// Show new address form
467
	// Show new address form
488
	$("#addNewAddress").show();
468
	$("#addNewAddress").show();
489
	//scrollWindow("addNewAddress", 2000);
-
 
490
	
469
	
491
	$("#addNewAddress #txtName").focus();
470
	$("#addNewAddress #txtName").focus();
492
}
471
}
493
 
472
 
494
/**
473
/**
Line 503... Line 482...
503
	// Show second addAddress button
482
	// Show second addAddress button
504
	$("#addAddress2").show();
483
	$("#addAddress2").show();
505
	
484
	
506
	// Hide add new address form
485
	// Hide add new address form
507
	$("#addNewAddress").hide();
486
	$("#addNewAddress").hide();
508
	//scrollWindow("shippingAddress", 1000);
-
 
509
	
487
	
510
	$("#shippingAddress #txtName").val("");
488
	$("#shippingAddress #txtName").val("");
511
	$("#shippingAddress #txtAddress").val("");
489
	$("#shippingAddress #txtAddress").val("");
512
	$("#shippingAddress #txtAddress2").val("");
490
	$("#shippingAddress #txtAddress2").val("");
513
	$("#shippingAddress #txtCity").val("");
491
	$("#shippingAddress #txtCity").val("");
Line 516... Line 494...
516
	$("#shippingAddress #txtPhone").val("");
494
	$("#shippingAddress #txtPhone").val("");
517
}
495
}
518
 
496
 
519
 
497
 
520
function ajaxAddAddress(isprimary, name, add1, add2, city, state, pin, phone, email){
498
function ajaxAddAddress(isprimary, name, add1, add2, city, state, pin, phone, email){
521
	//alert("in ajax" +isprimary + name + add1 + add2 + city + state + pin + phone + email);
-
 
522
	jQuery.ajax({
499
	jQuery.ajax({
523
		  type: "POST",
500
		  type: "POST",
524
		  url: "/address",
501
		  url: "/address",
525
		  data: "action=add&default="+isprimary+"&name="+name+"&line1="+add1+"&line2="+add2+"&city="+city
502
		  data: "action=add&default="+isprimary+"&name="+name+"&line1="+add1+"&line2="+add2+"&city="+city
526
		  +"&state="+state+"&pincode="+pin+"&phone="+phone+"&country=India",
503
		  +"&state="+state+"&pincode="+pin+"&phone="+phone+"&country=India",
527
		  success: function(msg){
504
		  success: function(msg){
528
			//  alert( "Data Saved: " + msg );
-
 
529
			  // 	$("#addressid").val(msg);
-
 
530
		  }
505
		  }
531
	});
506
	});
532
}
507
}
533
 
508
 
534
function ajaxMakePrimary(addressid){
509
function ajaxMakePrimary(addressid){
535
	jQuery.ajax({
510
	jQuery.ajax({
536
		  type: "POST",
511
		  type: "POST",
537
		  url: "/address",
512
		  url: "/address",
538
		  data: "action=setdefault&addressid="+addressid,
513
		  data: "action=setdefault&addressid="+addressid,
539
		  success: function(msg){
514
		  success: function(msg){
540
			 // alert( "Data Saved: " + msg );
-
 
541
			   //	$("#addressid").val(msg);
-
 
542
		  }
515
		  }
543
	});
516
	});
544
}
517
}
545
 
518
 
546
function ajaxDeleteAddress(addressid){
519
function ajaxDeleteAddress(addressid){
547
	jQuery.ajax({
520
	jQuery.ajax({
548
		  type: "POST",
521
		  type: "POST",
549
		  url: "/address",
522
		  url: "/address",
550
		  data: "action=delete&addressid="+addressid,
523
		  data: "action=delete&addressid="+addressid,
551
		  success: function(msg){
524
		  success: function(msg){
552
			  //alert( "Data Saved: " + msg );
-
 
553
			   //	$("#addressid").val(msg);
-
 
554
		  }
525
		  }
555
	});
526
	});
556
}
527
}