Skip to content

Commit a0eb467

Browse files
committed
Move autocomplete in to separate file.
Other location fixes.
1 parent 1a7e06b commit a0eb467

File tree

4 files changed

+120
-141
lines changed

4 files changed

+120
-141
lines changed

bw-calendar-xsl-caladminrsrc/src/main/webapp/themes/bedeworkAdminTheme/css/default.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,6 @@ label.interiorLabel {
870870
#bwLocationsPrimaryContainer {
871871
margin: 0 0.25em 0.25em 0;
872872
}
873-
#bwLocationsSecondaryContainer {
874-
margin: 0;
875-
}
876873
#bwContactsCell label {
877874
display: block;
878875
}

bw-calendar-xsl-caladminrsrc/src/main/webapp/themes/bedeworkAdminTheme/head.xsl

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<!-- load the bedework event form scripts -->
6767
<script type="text/javascript" src="{$resourcesRoot}/javascript/bedework.js">/* Bedework */</script>
6868
<script type="text/javascript" src="{$resourcesRoot}/javascript/bedeworkEventForm.js?v=2.0.8">/* Bedework Event Form Functions */</script>
69+
<script type="text/javascript" src="{$resourcesRoot}/javascript/bedeworkAutocompletSearch.js">/* Bedework Event Form Autocomplete */</script>
6970
<script type="text/javascript" src="/javascript/bedework/bedeworkXProperties.js">/* Bedework X-Property Handling */</script>
7071
<script type="text/javascript" src="/javascript/bedework/bwClock.js">/* Bedework clock widget */</script>
7172
<link rel="stylesheet" href="/javascript/bedework/bwClock.css"/>
@@ -217,38 +218,16 @@
217218
var locOptionsPrimary = processLocationsPrimary(data.locations,selectedLocUid);
218219
$("#bwLocationsPrimary").append(locOptionsPrimary);
219220

220-
// setup the secondary locations
221-
var locKey = $("#bwLocationsPrimary option:selected").text();
222-
var locEmptyStr = "<xsl:value-of select="$bwStr-AEEF-None"/>";
223-
var locOptionsSecondary = processLocationsSecondary(data.locations,locKey,locEmptyStr,selectedLocUid);
224-
$("#bwLocationsSecondary").html(locOptionsSecondary);
225-
226221
// turn both select boxes into select/search combos
227222
$("#bwLocationsPrimary").select2({
228223
placeholder: selectOrSearchStr,
229224
width: "600"
230225
});
231-
$("#bwLocationsSecondary").select2({
232-
placeholder: selectOrSearchStr,
233-
width: "600"
234-
});
235226

236227
// add the onchange handlers
237228
$("#bwLocationsPrimary").on("change",function() {
238229
var locKey = $("#bwLocationsPrimary option:selected").text();
239230
var locEmptyStr = "<xsl:value-of select="$bwStr-AEEF-None"/>";
240-
var locOptionsSecondary = processLocationsSecondary(data.locations,locKey,locEmptyStr,selectedLocUid);
241-
$("#bwLocationsSecondary").html(locOptionsSecondary);
242-
$("#bwLocationsSecondary").select2("destroy"); // destroy and re-init to reset the options
243-
$("#bwLocationsSecondary").select2({
244-
placeholder: selectOrSearchStr,
245-
width: "600"
246-
});
247-
$("#bwLocation").val($("#bwLocationsSecondary option:selected").val());
248-
$("#bwLocationsSecondaryContainer").show();
249-
});
250-
$("#bwLocationsSecondary").on("change",function() {
251-
$("#bwLocation").val($(this).val());
252231
});
253232
})
254233
.fail(function(jqxhr, textStatus, error ) {
@@ -403,6 +382,7 @@
403382
/bedework/page='eventList'">
404383
<script type="text/javascript" src="{$resourcesRoot}/javascript/bedework.js">/* Bedework */</script>
405384
<script type="text/javascript" src="{$resourcesRoot}/javascript/bedeworkEventForm.js">/* Bedework Event Form Functions */</script>
385+
<script type="text/javascript" src="{$resourcesRoot}/javascript/bedeworkAutocompletSearch.js">/* Bedework Event Form Autocomplete */</script>
406386
<script type="text/javascript" src="/javascript/bedework/bedeworkUtil.js">/* Bedework Utilities */</script>
407387
</xsl:if>
408388
<xsl:if test="/bedework/page='calendarDescriptions' or /bedework/page='displayCalendar'">
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// Implement autocomplete for location and contacts using
3+
// searches of data
4+
//
5+
$(function() {
6+
// Location autocomplete
7+
$("#bwLocationSearch").autocomplete({
8+
minLength: 2,
9+
appendTo: "#bwLocationSearchResults",
10+
source: function (request, response) {
11+
let searchResult = [];
12+
$.ajax({
13+
url: '/cal/location/all.gdo',
14+
method: 'get',
15+
dataType: 'json',
16+
contentType: 'application/json',
17+
data: 'fexpr=loc_all%3d\'' + request.term + '\'',
18+
success: function (result) {
19+
if (result !== undefined) {
20+
if (result.status === 'ok' && result.locations[0]) {
21+
searchResult = result.locations;
22+
console.log("found this first: " + searchResult[0].addressField + " - " + searchResult[0].roomField);
23+
response(searchResult);
24+
}
25+
}
26+
},
27+
error: function (xhr, status, err) {
28+
console.error('/cal/location/all.gdo', status, err.toString());
29+
}
30+
})
31+
},
32+
focus: function (event, ui) {
33+
// do nothing on focus event
34+
return false;
35+
},
36+
select: function (event, ui) {
37+
console.log("selected: " + ui.item.href);
38+
//$(this).val(ui.item.href).removeClass("ui-autocomplete-loading");
39+
40+
let resultString = ui.item.addressField; // this must exist
41+
if (ui.item.roomField !== undefined &&
42+
ui.item.roomField !== "") {
43+
resultString += " - " + ui.item.roomField;
44+
}
45+
46+
$("#bwLocationUid").val(ui.item.uid);
47+
$("#bwLocationSearch").val(resultString);
48+
return false;
49+
}
50+
}).autocomplete("instance")._renderItem = function (ul, item) {
51+
let resultString = '<div class="loc-result-address">' + item.addressField + '</div>'; // this must exist
52+
if (item.roomField !== undefined && item.roomField !== "") {
53+
resultString += '<div class="loc-result-room">' + item.roomField + '</div>';
54+
}
55+
if ((item.street !== undefined && item.street !== "") || (item.city !== undefined && item.city !== "")) {
56+
resultString += '<div class="loc-result-street-address">';
57+
if (item.street !== undefined && item.street !== "") {
58+
resultString += '<span class="loc-result-street">' + item.street;
59+
if (item.city !== undefined && item.city !== "") {
60+
resultString += ', ';
61+
}
62+
resultString += '</span>';
63+
}
64+
if (item.city !== undefined && item.city !== "") {
65+
resultString += '<span class="loc-result-city">' + item.city + '</span>';
66+
}
67+
}
68+
69+
return $('<li class="loc-result">').append(resultString).appendTo(ul);
70+
71+
};
72+
73+
// Contact autocomplete
74+
$("#bwContactSearch").autocomplete({
75+
minLength: 2,
76+
appendTo: "#bwContactSearchResults",
77+
source: function (request, response) {
78+
let searchResult = [];
79+
$.ajax({
80+
url: '/cal/contact/all.gdo',
81+
method: 'get',
82+
dataType: 'json',
83+
contentType: 'application/json',
84+
data: 'fexpr=contact_all%3d\'' + request.term + '\'',
85+
success: function (result) {
86+
if (result !== undefined) {
87+
if (result.status === 'ok' && result.contacts[0]) {
88+
searchResult = result.contacts;
89+
console.log("found this first: " + searchResult[0].cn.value);
90+
response(searchResult);
91+
}
92+
}
93+
},
94+
error: function (xhr, status, err) {
95+
console.error('/cal/contact/all.gdo', status, err.toString());
96+
}
97+
})
98+
},
99+
focus: function (event, ui) {
100+
// do nothing on focus event
101+
return false;
102+
},
103+
select: function (event, ui) {
104+
console.log("selected: " + ui.item.uid);
105+
//$(this).val(ui.item.href).removeClass("ui-autocomplete-loading");
106+
107+
var resultString = ui.item.cn.value; // this must exist
108+
109+
$("#bwContactUid").val(ui.item.uid);
110+
$("#bwContactSearch").val(resultString);
111+
return false;
112+
}
113+
}).autocomplete("instance")._renderItem = function (ul, item) {
114+
var resultString = item.cn.value; // this must exist
115+
return $("<li>").append("<div>" + resultString + "</div>").appendTo(ul);
116+
};
117+
118+
});

bw-calendar-xsl-caladminrsrc/src/main/webapp/themes/bedeworkAdminTheme/javascript/bedeworkEventForm.js

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,119 +1257,3 @@ function bwAddRoom() {
12571257
}
12581258
});
12591259
}
1260-
1261-
// Form bindings
1262-
$(function() {
1263-
// Location autocomplete
1264-
$("#bwLocationSearch").autocomplete({
1265-
minLength: 2,
1266-
appendTo: "#bwLocationSearchResults",
1267-
source: function (request, response) {
1268-
let searchResult = [];
1269-
$.ajax({
1270-
url: '/cal/location/all.gdo',
1271-
method: 'get',
1272-
dataType: 'json',
1273-
contentType: 'application/json',
1274-
data: 'fexpr=loc_all%3d\'' + request.term + '\'',
1275-
success: function (result) {
1276-
if (result !== undefined) {
1277-
if (result.status === 'ok' && result.locations[0]) {
1278-
searchResult = result.locations;
1279-
console.log("found this first: " + searchResult[0].addressField + " - " + searchResult[0].roomField);
1280-
response(searchResult);
1281-
}
1282-
}
1283-
},
1284-
error: function (xhr, status, err) {
1285-
console.error('/cal/location/all.gdo', status, err.toString());
1286-
}
1287-
})
1288-
},
1289-
focus: function (event, ui) {
1290-
// do nothing on focus event
1291-
return false;
1292-
},
1293-
select: function (event, ui) {
1294-
console.log("selected: " + ui.item.href);
1295-
//$(this).val(ui.item.href).removeClass("ui-autocomplete-loading");
1296-
1297-
let resultString = ui.item.addressField; // this must exist
1298-
if (ui.item.roomField !== undefined &&
1299-
ui.item.roomField !== "") {
1300-
resultString += " - " + ui.item.roomField;
1301-
}
1302-
1303-
$("#bwLocationUid").val(ui.item.uid);
1304-
$("#bwLocationSearch").val(resultString);
1305-
return false;
1306-
}
1307-
}).autocomplete("instance")._renderItem = function (ul, item) {
1308-
let resultString = '<div class="loc-result-address">' + item.addressField + '</div>'; // this must exist
1309-
if (item.roomField !== undefined && item.roomField !== "") {
1310-
resultString += '<div class="loc-result-room">' + item.roomField + '</div>';
1311-
}
1312-
if ((item.street !== undefined && item.street !== "") || (item.city !== undefined && item.city !== "")) {
1313-
resultString += '<div class="loc-result-street-address">';
1314-
if (item.street !== undefined && item.street !== "") {
1315-
resultString += '<span class="loc-result-street">' + item.street;
1316-
if (item.city !== undefined && item.city !== "") {
1317-
resultString += ', ';
1318-
}
1319-
resultString += '</span>';
1320-
}
1321-
if (item.city !== undefined && item.city !== "") {
1322-
resultString += '<span class="loc-result-city">' + item.city + '</span>';
1323-
}
1324-
}
1325-
1326-
return $('<li class="loc-result">').append(resultString).appendTo(ul);
1327-
1328-
};
1329-
1330-
// Contact autocomplete
1331-
$("#bwContactSearch").autocomplete({
1332-
minLength: 2,
1333-
appendTo: "#bwContactSearchResults",
1334-
source: function (request, response) {
1335-
let searchResult = [];
1336-
$.ajax({
1337-
url: '/cal/contact/all.gdo',
1338-
method: 'get',
1339-
dataType: 'json',
1340-
contentType: 'application/json',
1341-
data: 'fexpr=contact_all%3d\'' + request.term + '\'',
1342-
success: function (result) {
1343-
if (result !== undefined) {
1344-
if (result.status === 'ok' && result.contacts[0]) {
1345-
searchResult = result.contacts;
1346-
console.log("found this first: " + searchResult[0].cn.value);
1347-
response(searchResult);
1348-
}
1349-
}
1350-
},
1351-
error: function (xhr, status, err) {
1352-
console.error('/cal/contact/all.gdo', status, err.toString());
1353-
}
1354-
})
1355-
},
1356-
focus: function (event, ui) {
1357-
// do nothing on focus event
1358-
return false;
1359-
},
1360-
select: function (event, ui) {
1361-
console.log("selected: " + ui.item.uid);
1362-
//$(this).val(ui.item.href).removeClass("ui-autocomplete-loading");
1363-
1364-
var resultString = ui.item.cn.value; // this must exist
1365-
1366-
$("#bwContactUid").val(ui.item.uid);
1367-
$("#bwContactSearch").val(resultString);
1368-
return false;
1369-
}
1370-
}).autocomplete("instance")._renderItem = function (ul, item) {
1371-
var resultString = item.cn.value; // this must exist
1372-
return $("<li>").append("<div>" + resultString + "</div>").appendTo(ul);
1373-
};
1374-
1375-
});

0 commit comments

Comments
 (0)