2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-22 12:08:29 +00:00
|
|
|
/*eslint ember/closure-actions: "warn"*/
|
2019-12-17 18:47:37 +00:00
|
|
|
import Component from '@ember/component';
|
2020-01-22 12:08:29 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2019-12-17 18:47:37 +00:00
|
|
|
import Slotted from 'block-slots';
|
2020-06-09 10:10:14 +00:00
|
|
|
import { set } from '@ember/object';
|
2019-12-17 18:47:37 +00:00
|
|
|
|
|
|
|
export default Component.extend(Slotted, {
|
|
|
|
tagName: '',
|
2020-01-22 12:08:29 +00:00
|
|
|
dom: service('dom'),
|
|
|
|
expanded: false,
|
|
|
|
keyboardAccess: true,
|
2022-09-15 08:43:17 +00:00
|
|
|
onchange: function () {},
|
2020-02-18 16:44:15 +00:00
|
|
|
// TODO: this needs to be made dynamic/auto detect
|
|
|
|
// for now use this to set left/right explicitly
|
|
|
|
position: '',
|
2022-09-15 08:43:17 +00:00
|
|
|
init: function () {
|
2020-01-22 12:08:29 +00:00
|
|
|
this._super(...arguments);
|
|
|
|
this.guid = this.dom.guid(this);
|
2020-06-23 09:12:04 +00:00
|
|
|
this.submenus = [];
|
2020-01-22 12:08:29 +00:00
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
willRender: function () {
|
2020-06-09 10:10:14 +00:00
|
|
|
set(this, 'hasHeader', this._isRegistered('header'));
|
|
|
|
},
|
2020-01-22 12:08:29 +00:00
|
|
|
actions: {
|
2022-09-15 08:43:17 +00:00
|
|
|
addSubmenu: function (name) {
|
2020-06-23 09:12:04 +00:00
|
|
|
set(this, 'submenus', this.submenus.concat(name));
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
removeSubmenu: function (name) {
|
2020-06-23 09:12:04 +00:00
|
|
|
const pos = this.submenus.indexOf(name);
|
|
|
|
if (pos !== -1) {
|
|
|
|
this.submenus.splice(pos, 1);
|
|
|
|
set(this, 'submenus', this.submenus);
|
|
|
|
}
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
change: function (e) {
|
2020-01-22 12:08:29 +00:00
|
|
|
if (!e.target.checked) {
|
2022-09-15 08:43:17 +00:00
|
|
|
[...this.dom.elements(`[id^=popover-menu-${this.guid}]`)].forEach(function ($item) {
|
2020-01-22 12:08:29 +00:00
|
|
|
$item.checked = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.onchange(e);
|
|
|
|
},
|
|
|
|
// Temporary send here so we can send route actions
|
|
|
|
// easily. It kind of makes sense that you'll want to perform
|
|
|
|
// route actions from a popup menu for the moment
|
2022-09-15 08:43:17 +00:00
|
|
|
send: function () {
|
2020-01-22 12:08:29 +00:00
|
|
|
this.sendAction(...arguments);
|
|
|
|
},
|
|
|
|
},
|
2019-12-17 18:47:37 +00:00
|
|
|
});
|