Ticket #13883: RelatedObjectLookups.js.diff
File RelatedObjectLookups.js.diff, 2.1 KB (added by , 14 years ago) |
---|
-
js/admin/RelatedObjectLookups.js
66 66 return false; 67 67 } 68 68 69 function dismissAddAnotherPopup(win, newId, newRepr ) {70 // newId and newReprare expected to have previously been escaped by69 function dismissAddAnotherPopup(win, newId, newRepr, newGrp) { 70 // newId, newRepr and newGrp are expected to have previously been escaped by 71 71 // django.utils.html.escape. 72 72 newId = html_unescape(newId); 73 73 newRepr = html_unescape(newRepr); 74 newGrp = newGrp? html_unescape(newGrp): null; 74 75 var name = windowname_to_id(win.name); 75 76 var elem = document.getElementById(name); 76 if (elem) { 77 if (elem) { //simple selects 77 78 if (elem.nodeName == 'SELECT') { 78 79 var o = new Option(newRepr, newId); 79 elem.options[elem.options.length] = o; 80 if(newGrp) { //find/create option group 81 var grps = elem.getElementsByTagName('optgroup'); 82 var grp = null; 83 for(var i=0; i < grps.length; i++) { 84 if(grps[i].getAttribute('label') == newGrp) { 85 grp = grps[i]; 86 break; 87 } 88 } 89 if(grp == null) { 90 grp = document.createElement('optgroup'); 91 grp.setAttribute('label', newGrp); 92 elem.appendChild(grp); 93 } 94 grp.appendChild(o); 95 } else { 96 elem.options[elem.options.length] = o; 97 } 80 98 o.selected = true; 81 99 } else if (elem.nodeName == 'INPUT') { 82 100 if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { … … 89 107 var toId = name + "_to"; 90 108 elem = document.getElementById(toId); 91 109 var o = new Option(newRepr, newId); 92 SelectBox.add_to_cache(toId, o );110 SelectBox.add_to_cache(toId, o, newGrp); 93 111 SelectBox.redisplay(toId); 94 112 } 95 113 win.close();