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",
|
2018-06-15 23:03:24 +08:00
|
|
|
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
|
|
|
|
2018-09-12 18:19:04 +08:00
|
|
|
forceEscape: Ember.computed.alias("options.forceEscape"),
|
|
|
|
|
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() {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (!this.shouldDisplayFilter) return;
|
2017-11-10 02:57:53 +08:00
|
|
|
|
2019-07-16 18:45:15 +08:00
|
|
|
const $filter = $(this.element.querySelector(".filter"));
|
2017-11-10 02:57:53 +08:00
|
|
|
$filter.width(0);
|
2017-10-20 03:51:08 +08:00
|
|
|
|
2019-07-16 18:45:15 +08:00
|
|
|
const leftHeaderOffset = $(this.element).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;
|
2019-07-16 18:45:15 +08:00
|
|
|
const width = $(this.element).outerWidth(false);
|
2017-10-20 03:51:08 +08:00
|
|
|
const availableSpace = width - offset;
|
2017-11-10 02:57:53 +08:00
|
|
|
const $choices = $filter.parent(".choices");
|
2018-06-15 23:03:24 +08:00
|
|
|
const parentRightPadding = parseInt($choices.css("padding-right"), 10);
|
2017-11-10 02:57:53 +08:00
|
|
|
$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) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return Ember.makeArray(selection)
|
|
|
|
.map(s => s.name)
|
|
|
|
.join(",");
|
2017-12-22 20:08:12 +08:00
|
|
|
},
|
|
|
|
|
2018-03-22 18:29:55 +08:00
|
|
|
@computed("computedContent.selection.[]")
|
2017-12-22 20:08:12 +08:00
|
|
|
values(selection) {
|
2018-06-15 23:03:24 +08:00
|
|
|
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
|
|
|
});
|