| OLD | NEW |
| 1 part of angular.directive; | 1 part of angular.directive; |
| 2 | 2 |
| 3 typedef dynamic ItemEval(dynamic item, num index); | 3 typedef dynamic ItemEval(dynamic item, num index); |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * HTML [SELECT] element with angular data-binding if used with [NgModelDirectiv
e]. | 6 * HTML [SELECT] element with angular data-binding if used with [NgModelDirectiv
e]. |
| 7 * | 7 * |
| 8 * The [NgModelDirective] will receive the currently selected item. The binding
is | 8 * The [NgModelDirective] will receive the currently selected item. The binding
is |
| 9 * performed on the [OPTION].[value] property. | 9 * performed on the [OPTION].[value] property. |
| 10 * An empty [OPTION].[value] is treated as null. | 10 * An empty [OPTION].[value] is treated as null. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 _mode = new _MultipleSelectionMode(expando, _selectElement, _model); | 55 _mode = new _MultipleSelectionMode(expando, _selectElement, _model); |
| 56 } | 56 } |
| 57 _mode.onModelChange(_model.viewValue); | 57 _mode.onModelChange(_model.viewValue); |
| 58 }); | 58 }); |
| 59 | 59 |
| 60 _selectElement.onChange.listen((event) => _mode.onViewChange(event)); | 60 _selectElement.onChange.listen((event) => _mode.onViewChange(event)); |
| 61 _model.render = (value) => _mode.onModelChange(value); | 61 _model.render = (value) => _mode.onModelChange(value); |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * This method invalidates the current state of the selector and forces a rere
ndering of the | 65 * This method invalidates the current state of the selector and forces a re-r
endering of the |
| 66 * options using the [Scope.$evalAsync]. | 66 * options using the [Scope.$evalAsync]. |
| 67 */ | 67 */ |
| 68 dirty() { | 68 dirty() { |
| 69 if (!_dirty) { | 69 if (!_dirty) { |
| 70 _dirty = true; | 70 _dirty = true; |
| 71 _scope.$evalAsync(() { | 71 _scope.$evalAsync(() { |
| 72 _dirty = false; | 72 _dirty = false; |
| 73 _mode.onModelChange(_model.viewValue); | 73 _mode.onModelChange(_model.viewValue); |
| 74 }); | 74 }); |
| 75 } | 75 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (option != _unknownOption && option != _nullOption) { | 168 if (option != _unknownOption && option != _nullOption) { |
| 169 i++; | 169 i++; |
| 170 } | 170 } |
| 171 }, true); | 171 }, true); |
| 172 } | 172 } |
| 173 | 173 |
| 174 onModelChange(value) { | 174 onModelChange(value) { |
| 175 var found = false; | 175 var found = false; |
| 176 _forEachOption((option, i) { | 176 _forEachOption((option, i) { |
| 177 if (option == _unknownOption) return; | 177 if (option == _unknownOption) return; |
| 178 var selected = value == null ? option == _nullOption : expando[option].ngV
alue == value; | 178 var selected; |
| 179 if (value == null) { |
| 180 selected = option == _nullOption; |
| 181 } else { |
| 182 OptionValueDirective optionValueDirective = expando[option]; |
| 183 selected = optionValueDirective == null ? false : optionValueDirective.n
gValue == value; |
| 184 } |
| 179 found = found || selected; | 185 found = found || selected; |
| 180 option.selected = selected; | 186 option.selected = selected; |
| 181 }); | 187 }); |
| 182 | 188 |
| 183 if (!found) { | 189 if (!found) { |
| 184 if (!_unknownOptionActive) { | 190 if (!_unknownOptionActive) { |
| 185 select.insertBefore(_unknownOption, select.firstChild); | 191 select.insertBefore(_unknownOption, select.firstChild); |
| 186 _unknownOption.selected = true; | 192 _unknownOption.selected = true; |
| 187 _unknownOptionActive = true; | 193 _unknownOptionActive = true; |
| 188 } | 194 } |
| 189 } else { | 195 } else { |
| 190 if (_unknownOptionActive) { | 196 if (_unknownOptionActive) { |
| 191 _unknownOption.remove(); | 197 _unknownOption.remove(); |
| 192 _unknownOptionActive = false; | 198 _unknownOptionActive = false; |
| 193 } | 199 } |
| 194 } | 200 } |
| 195 } | 201 } |
| 196 } | 202 } |
| 197 | 203 |
| 198 class _MultipleSelectionMode extends _SelectMode { | 204 class _MultipleSelectionMode extends _SelectMode { |
| 199 _MultipleSelectionMode(Expando<OptionValueDirective> expando, | 205 _MultipleSelectionMode(Expando<OptionValueDirective> expando, |
| 200 dom.SelectElement select, | 206 dom.SelectElement select, |
| 201 NgModel model | 207 NgModel model |
| 202 ): super(expando, select, model); | 208 ): super(expando, select, model); |
| 203 | 209 |
| 204 onViewChange(event) { | 210 onViewChange(event) { |
| 205 var selected = []; | 211 var selected = []; |
| 206 var fn = (o, i) => o.value; | |
| 207 | 212 |
| 208 _forEachOption((o, i) { | 213 _forEachOption((o, i) { |
| 209 if (o.selected) { | 214 if (o.selected) { |
| 210 selected.add(expando[o].ngValue); | 215 selected.add(expando[o].ngValue); |
| 211 } | 216 } |
| 212 }); | 217 }); |
| 213 model.viewValue = selected; | 218 model.viewValue = selected; |
| 214 } | 219 } |
| 215 | 220 |
| 216 onModelChange(List selectedValues) { | 221 onModelChange(List selectedValues) { |
| 217 num index = 0; | |
| 218 Function fn = (o, i) => o.selected = null; | 222 Function fn = (o, i) => o.selected = null; |
| 219 | 223 |
| 220 if (selectedValues is List) { | 224 if (selectedValues is List) { |
| 221 fn = (o, i) => o.selected = selectedValues.contains(expando[o].ngValue); | 225 fn = (o, i) => o.selected = selectedValues.contains(expando[o].ngValue); |
| 222 } | 226 } |
| 223 | 227 |
| 224 _forEachOption(fn); | 228 _forEachOption(fn); |
| 225 } | 229 } |
| 226 } | 230 } |
| OLD | NEW |