1 | | // Handles related-objects functionality: lookup link for raw_id_fields |
2 | | // and Add Another links. |
3 | | |
4 | | function html_unescape(text) { |
5 | | // Unescape a string that was escaped using django.utils.html.escape. |
6 | | text = text.replace(/</g, '<'); |
7 | | text = text.replace(/>/g, '>'); |
8 | | text = text.replace(/"/g, '"'); |
9 | | text = text.replace(/'/g, "'"); |
10 | | text = text.replace(/&/g, '&'); |
11 | | return text; |
12 | | } |
13 | | |
14 | | function showRelatedObjectLookupPopup(triggeringLink) { |
15 | | var name = triggeringLink.id.replace(/^lookup_/, ''); |
16 | | // IE doesn't like periods in the window name, so convert temporarily. |
17 | | name = name.replace(/\./g, '___'); |
18 | | var href; |
19 | | if (triggeringLink.href.search(/\?/) >= 0) { |
20 | | href = triggeringLink.href + '&pop=1'; |
21 | | } else { |
22 | | href = triggeringLink.href + '?pop=1'; |
23 | | } |
24 | | var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); |
25 | | win.focus(); |
26 | | return false; |
27 | | } |
28 | | |
29 | | function dismissRelatedLookupPopup(win, chosenId) { |
30 | | var name = win.name.replace(/___/g, '.'); |
31 | | var elem = document.getElementById(name); |
32 | | if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { |
33 | | elem.value += ',' + chosenId; |
34 | | } else { |
35 | | document.getElementById(name).value = chosenId; |
36 | | } |
37 | | win.close(); |
38 | | } |
39 | | |
40 | | function showAddAnotherPopup(triggeringLink) { |
41 | | var name = triggeringLink.id.replace(/^add_/, ''); |
42 | | name = name.replace(/\./g, '___'); |
43 | | href = triggeringLink.href |
44 | | if (href.indexOf('?') == -1) { |
45 | | href += '?_popup=1'; |
46 | | } else { |
47 | | href += '&_popup=1'; |
48 | | } |
49 | | var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); |
50 | | win.focus(); |
51 | | return false; |
52 | | } |
53 | | |
54 | | function dismissAddAnotherPopup(win, newId, newRepr) { |
55 | | // newId and newRepr are expected to have previously been escaped by |
56 | | // django.utils.html.escape. |
57 | | newId = html_unescape(newId); |
58 | | newRepr = html_unescape(newRepr); |
59 | | var name = win.name.replace(/___/g, '.'); |
60 | | var elem = document.getElementById(name); |
61 | | if (elem) { |
62 | | if (elem.nodeName == 'SELECT') { |
63 | | var o = new Option(newRepr, newId); |
64 | | elem.options[elem.options.length] = o; |
65 | | o.selected = true; |
66 | | } else if (elem.nodeName == 'INPUT') { |
67 | | elem.value = newId; |
68 | | } |
69 | | } else { |
70 | | var toId = name + "_to"; |
71 | | elem = document.getElementById(toId); |
72 | | var o = new Option(newRepr, newId); |
73 | | SelectBox.add_to_cache(toId, o); |
74 | | SelectBox.redisplay(toId); |
75 | | } |
76 | | win.close(); |
77 | | } |
| 1 | // Handles related-objects functionality: lookup link for raw_id_fields |
| 2 | // and Add Another links. |
| 3 | |
| 4 | function html_unescape(text) { |
| 5 | // Unescape a string that was escaped using django.utils.html.escape. |
| 6 | text = text.replace(/</g, '<'); |
| 7 | text = text.replace(/>/g, '>'); |
| 8 | text = text.replace(/"/g, '"'); |
| 9 | text = text.replace(/'/g, "'"); |
| 10 | text = text.replace(/&/g, '&'); |
| 11 | return text; |
| 12 | } |
| 13 | |
| 14 | function showRelatedObjectLookupPopup(triggeringLink) { |
| 15 | var name = triggeringLink.id.replace(/^lookup_/, ''); |
| 16 | // IE doesn't like periods in the window name, so convert temporarily. |
| 17 | name = name.replace(/\./g, '___'); |
| 18 | var href; |
| 19 | if (triggeringLink.href.search(/\?/) >= 0) { |
| 20 | href = triggeringLink.href + '&pop=1'; |
| 21 | } else { |
| 22 | href = triggeringLink.href + '?pop=1'; |
| 23 | } |
| 24 | var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); |
| 25 | win.focus(); |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | function dismissRelatedLookupPopup(win, chosenId) { |
| 30 | var name = win.name.replace(/___/g, '.'); |
| 31 | var elem = document.getElementById(name); |
| 32 | if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { |
| 33 | elem.value += ',' + chosenId; |
| 34 | } else { |
| 35 | document.getElementById(name).value = chosenId; |
| 36 | } |
| 37 | win.close(); |
| 38 | } |
| 39 | |
| 40 | function showAddAnotherPopup(triggeringLink) { |
| 41 | var name = triggeringLink.id.replace(/^add_/, ''); |
| 42 | name = name.replace(/\./g, '___'); |
| 43 | href = triggeringLink.href |
| 44 | if (href.indexOf('?') == -1) { |
| 45 | href += '?_popup=1'; |
| 46 | } else { |
| 47 | href += '&_popup=1'; |
| 48 | } |
| 49 | var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); |
| 50 | win.focus(); |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | function showEditSelectedPopup(triggeringLink) { |
| 55 | var name = triggeringLink.id.replace(/^edit_/, ''); |
| 56 | name = name.replace(/\./g, '___'); |
| 57 | var elem = document.getElementById(name); |
| 58 | var id = elem.options[elem.selectedIndex].value; |
| 59 | if (id == '') |
| 60 | return false; |
| 61 | |
| 62 | href = triggeringLink.href +id+'/'; |
| 63 | if (href.indexOf('?') == -1) { |
| 64 | href += '?_popup=1'; |
| 65 | } else { |
| 66 | href += '&_popup=1'; |
| 67 | } |
| 68 | var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); |
| 69 | win.focus(); |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | function dismissAddAnotherPopup(win, newId, newRepr) { |
| 74 | // newId and newRepr are expected to have previously been escaped by |
| 75 | // django.utils.html.escape. |
| 76 | newId = html_unescape(newId); |
| 77 | newRepr = html_unescape(newRepr); |
| 78 | var name = win.name.replace(/___/g, '.'); |
| 79 | var elem = document.getElementById(name); |
| 80 | if (elem) { |
| 81 | if (elem.nodeName == 'SELECT') { |
| 82 | var o = new Option(newRepr, newId); |
| 83 | elem.options[elem.options.length] = o; |
| 84 | o.selected = true; |
| 85 | } else if (elem.nodeName == 'INPUT') { |
| 86 | elem.value = newId; |
| 87 | } |
| 88 | } else { |
| 89 | var toId = name + "_to"; |
| 90 | elem = document.getElementById(toId); |
| 91 | var o = new Option(newRepr, newId); |
| 92 | SelectBox.add_to_cache(toId, o); |
| 93 | SelectBox.redisplay(toId); |
| 94 | } |
| 95 | win.close(); |
| 96 | } |