=== modified file 'django/contrib/admin/media/js/SelectBox.js'
|
|
|
|
| 3 | 3 | init: function(id) { |
| 4 | 4 | var box = document.getElementById(id); |
| 5 | 5 | var node; |
| 6 | | SelectBox.cache[id] = new Array(); |
| 7 | | var cache = SelectBox.cache[id]; |
| 8 | | for (var i = 0; (node = box.options[i]); i++) { |
| 9 | | cache.push({ value: node.value, text: node.text, displayed: 1 }); |
| | 6 | SelectBox.cache[id] = new Object(); |
| | 7 | var boxCache = SelectBox.cache[id]; |
| | 8 | for (var i=0; (node=box.options[i]); i++) { |
| | 9 | boxCache[node.value] = {value: node.value, text: node.text, displayed: 1}; |
| 10 | 10 | } |
| 11 | 11 | }, |
| 12 | 12 | redisplay: function(id) { |
| 13 | 13 | // Repopulate HTML select box from cache |
| 14 | 14 | var box = document.getElementById(id); |
| 15 | 15 | box.options.length = 0; // clear all options |
| 16 | | for (var i = 0, j = SelectBox.cache[id].length; i < j; i++) { |
| 17 | | var node = SelectBox.cache[id][i]; |
| | 16 | var elementsArray = SelectBox.sort(id); |
| | 17 | for (var i=0; i<elementsArray.length; i++ ) { |
| | 18 | var node = elementsArray[i]; //SelectBox.cache[id][nodeValue]; |
| 18 | 19 | if (node.displayed) { |
| 19 | 20 | box.options[box.options.length] = new Option(node.text, node.value, false, false); |
| 20 | 21 | } |
| … |
… |
|
| 25 | 26 | // the words in text. (It's an AND search.) |
| 26 | 27 | var tokens = text.toLowerCase().split(/\s+/); |
| 27 | 28 | var node, token; |
| 28 | | for (var i = 0; (node = SelectBox.cache[id][i]); i++) { |
| | 29 | for (var nodeValue in SelectBox.cache[id]) { |
| | 30 | node = SelectBox.cache[id][nodeValue]; |
| 29 | 31 | node.displayed = 1; |
| 30 | | for (var j = 0; (token = tokens[j]); j++) { |
| | 32 | for (var j=0; (token=tokens[j]); j++) { |
| 31 | 33 | if (node.text.toLowerCase().indexOf(token) == -1) { |
| 32 | 34 | node.displayed = 0; |
| 33 | 35 | } |
| … |
… |
|
| 36 | 38 | SelectBox.redisplay(id); |
| 37 | 39 | }, |
| 38 | 40 | delete_from_cache: function(id, value) { |
| 39 | | var node, delete_index = null; |
| 40 | | for (var i = 0; (node = SelectBox.cache[id][i]); i++) { |
| 41 | | if (node.value == value) { |
| 42 | | delete_index = i; |
| 43 | | break; |
| 44 | | } |
| 45 | | } |
| 46 | | var j = SelectBox.cache[id].length - 1; |
| 47 | | for (var i = delete_index; i < j; i++) { |
| 48 | | SelectBox.cache[id][i] = SelectBox.cache[id][i+1]; |
| 49 | | } |
| 50 | | SelectBox.cache[id].length--; |
| | 41 | delete SelectBox.cache[id][value]; |
| 51 | 42 | }, |
| 52 | 43 | add_to_cache: function(id, option) { |
| 53 | | SelectBox.cache[id].push({ value: option.value, text: option.text, displayed: 1 }); |
| | 44 | SelectBox.cache[id][option.value] = {value: option.value, text: option.text, displayed: 1}; |
| 54 | 45 | }, |
| 55 | 46 | cache_contains: function(id, value) { |
| 56 | | // Check if an item is contained in the cache |
| 57 | | var node; |
| 58 | | for (var i = 0; (node = SelectBox.cache[id][i]); i++) { |
| 59 | | if (node.value == value) { |
| 60 | | return true; |
| 61 | | } |
| 62 | | } |
| 63 | | return false; |
| | 47 | return SelectBox.cache[id].hasOwnProperty(value); |
| 64 | 48 | }, |
| 65 | 49 | move: function(from, to) { |
| 66 | 50 | var from_box = document.getElementById(from); |
| 67 | 51 | var to_box = document.getElementById(to); |
| 68 | 52 | var option; |
| 69 | | for (var i = 0; (option = from_box.options[i]); i++) { |
| | 53 | for (var i=0; (option=from_box.options[i]); i++) { |
| 70 | 54 | if (option.selected && SelectBox.cache_contains(from, option.value)) { |
| 71 | | SelectBox.add_to_cache(to, { value: option.value, text: option.text, displayed: 1 }); |
| | 55 | SelectBox.add_to_cache(to, {value: option.value, text: option.text, displayed: 1}); |
| 72 | 56 | SelectBox.delete_from_cache(from, option.value); |
| 73 | 57 | } |
| 74 | 58 | } |
| … |
… |
|
| 79 | 63 | var from_box = document.getElementById(from); |
| 80 | 64 | var to_box = document.getElementById(to); |
| 81 | 65 | var option; |
| 82 | | for (var i = 0; (option = from_box.options[i]); i++) { |
| 83 | | SelectBox.add_to_cache(to, { value: option.value, text: option.text, displayed: 1 }); |
| | 66 | for (var i=0; (option=from_box.options[i]); i++) { |
| | 67 | SelectBox.add_to_cache(to, {value: option.value, text: option.text, displayed: 1}); |
| 84 | 68 | SelectBox.delete_from_cache(from, option.value); |
| 85 | 69 | } |
| 86 | 70 | SelectBox.redisplay(from); |
| 87 | 71 | SelectBox.redisplay(to); |
| 88 | 72 | }, |
| 89 | 73 | sort: function(id) { |
| 90 | | SelectBox.cache[id].sort( function(a, b) { |
| | 74 | var cache = SelectBox.cache[id]; |
| | 75 | var array = new Array(); |
| | 76 | for (optionValue in cache) { |
| | 77 | var option = cache[optionValue]; |
| | 78 | array.push(option); |
| | 79 | } |
| | 80 | array.sort(function(a, b) { |
| 91 | 81 | a = a.text.toLowerCase(); |
| 92 | 82 | b = b.text.toLowerCase(); |
| 93 | 83 | try { |
| … |
… |
|
| 98 | 88 | // silently fail on IE 'unknown' exception |
| 99 | 89 | } |
| 100 | 90 | return 0; |
| 101 | | } ); |
| | 91 | }); |
| | 92 | return array; |
| 102 | 93 | }, |
| 103 | 94 | select_all: function(id) { |
| 104 | 95 | var box = document.getElementById(id); |
| 105 | | for (var i = 0; i < box.options.length; i++) { |
| | 96 | for (var i=0; i<box.options.length; i++) { |
| 106 | 97 | box.options[i].selected = 'selected'; |
| 107 | 98 | } |
| 108 | 99 | } |