diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js
index 2eb67e8..02c871b 100644
a
|
b
|
window.SelectFilter = {
|
21 | 21 | return; |
22 | 22 | } |
23 | 23 | var from_box = document.getElementById(field_id); |
24 | | from_box.id += '_from'; // change its ID |
| 24 | |
| 25 | // Create a clone to keep the actual values to be sent with the form |
| 26 | var actual_box = $(from_box).clone().insertBefore(from_box).hide(); |
| 27 | |
| 28 | from_box.id += '_from'; |
| 29 | from_box.name += '_from'; |
25 | 30 | from_box.className = 'filtered'; |
26 | 31 | |
27 | 32 | var ps = from_box.parentNode.getElementsByTagName('p'); |
… |
… |
window.SelectFilter = {
|
60 | 65 | filter_input.id = field_id + '_input'; |
61 | 66 | |
62 | 67 | selector_available.appendChild(from_box); |
63 | | var choose_all = quickElement('a', selector_available, gettext('Add all'), 'href', 'javascript: (function(){ SelectBox.move_all("' + field_id + '_from", "' + field_id + '_to"); SelectFilter.refresh_icons("' + field_id + '");})()', 'id', field_id + '_add_all_link'); |
| 68 | var choose_all = quickElement('a', selector_available, gettext('Add all'), 'href', 'javascript: (function(){ SelectBox.move_all("' + field_id + '_from", "' + field_id + '_to"); SelectFilter.refresh_state("' + field_id + '");})()', 'id', field_id + '_add_all_link'); |
64 | 69 | choose_all.className = 'selector-chooseall'; |
65 | 70 | |
66 | 71 | // <ul class="selector-chooser"> |
67 | 72 | var selector_chooser = quickElement('ul', selector_div, ''); |
68 | 73 | selector_chooser.className = 'selector-chooser'; |
69 | | var add_link = quickElement('a', quickElement('li', selector_chooser, ''), gettext('Add'), 'title', gettext('Add'), 'href', 'javascript: (function(){ SelectBox.move("' + field_id + '_from","' + field_id + '_to"); SelectFilter.refresh_icons("' + field_id + '");})()', 'id', field_id + '_add_link'); |
| 74 | var add_link = quickElement('a', quickElement('li', selector_chooser, ''), gettext('Add'), 'title', gettext('Add'), 'href', 'javascript: (function(){ SelectBox.move("' + field_id + '_from","' + field_id + '_to"); SelectFilter.refresh_state("' + field_id + '");})()', 'id', field_id + '_add_link'); |
70 | 75 | add_link.className = 'selector-add'; |
71 | | var remove_link = quickElement('a', quickElement('li', selector_chooser, ''), gettext('Remove'), 'title', gettext('Remove'), 'href', 'javascript: (function(){ SelectBox.move("' + field_id + '_to","' + field_id + '_from"); SelectFilter.refresh_icons("' + field_id + '");})()', 'id', field_id + '_remove_link'); |
| 76 | var remove_link = quickElement('a', quickElement('li', selector_chooser, ''), gettext('Remove'), 'title', gettext('Remove'), 'href', 'javascript: (function(){ SelectBox.move("' + field_id + '_to","' + field_id + '_from"); SelectFilter.refresh_state("' + field_id + '");})()', 'id', field_id + '_remove_link'); |
72 | 77 | remove_link.className = 'selector-remove'; |
73 | 78 | |
74 | 79 | // <div class="selector-chosen"> |
… |
… |
window.SelectFilter = {
|
77 | 82 | var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Added %s') + ' ', [field_name])); |
78 | 83 | quickElement('img', title_chosen, '', 'src', admin_media_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of added %s. You may remove some by selecting them below and then clicking the "Remove" button.'), [field_name])); |
79 | 84 | |
80 | | var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', from_box.getAttribute('name')); |
| 85 | var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', actual_box.attr('name') + '_to'); |
81 | 86 | to_box.className = 'filtered'; |
82 | | var clear_all = quickElement('a', selector_chosen, gettext('Remove all'), 'href', 'javascript: (function() { SelectBox.move_all("' + field_id + '_to", "' + field_id + '_from"); SelectFilter.refresh_icons("' + field_id + '");})()', 'id', field_id + '_remove_all_link'); |
| 87 | var clear_all = quickElement('a', selector_chosen, gettext('Remove all'), 'href', 'javascript: (function() { SelectBox.move_all("' + field_id + '_to", "' + field_id + '_from"); SelectFilter.refresh_state("' + field_id + '");})()', 'id', field_id + '_remove_all_link'); |
83 | 88 | clear_all.className = 'selector-clearall'; |
84 | 89 | |
85 | | from_box.setAttribute('name', from_box.getAttribute('name') + '_old'); |
86 | | |
87 | 90 | // Set up the JavaScript event handlers for the select box filter interface |
88 | 91 | addEvent(filter_input, 'keyup', function(e) { SelectFilter.filter_key_up(e, field_id); }); |
89 | 92 | addEvent(filter_input, 'keydown', function(e) { SelectFilter.filter_key_down(e, field_id); }); |
90 | | addEvent(from_box, 'change', function(e) { SelectFilter.refresh_icons(field_id) }); |
91 | | addEvent(to_box, 'change', function(e) { SelectFilter.refresh_icons(field_id) }); |
92 | | addEvent(from_box, 'dblclick', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); }); |
93 | | addEvent(to_box, 'dblclick', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); }); |
94 | | addEvent(findForm(from_box), 'submit', function() { SelectBox.select_all(field_id + '_to'); }); |
| 93 | addEvent(from_box, 'change', function(e) { SelectFilter.refresh_icons(field_id); }); |
| 94 | addEvent(to_box, 'change', function(e) { SelectFilter.refresh_icons(field_id); }); |
| 95 | addEvent(from_box, 'dblclick', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_state(field_id); }); |
| 96 | addEvent(to_box, 'dblclick', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_state(field_id); }); |
95 | 97 | SelectBox.init(field_id + '_from'); |
96 | 98 | SelectBox.init(field_id + '_to'); |
97 | 99 | // Move selected from_box options to to_box |
… |
… |
window.SelectFilter = {
|
102 | 104 | $(to_box).height($(filter_p).outerHeight() + $(from_box).outerHeight()); |
103 | 105 | } |
104 | 106 | |
105 | | // Initial icon refresh |
106 | | SelectFilter.refresh_icons(field_id); |
| 107 | // Initial state refresh |
| 108 | SelectFilter.refresh_state(field_id); |
107 | 109 | }, |
108 | 110 | refresh_icons: function(field_id) { |
109 | 111 | var from = $('#' + field_id + '_from'); |
… |
… |
window.SelectFilter = {
|
117 | 119 | $('#' + field_id + '_add_all_link').toggleClass('active', from.find('option').length > 0); |
118 | 120 | $('#' + field_id + '_remove_all_link').toggleClass('active', to.find('option').length > 0); |
119 | 121 | }, |
| 122 | refresh_state: function(field_id) { |
| 123 | SelectFilter.refresh_icons(field_id); |
| 124 | |
| 125 | // Re-generate the content of the actual, hidden, box. |
| 126 | var actual_box = document.getElementById(field_id); |
| 127 | |
| 128 | // Clear all options. |
| 129 | actual_box.options.length = 0; |
| 130 | |
| 131 | var node, i; |
| 132 | var cache_to = SelectBox.cache[field_id + '_to']; |
| 133 | var cache_from = SelectBox.cache[field_id + '_from']; |
| 134 | |
| 135 | // Add all options from the 'to' box and select them. |
| 136 | for (i = 0; i < cache_to.length; i++) { |
| 137 | node = cache_to[i]; |
| 138 | actual_box.options[actual_box.options.length] = new Option(node.text, node.value, false, true); |
| 139 | } |
| 140 | // Add all options from the 'from' box and keep them unselected. |
| 141 | for (i = 0; i < cache_from.length; i++) { |
| 142 | node = cache_from[i]; |
| 143 | actual_box.options[actual_box.options.length] = new Option(node.text, node.value, false, false); |
| 144 | } |
| 145 | }, |
120 | 146 | filter_key_up: function(event, field_id) { |
121 | 147 | var from = document.getElementById(field_id + '_from'); |
122 | 148 | // don't submit form if user pressed Enter |