-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathselectable-item.js
More file actions
55 lines (48 loc) · 1.55 KB
/
selectable-item.js
File metadata and controls
55 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import Component from '@ember/component';
import ChildComponentSupport from 'ember-composability/mixins/child-component-support';
import SelectableItemGroup from './selectable-item-group';
import jQuery from 'jquery';
export default Component.extend(ChildComponentSupport, {
// eslint-disable-next-line
_parentComponentTypes: [SelectableItemGroup],
checked: null,
disabled: false,
classNames: ['materialize-selectable-item'],
_checked: computed('checked', 'group.selection', 'group.selection.[]', {
get() {
let group = this.get('group');
if (!group) {
return this.get('checked');
} else {
return group.isValueSelected(this.get('value'));
}
},
set(key, val) {
let group = this.get('group');
if (!group) {
this.set('checked', val);
} else {
group.setValueSelection(this.get('value'), val);
}
this.sendAction('action', { checked: !!val });
return !!val;
}
}),
isSelected: alias('_checked'),
_setupLabel() {
let [$input] = jQuery(
'.materialize-selectable-item-input, .materialize-selectable-item-input-container input'
).toArray();
let inputId = $input ? $input.id : null;
jQuery('.materialize-selectable-item-label').attr('for', inputId);
},
didInsertElement() {
this._super(...arguments);
this._setupLabel();
},
group: computed(function() {
return this.nearestWithProperty('__materializeSelectableItemGroup');
})
});