import {LitElement, html} from './lit-all.min.js'; import * as tfrpc from '/static/tfrpc.js'; class TfCollectionElement extends LitElement { static get properties() { return { whoami: {type: String}, category: {type: String}, collection: {type: Object}, selected_id: {type: String}, is_creating: {type: Boolean}, is_renaming: {type: Boolean}, }; } on_create(event) { let name = this.shadowRoot.getElementById('create_name').value; this.dispatchEvent( new CustomEvent('create', { bubbles: true, detail: { name: name, }, }) ); this.is_creating = false; } on_rename(event) { let id = this.shadowRoot.getElementById('select').value; let name = this.shadowRoot.getElementById('rename_name').value; this.dispatchEvent( new CustomEvent('rename', { bubbles: true, detail: { id: id, value: this.collection[id], name: name, }, }) ); this.is_renaming = false; } on_tombstone(event) { let id = this.shadowRoot.getElementById('select').value; if ( confirm(`Are you sure you want to delete '${this.collection[id].name}'?`) ) { this.dispatchEvent( new CustomEvent('tombstone', { bubbles: true, detail: { id: id, value: this.collection[id], }, }) ); } } on_selected(event) { let id = event.srcElement.value; this.selected_id = id != '' ? id : undefined; this.dispatchEvent( new CustomEvent('change', { bubbles: true, detail: { id: id, value: this.collection[id], }, }) ); } render() { let self = this; return html` `; } } customElements.define('tf-collection', TfCollectionElement);