Subversion Repositories SmartDukaan

Rev

Rev 36892 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36892 Rev 37019
Line 13... Line 13...
13
		$('#contactUsForm')[0].reset();
13
		$('#contactUsForm')[0].reset();
14
		$('#cuId').val(0);
14
		$('#cuId').val(0);
15
		$('#cuSection').val(section);
15
		$('#cuSection').val(section);
16
		$('#contactUsModalTitle').text(section === 'ESCALATION' ? 'Add Escalation' : 'Add Contact');
16
		$('#contactUsModalTitle').text(section === 'ESCALATION' ? 'Add Escalation' : 'Add Contact');
17
		$('#cuBaseAreaLabel').text(section === 'ESCALATION' ? 'Region' : 'Base Area');
17
		$('#cuBaseAreaLabel').text(section === 'ESCALATION' ? 'Region' : 'Base Area');
-
 
18
		buildPositionOptions(section, null, false);
18
		$('#contactUsModal').modal('show');
19
		$('#contactUsModal').modal('show');
19
	});
20
	});
20
 
21
 
21
	// Open the modal pre-filled in "edit" mode.
22
	// Open the modal pre-filled in "edit" mode.
22
	$(document).on('click', ".contact-edit-btn", function() {
23
	$(document).on('click', ".contact-edit-btn", function() {
Line 32... Line 33...
32
		$('#cuDesignation').val(btn.data('designation'));
33
		$('#cuDesignation').val(btn.data('designation'));
33
		$('#cuMobile').val(mobile === '-' ? '' : mobile);
34
		$('#cuMobile').val(mobile === '-' ? '' : mobile);
34
		$('#cuEmail').val(btn.data('email'));
35
		$('#cuEmail').val(btn.data('email'));
35
		$('#contactUsModalTitle').text('Edit Contact');
36
		$('#contactUsModalTitle').text('Edit Contact');
36
		$('#cuBaseAreaLabel').text(section === 'ESCALATION' ? 'Region' : 'Base Area');
37
		$('#cuBaseAreaLabel').text(section === 'ESCALATION' ? 'Region' : 'Base Area');
-
 
38
		buildPositionOptions(section, btn.data('id'), true);
37
		$('#contactUsModal').modal('show');
39
		$('#contactUsModal').modal('show');
38
	});
40
	});
39
 
41
 
40
	// Persist add / edit.
42
	// Persist add / edit.
41
	$(document).on('click', "#contactUsSaveBtn", function() {
43
	$(document).on('click', "#contactUsSaveBtn", function() {
42
		var name = $.trim($('#cuName').val());
44
		var name = $.trim($('#cuName').val());
43
		if (name === '') {
45
		if (name === '') {
44
			alert('Name is required.');
46
			alert('Name is required.');
45
			return;
47
			return;
46
		}
48
		}
-
 
49
		var isEdit = parseInt($('#cuId').val(), 10) > 0;
-
 
50
		var posVal = $('#cuPosition').val() || (isEdit ? 'KEEP|0' : 'BOTTOM|0');
-
 
51
		var posParts = posVal.split('|');
47
		var params = {
52
		var params = {
48
			id: $('#cuId').val(),
53
			id: $('#cuId').val(),
49
			section: $('#cuSection').val(),
54
			section: $('#cuSection').val(),
50
			area: $('#cuArea').val(),
55
			area: $('#cuArea').val(),
51
			baseArea: $('#cuBaseArea').val(),
56
			baseArea: $('#cuBaseArea').val(),
52
			name: name,
57
			name: name,
53
			designation: $('#cuDesignation').val(),
58
			designation: $('#cuDesignation').val(),
54
			mobile: $('#cuMobile').val(),
59
			mobile: $('#cuMobile').val(),
55
			email: $('#cuEmail').val()
60
			email: $('#cuEmail').val(),
-
 
61
			position: posParts[0],
-
 
62
			afterId: posParts[1] || 0
56
		};
63
		};
57
		doPostAjaxRequestWithParamsHandler(context + "/contactUs/save", params, function(response) {
64
		doPostAjaxRequestWithParamsHandler(context + "/contactUs/save", params, function(response) {
58
			if (response && response.success) {
65
			if (response && response.success) {
59
				$('#contactUsModal').modal('hide');
66
				$('#contactUsModal').modal('hide');
60
				contactUs("main-content");
67
				contactUs("main-content");
Line 90... Line 97...
90
		} else if (confirm('Remove ' + name + ' from the contact list?')) {
97
		} else if (confirm('Remove ' + name + ' from the contact list?')) {
91
			doDelete();
98
			doDelete();
92
		}
99
		}
93
	});
100
	});
94
 
101
 
-
 
102
	// Move a contact one step up/down within its section (authorised users only).
-
 
103
	$(document).on('click', ".contact-up-btn, .contact-down-btn", function() {
-
 
104
		var id = $(this).data('id');
-
 
105
		var direction = $(this).hasClass('contact-up-btn') ? 'UP' : 'DOWN';
-
 
106
		doPostAjaxRequestWithParamsHandler(context + "/contactUs/reorder", { id: id, direction: direction }, function(response) {
-
 
107
			if (response && response.success) {
-
 
108
				contactUs("main-content");
-
 
109
			} else {
-
 
110
				alert((response && response.message) ? response.message : 'Could not reorder contact.');
-
 
111
			}
-
 
112
		});
-
 
113
	});
-
 
114
 
95
});
115
});
96
 
116
 
97
function contactUs(domId){
117
function contactUs(domId){
98
	doGetAjaxRequestHandler(context+"/contactUs", function(response){
118
	doGetAjaxRequestHandler(context+"/contactUs", function(response){
99
		console.log("doGetAjaxRequest");
119
		console.log("doGetAjaxRequest");
Line 104... Line 124...
104
		// Bootstrap modal behind its body-level backdrop ("screen dims, no popup").
124
		// Bootstrap modal behind its body-level backdrop ("screen dims, no popup").
105
		// Move the modal out to <body> so it renders above the backdrop.
125
		// Move the modal out to <body> so it renders above the backdrop.
106
		$('#contactUsModal').appendTo('body');
126
		$('#contactUsModal').appendTo('body');
107
	});
127
	});
108
}
128
}
-
 
129
 
-
 
130
// Populate the "Position in list" dropdown for the given section by scanning the rendered rows.
-
 
131
// On edit, the contact being edited is excluded and "Keep current position" is offered as default.
-
 
132
function buildPositionOptions(section, excludeId, isEdit){
-
 
133
	var $sel = $('#cuPosition').empty();
-
 
134
	if (isEdit) {
-
 
135
		$sel.append($('<option>').val('KEEP|0').text('Keep current position'));
-
 
136
	}
-
 
137
	$sel.append($('<option>').val('TOP|0').text('Top of list'));
-
 
138
	$('#contact-us-table tr[data-cu-section="' + section + '"]').each(function(){
-
 
139
		var cid = String($(this).data('cuId'));
-
 
140
		if (excludeId != null && cid === String(excludeId)) {
-
 
141
			return; // skip the contact being edited - can't place it after itself
-
 
142
		}
-
 
143
		$sel.append($('<option>').val('AFTER|' + cid).text('After — ' + $(this).data('cuName')));
-
 
144
	});
-
 
145
	$sel.append($('<option>').val('BOTTOM|0').text('Bottom of list'));
-
 
146
	$sel.val(isEdit ? 'KEEP|0' : 'BOTTOM|0');
-
 
147
}