Subversion Repositories SmartDukaan

Rev

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

Rev 36888 Rev 36889
Line 1... Line 1...
1
$(function() {
1
$(function() {
2
 
2
	
3
	$(document).on('click', ".contact-us", function() {
3
	$(document).on('click', ".contact-us", function() {
4
		console.log("Contact Us Button Clicked...")
4
		console.log("Contact Us Button Clicked...")
5
		contactUs("main-content");
5
		contactUs("main-content");
6
	});
6
	});
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
 
7
	
82
});
8
});
83
 
9
 
84
function contactUs(domId){
10
function contactUs(domId){
85
	doGetAjaxRequestHandler(context+"/contactUs", function(response){
11
	doGetAjaxRequestHandler(context+"/contactUs", function(response){
86
		console.log("doGetAjaxRequest");
12
		console.log("doGetAjaxRequest");
87
		$('#' + domId).html(response);
13
		$('#' + domId).html(response);
88
	});
14
	});
89
}
15
}
90
16