2017-10-20 03:51:08 +08:00
|
|
|
import { on } from "ember-addons/ember-computed-decorators";
|
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2017-11-21 18:53:09 +08:00
|
|
|
import SelectKitHeaderComponent from "select-kit/components/select-kit/select-kit-header";
|
2017-10-20 03:51:08 +08:00
|
|
|
|
2017-11-21 18:53:09 +08:00
|
|
|
export default SelectKitHeaderComponent.extend({
|
2017-12-22 20:08:12 +08:00
|
|
|
attributeBindings: [
|
|
|
|
"label:title",
|
|
|
|
"label:aria-label",
|
|
|
|
"names:data-name",
|
|
|
|
"values:data-value"
|
|
|
|
],
|
2017-11-21 18:53:09 +08:00
|
|
|
classNames: "multi-select-header",
|
|
|
|
layoutName: "select-kit/templates/components/multi-select/multi-select-header",
|
2017-11-10 02:57:53 +08:00
|
|
|
selectedNameComponent: Ember.computed.alias("options.selectedNameComponent"),
|
2017-10-20 03:51:08 +08:00
|
|
|
|
2017-12-22 20:08:12 +08:00
|
|
|
ariaLabel: Ember.computed.or("computedContent.ariaLabel", "title", "names"),
|
|
|
|
|
|
|
|
title: Ember.computed.or("computedContent.title", "names"),
|
|
|
|
|
2017-10-20 03:51:08 +08:00
|
|
|
@on("didRender")
|
|
|
|
_positionFilter() {
|
2017-12-22 20:08:12 +08:00
|
|
|
if (!this.get("shouldDisplayFilter")) return;
|
2017-11-10 02:57:53 +08:00
|
|
|
|
|
|
|
const $filter = this.$(".filter");
|
|
|
|
$filter.width(0);
|
2017-10-20 03:51:08 +08:00
|
|
|
|
|
|
|
const leftHeaderOffset = this.$().offset().left;
|
2017-11-10 02:57:53 +08:00
|
|
|
const leftFilterOffset = $filter.offset().left;
|
2017-10-20 03:51:08 +08:00
|
|
|
const offset = leftFilterOffset - leftHeaderOffset;
|
|
|
|
const width = this.$().outerWidth(false);
|
|
|
|
const availableSpace = width - offset;
|
2017-11-10 02:57:53 +08:00
|
|
|
const $choices = $filter.parent(".choices");
|
|
|
|
const parentRightPadding = parseInt($choices.css("padding-right") , 10);
|
|
|
|
$filter.width(availableSpace - parentRightPadding * 4);
|
2017-10-20 03:51:08 +08:00
|
|
|
},
|
|
|
|
|
2018-03-22 18:29:55 +08:00
|
|
|
@computed("computedContent.selection.[]")
|
2017-12-22 20:08:12 +08:00
|
|
|
names(selection) {
|
|
|
|
return Ember.makeArray(selection).map(s => s.name).join(",");
|
|
|
|
},
|
|
|
|
|
2018-03-22 18:29:55 +08:00
|
|
|
@computed("computedContent.selection.[]")
|
2017-12-22 20:08:12 +08:00
|
|
|
values(selection) {
|
|
|
|
return Ember.makeArray(selection).map(s => s.value).join(",");
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
2017-10-20 03:51:08 +08:00
|
|
|
});
|