|
32 | 32 | xhr: false |
33 | 33 | }, |
34 | 34 |
|
| 35 | + wrapper: null, |
| 36 | + filter: null, |
| 37 | + collection: null, |
| 38 | + addAll: null, |
| 39 | + add: null, |
| 40 | + remove: null, |
| 41 | + up: null, |
| 42 | + down: null, |
| 43 | + selection: null, |
| 44 | + removeAll: null, |
| 45 | + |
35 | 46 | _create: function() { |
36 | 47 | this._cache = {}; |
37 | 48 | this._build(); |
|
42 | 53 | _build: function() { |
43 | 54 | var i; |
44 | 55 |
|
45 | | - this.wrapper = $('<div class="ra-multiselect">'); |
| 56 | + this.wrapper = this.element.siblings( |
| 57 | + '.ra-multiselect[data-input-for="' + this.element.attr('id') + '"]' |
| 58 | + ); |
| 59 | + |
| 60 | + // Prevent duplication on browser back |
| 61 | + if (this.wrapper.length > 0) { |
| 62 | + this.filter = this.wrapper.find('input.ra-multiselect-search'); |
| 63 | + this.collection = this.wrapper.find('select.ra-multiselect-collection'); |
| 64 | + this.addAll = this.wrapper.find('a.ra-multiselect-item-add-all'); |
| 65 | + this.add = this.wrapper.find('a.ra-multiselect-item-add'); |
| 66 | + this.remove = this.wrapper.find('a.ra-multiselect-item-remove'); |
| 67 | + this.up = this.wrapper.find('a.ra-multiselect-item-up'); |
| 68 | + this.down = this.wrapper.find('a.ra-multiselect-item-down'); |
| 69 | + this.selection = this.wrapper.find('select.ra-multiselect-selection'); |
| 70 | + this.removeAll = this.wrapper.find('a.ra-multiselect-item-remove-all'); |
| 71 | + return; |
| 72 | + } |
46 | 73 |
|
| 74 | + this.wrapper = $('<div class="ra-multiselect">').attr('data-input-for', this.element.attr('id')) |
47 | 75 | this.wrapper.insertAfter(this.element); |
48 | | - |
49 | | - this.header = $('<div class="ra-multiselect-header ui-helper-clearfix">'); |
50 | | - |
| 76 | + var header = $('<div class="ra-multiselect-header ui-helper-clearfix">'); |
51 | 77 | this.filter = $('<input type="search" placeholder="' + this.options.regional.search + '" class="form-control ra-multiselect-search"/>'); |
| 78 | + header.append(this.filter); |
| 79 | + this.wrapper.append(header); |
52 | 80 |
|
53 | | - this.header.append(this.filter); |
54 | | - |
55 | | - this.wrapper.append(this.header); |
56 | | - |
57 | | - this.columns = { |
| 81 | + var columns = { |
58 | 82 | left: $('<div class="ra-multiselect-column ra-multiselect-left">'), |
59 | 83 | center: $('<div class="ra-multiselect-column ra-multiselect-center">'), |
60 | 84 | right: $('<div class="ra-multiselect-column ra-multiselect-right">') |
61 | 85 | }; |
62 | 86 |
|
63 | | - for (i in this.columns) { |
64 | | - if (this.columns.hasOwnProperty(i)) { |
65 | | - this.wrapper.append(this.columns[i]); |
| 87 | + for (i in columns) { |
| 88 | + if (columns.hasOwnProperty(i)) { |
| 89 | + this.wrapper.append(columns[i]); |
66 | 90 | } |
67 | 91 | } |
68 | 92 |
|
69 | 93 | this.collection = $('<select multiple="multiple"></select>'); |
70 | | - |
71 | 94 | this.collection.addClass("form-control ra-multiselect-collection"); |
72 | | - |
73 | 95 | this.addAll = $('<a href="#" class="ra-multiselect-item-add-all"><span class="ui-icon ui-icon-circle-triangle-e"></span>' + this.options.regional.chooseAll + '</a>'); |
74 | | - |
75 | | - this.columns.left.html(this.collection) |
76 | | - .append(this.addAll); |
77 | | - |
| 96 | + columns.left.html(this.collection) |
| 97 | + .append(this.addAll); |
78 | 98 | this.collection.wrap('<div class="wrapper"/>'); |
79 | 99 |
|
80 | 100 |
|
81 | 101 | this.add = $('<a href="#" class="ui-icon ui-icon-circle-triangle-e ra-multiselect-item-add">' + this.options.regional.add + '</a>'); |
82 | | - this.columns.center.append(this.add); |
83 | | - |
| 102 | + columns.center.append(this.add); |
84 | 103 | if (this.options.removable) { |
85 | 104 | this.remove = $('<a href="#" class="ui-icon ui-icon-circle-triangle-w ra-multiselect-item-remove">' + this.options.regional.remove + '</a>'); |
86 | | - this.columns.center.append(this.remove); |
| 105 | + columns.center.append(this.remove); |
87 | 106 | } |
88 | | - |
89 | 107 | if (this.options.sortable) { |
90 | 108 | this.up = $('<a href="#" class="ui-icon ui-icon-circle-triangle-n ra-multiselect-item-up">' + this.options.regional.up + '</a>'); |
91 | 109 | this.down = $('<a href="#" class="ui-icon ui-icon-circle-triangle-s ra-multiselect-item-down">' + this.options.regional.down + '</a>'); |
92 | | - this.columns.center.append(this.up).append(this.down); |
| 110 | + columns.center.append(this.up).append(this.down); |
93 | 111 | } |
94 | 112 |
|
95 | 113 | this.selection = $('<select class="form-control ra-multiselect-selection" multiple="multiple"></select>'); |
96 | | - this.columns.right.append(this.selection); |
97 | | - |
98 | | - |
| 114 | + columns.right.append(this.selection); |
99 | 115 | if (this.options.removable) { |
100 | 116 | this.removeAll = $('<a href="#" class="ra-multiselect-item-remove-all"><span class="ui-icon ui-icon-circle-triangle-w"></span>' + this.options.regional.clearAll + '</a>'); |
101 | | - this.columns.right.append(this.removeAll); |
| 117 | + columns.right.append(this.removeAll); |
102 | 118 | } |
103 | | - |
104 | 119 | this.selection.wrap('<div class="wrapper"/>'); |
105 | 120 |
|
106 | 121 | this.element.css({display: "none"}); |
107 | 122 |
|
108 | 123 | this.tooManyObjectsPlaceholder = $('<option disabled="disabled" />').text(RailsAdmin.I18n.t("too_many_objects")); |
109 | 124 | this.noObjectsPlaceholder = $('<option disabled="disabled" />').text(RailsAdmin.I18n.t("no_objects")) |
110 | 125 |
|
111 | | - if(this.options.xhr){ |
| 126 | + if (this.options.xhr) { |
112 | 127 | this.collection.append(this.tooManyObjectsPlaceholder); |
113 | 128 | } |
114 | 129 | }, |
|
0 commit comments