Skip to content

Commit

Permalink
feat(collection): add select all, clear and disabled, close #276
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanood committed Sep 18, 2016
1 parent 6095557 commit e3f3bf0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/collection/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ export class MdCollection {
return items.filter(i => i.au['md-collection-selector'].viewModel.isSelected)
.map(i => i.au['md-collection-selector'].viewModel.item);
}

clearSelection() {
let items = [].slice.call(this.element.querySelectorAll('md-collection-selector'));
items.forEach(i => i.au['md-collection-selector'].viewModel.isSelected = false);
}

selectAll() {
let items = [].slice.call(this.element.querySelectorAll('md-collection-selector'));
items.forEach(i => {
let vm = i.au['md-collection-selector'].viewModel;
vm.isSelected = !vm.mdDisabled;
});
}
}
2 changes: 1 addition & 1 deletion src/collection/md-collection-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<!-- <content select=".md-collection-selector__hover"></content> -->
<slot></slot>
<div>
<md-checkbox md-checked.two-way="isSelected"></mdl-checkbox>
<md-checkbox md-checked.two-way="isSelected" md-disabled.bind="mdDisabled"></mdl-checkbox>
</div>
</template>
6 changes: 6 additions & 0 deletions src/collection/md-collection-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { bindable, customElement } from 'aurelia-templating';
import { inject } from 'aurelia-dependency-injection';
import { observable } from 'aurelia-binding';
import { fireMaterializeEvent } from '../common/events';
import { getBooleanFromAttributeValue } from '../common/attributes';

@customElement('md-collection-selector')
@inject(Element)
export class MdlListSelector {
@bindable() item;
@bindable() mdDisabled = false;
@observable() isSelected = false;

constructor(element) {
Expand All @@ -16,4 +18,8 @@ export class MdlListSelector {
isSelectedChanged(newValue) {
fireMaterializeEvent(this.element, 'selection-changed', { item: this.item, isSelected: this.isSelected });
}

mdDisabledChanged(newValue) {
this.mdDisabled = getBooleanFromAttributeValue(newValue);
}
}

0 comments on commit e3f3bf0

Please sign in to comment.