Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import Ember from 'ember';
  2.  
  3. const {
  4. Component,
  5. get,
  6. set,
  7. computed: { filter }
  8. } = Ember;
  9.  
  10. export default Component.extend({
  11.  
  12. classNames: ['multi-select'],
  13.  
  14. _optionFilter: '',
  15. _selectedOptionFilter: '',
  16. _selectedOptions: [],
  17.  
  18. _options: filter('options', function(option) {
  19.  
  20. return ! get(this, '_selectedOptions').contains(option);
  21.  
  22. }).property('options.[]','_selectedOptions.[]'),
  23.  
  24. _filteredOptions: filter('_options', function(option) {
  25. const filter = get(this, '_optionFilter');
  26. const regex = new RegExp(filter, 'gi');
  27.  
  28. return get(option, 'name').match(regex);
  29.  
  30. }).property('_optionFilter', '_options.[]'),
  31.  
  32. _filteredSelectedOptions: filter('_selectedOptions', function(option) {
  33. const filter = get(this, '_selectedOptionFilter');
  34. const regex = new RegExp(filter, 'gi');
  35.  
  36. return get(option, 'name').match(regex);
  37.  
  38. }).property('_selectedOptionFilter', '_selectedOptions.[]'),
  39.  
  40. actions: {
  41. selectOption(option) {
  42. get(this, '_selectedOptions').addObject(option);
  43. },
  44. deselectOption(option) {
  45. get(this, '_selectedOptions').removeObject(option);
  46. }
  47. }
  48.  
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement