2016-07-07 18:54:16 -07:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
import { set } from '@ember/object';
|
|
|
|
import Component from '@ember/component';
|
2017-12-06 19:56:51 +00:00
|
|
|
import { computed } from '@ember/object';
|
2017-11-16 13:28:05 +00:00
|
|
|
|
|
|
|
export default Component.extend({
|
2017-09-21 15:48:00 +01:00
|
|
|
nameField: 'category',
|
2017-11-22 16:28:17 +00:00
|
|
|
singleSelect: false,
|
2017-12-06 19:56:51 +00:00
|
|
|
maxHeight: 0,
|
2017-12-07 20:47:26 +00:00
|
|
|
onSelect: null,
|
2017-12-06 19:56:51 +00:00
|
|
|
styleCss: computed('maxHeight', function () {
|
|
|
|
let height = this.get('maxHeight');
|
|
|
|
|
|
|
|
if (height > 0) {
|
|
|
|
return `overflow-y: scroll; max-height: ${height}px;`;
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}),
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
},
|
|
|
|
|
2017-09-21 15:48:00 +01:00
|
|
|
actions: {
|
|
|
|
onToggle(item) {
|
2017-12-07 20:47:26 +00:00
|
|
|
// callback takes precedence
|
|
|
|
// caller sets item to 'selected'
|
|
|
|
let cb = this.get('onSelect');
|
|
|
|
if (cb !== null) {
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onSelect');
|
|
|
|
cb(item);
|
2017-12-07 20:47:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no callback, we mark item as selected
|
2017-11-22 16:28:17 +00:00
|
|
|
if (this.get('singleSelect')) {
|
|
|
|
let items = this.get('items');
|
|
|
|
items.forEach(item => {
|
|
|
|
set(item, 'selected', false);
|
|
|
|
});
|
|
|
|
this.set('items', items);
|
|
|
|
}
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
set(item, 'selected', !item.get('selected'));
|
2017-09-21 15:48:00 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
});
|