Subversion Repositories SmartDukaan

Rev

Rev 27754 | Rev 36889 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21627 kshitij.so 1
$(function() {
36888 aman 2
 
27754 amit.gupta 3
	$(document).on('click', ".contact-us", function() {
22354 ashik.ali 4
		console.log("Contact Us Button Clicked...")
5
		contactUs("main-content");
6
	});
36888 aman 7
 
8
	// ----- Add / Edit / Delete contact entries (authorised users only) -----
9
 
10
	// Open the modal in "add" mode for the clicked section.
11
	$(document).on('click', ".contact-add-btn", function() {
12
		var section = $(this).data('section');
13
		$('#contactUsForm')[0].reset();
14
		$('#cuId').val(0);
15
		$('#cuSection').val(section);
16
		$('#contactUsModalTitle').text(section === 'ESCALATION' ? 'Add Escalation' : 'Add Contact');
17
		$('#cuBaseAreaLabel').text(section === 'ESCALATION' ? 'Region' : 'Base Area');
18
		$('#contactUsModal').modal('show');
19
	});
20
 
21
	// Open the modal pre-filled in "edit" mode.
22
	$(document).on('click', ".contact-edit-btn", function() {
23
		var btn = $(this);
24
		var section = btn.data('section');
25
		var mobile = String(btn.data('mobile'));
26
		$('#contactUsForm')[0].reset();
27
		$('#cuId').val(btn.data('id'));
28
		$('#cuSection').val(section);
29
		$('#cuArea').val(btn.data('area'));
30
		$('#cuBaseArea').val(btn.data('basearea'));
31
		$('#cuName').val(btn.data('name'));
32
		$('#cuDesignation').val(btn.data('designation'));
33
		$('#cuMobile').val(mobile === '-' ? '' : mobile);
34
		$('#cuEmail').val(btn.data('email'));
35
		$('#contactUsModalTitle').text('Edit Contact');
36
		$('#cuBaseAreaLabel').text(section === 'ESCALATION' ? 'Region' : 'Base Area');
37
		$('#contactUsModal').modal('show');
38
	});
39
 
40
	// Persist add / edit.
41
	$(document).on('click', "#contactUsSaveBtn", function() {
42
		var name = $.trim($('#cuName').val());
43
		if (name === '') {
44
			alert('Name is required.');
45
			return;
46
		}
47
		var params = {
48
			id: $('#cuId').val(),
49
			section: $('#cuSection').val(),
50
			area: $('#cuArea').val(),
51
			baseArea: $('#cuBaseArea').val(),
52
			name: name,
53
			designation: $('#cuDesignation').val(),
54
			mobile: $('#cuMobile').val(),
55
			email: $('#cuEmail').val()
56
		};
57
		doPostAjaxRequestWithParamsHandler(context + "/contactUs/save", params, function(response) {
58
			if (response && response.success) {
59
				$('#contactUsModal').modal('hide');
60
				contactUs("main-content");
61
			} else {
62
				alert((response && response.message) ? response.message : 'Could not save contact.');
63
			}
64
		});
65
	});
66
 
67
	// Soft-delete an entry.
68
	$(document).on('click', ".contact-delete-btn", function() {
69
		var name = $(this).data('name');
70
		if (!confirm('Remove ' + name + ' from the contact list?')) {
71
			return;
72
		}
73
		doPostAjaxRequestWithParamsHandler(context + "/contactUs/delete", { id: $(this).data('id') }, function(response) {
74
			if (response && response.success) {
75
				contactUs("main-content");
76
			} else {
77
				alert((response && response.message) ? response.message : 'Could not remove contact.');
78
			}
79
		});
80
	});
81
 
22661 amit.gupta 82
});
83
 
23343 ashik.ali 84
function contactUs(domId){
23500 ashik.ali 85
	doGetAjaxRequestHandler(context+"/contactUs", function(response){
86
		console.log("doGetAjaxRequest");
23343 ashik.ali 87
		$('#' + domId).html(response);
22245 ashik.ali 88
	});
36888 aman 89
}