blob: f10bd090e5b792a0b0486baa9a388ab3bf2b2943 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
function angebotVereinDialog(data) {
if (data.status == 'failure') {
$('#angebotDialog div.divForForm').html(data.div);
// Submit the form via function createAngebot
$('#angebotDialog div.divForForm form').submit(createAngebot);
} else {
$('#angebotDialog div.divForForm').html(data.div);
setTimeout("$('#angebotDialog').dialog('close')", 3000);
selectAngebot(data);
}
}
function selectAngebot(angebot) {
$("#AngebotVerein_angebot_id").val(angebot.value);
$("#angebot_name").val(angebot.label);
var newSelectObj = clearSelectBox("#AngebotVerein_einheit");
$("#emptyEinheitenTxt")[0].style.display = "none";
var count = 0;
var einheiten = angebot.einheiten.split(",");
for (i in einheiten) {
var einheit = einheiten[i].trim();
newSelectObj.options[count++] = new Option(einheit, einheit);
}
newSelectObj.style.display = "inline";
return false;
}
function changeAngebot(event) {
var autocomplete = $(this).data("autocomplete");
if (autocomplete.selectedItem) {
return;
}
var userEnteredValue = $(this).val();
if (null != userEnteredValue && !userEnteredValue.isEmpty()) { // User has entered at list one non-whitespace character
var escapedValue = $.ui.autocomplete.escapeRegex(userEnteredValue);
// Matcher to check if the user entered value is in element list
var fullMatcher = new RegExp("^" + escapedValue + "$", "i");
// Matcher to check if an element exists that starts with the user entered value
var partMatcher = new RegExp("^" + escapedValue, "i");
var items = autocomplete.widget().children(".ui-menu-item");
if (1 == items.length) {
items.each(function() {
// The current item in iteration
var item = $(this).data("item.autocomplete");
if (null != item.label && !item.label.isEmpty()) { // Check only if current item has a label
if (fullMatcher.test(item.label)) { // The label is identical with the user value
autocomplete.selectedItem = item; // Set the selected item to the current item
return false; // Return -> item already found
} else if (partMatcher.test(item.label)) { // The label starts with the user value
var conf = confirm("Meinten Sie \""+item.label+"\"?"); // Ask the user if the item is the one to choose
if (conf) { // The item is the one to choose
autocomplete.selectedItem = item; // Set the selected item to the current item
return false; // Return -> item already found
}
}
}
});
}
if (autocomplete.selectedItem) {
autocomplete._trigger("select", event, { item: autocomplete.selectedItem });
} else {
resetEinheiten();
// Ask the user to create the non-existing Angebot
var conf = confirm("Das eingegebene Angebot existiert noch nicht. Wollen Sie dieses Angebot neu erstellen?");
if (conf) { // The Angebot should be created
openAngebotDialog(); // initialize and open Angebot dialog
}
}
} else { // User has not entered anything or only entered whitespace characters
$("#AngebotVerein_angebot_id").val("");
resetEinheiten();
}
}
function resetEinheiten() {
clearSelectBox("#AngebotVerein_einheit");
$("#emptyEinheitenTxt")[0].style.display = "inline";
}
function clearSelectBox(id) {
var selectObj = $(id)[0];
if (null != selectObj) {
selectObj.style.display = "none";
var selectParentNode = selectObj.parentNode;
var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy
selectParentNode.replaceChild(newSelectObj, selectObj);
return newSelectObj;
}
return null;
}
|