open-vault/ui/app/components/linked-block.js

37 lines
924 B
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import Component from '@ember/component';
2018-04-03 14:16:57 +00:00
import hbs from 'htmlbars-inline-precompile';
let LinkedBlockComponent = Component.extend({
router: service(),
2018-04-03 14:16:57 +00:00
layout: hbs`{{yield}}`,
classNames: 'linked-block',
queryParams: null,
click(event) {
const $target = this.$(event.target);
const isAnchorOrButton =
$target.is('a') ||
$target.is('button') ||
$target.closest('button', event.currentTarget).length > 0 ||
$target.closest('a', event.currentTarget).length > 0;
if (!isAnchorOrButton) {
const params = this.get('params');
const queryParams = this.get('queryParams');
if (queryParams) {
params.push({ queryParams });
}
this.get('router').transitionTo(...params);
2018-04-03 14:16:57 +00:00
}
},
});
LinkedBlockComponent.reopenClass({
positionalParams: 'params',
});
export default LinkedBlockComponent;