window.angular && (function(angular) { 'use strict'; /** * * tableToolbar Component * * To use: * The component expects an 'actions' attribute * that should be an array of action objects. * Each action object should have 'type', 'label', and 'file' * properties. * * actions: [ * {type: 'Edit', label: 'Edit', file: 'icon-edit.svg'}, * {type: 'Delete', label: 'Edit', file: 'icon-trashcan.svg'} * ] * * The 'type' property is a string value that will be emitted to the * parent component when clicked. * * The 'label' property is a string value that will render as text in * the button * * The 'file' property is a string value of the filename of the svg icon * to provide directive. * */ const controller = function() { /** * Set defaults if properties undefined * @param {[]} actions */ const setActions = (actions = []) => { return actions .map((action) => { if (action.type === undefined) { return; } if (action.file === undefined) { action.file = null; } return action; }) .filter((action) => action); }; /** * Callback when button action clicked * Emits the action type to the parent component */ this.onClick = (action) => { this.emitAction({action}); }; this.onClickClose = () => { this.emitClose(); }; /** * onInit Component lifecycle hook */ this.$onInit = () => { this.actions = setActions(this.actions); }; }; /** * Component template */ const template = `

{{$ctrl.selectionCount}} selected

` /** * Register tableToolbar component */ angular.module('app.common.components').component('tableToolbar', { controller, template, bindings: { actions: '<', selectionCount: '<', active: '<', emitAction: '&', emitClose: '&' } }) })(window.angular);