Adrià Vilanova MartÃnez | 8803b6c | 2022-10-17 00:36:38 +0200 | [diff] [blame] | 1 | import '@material/mwc-dialog/mwc-dialog.js'; |
| 2 | import '@material/web/button/text-button.js'; |
| 3 | import '@material/web/button/filled-button.js'; |
| 4 | import './WorkflowEditor.js'; |
| 5 | |
| 6 | import {css, html, LitElement} from 'lit'; |
| 7 | import {createRef, ref} from 'lit/directives/ref.js'; |
| 8 | |
| 9 | import * as pb from '../../proto/main_pb.js'; |
| 10 | |
| 11 | export default class WFWorkflowDialog extends LitElement { |
| 12 | static properties = { |
| 13 | open: {type: Boolean}, |
| 14 | uuid: {type: String}, |
| 15 | workflow: {type: Object}, |
| 16 | }; |
| 17 | |
| 18 | static styles = css` |
| 19 | :host { |
| 20 | --mdc-dialog-content-ink-color: var(--mdc-theme-on-surface, #000); |
| 21 | } |
| 22 | `; |
| 23 | |
| 24 | workflowEditorRef = createRef(); |
| 25 | |
| 26 | constructor() { |
| 27 | super(); |
| 28 | this.open = false; |
| 29 | this.workflow = new pb.workflows.Workflow(); |
| 30 | } |
| 31 | |
| 32 | render() { |
| 33 | return html` |
| 34 | <mwc-dialog |
| 35 | ?open=${this.open} |
| 36 | @opening=${this._openingDialog} |
| 37 | @closing=${this._closingDialog}> |
| 38 | <wf-workflow-editor ${ref(this.workflowEditorRef)} |
| 39 | .workflow=${this.workflow}> |
| 40 | </wf-workflow-editor> |
| 41 | <md-filled-button |
| 42 | slot="primaryAction" |
| 43 | label="Save" |
| 44 | @click=${this._save}> |
| 45 | </md-filled-button> |
| 46 | <md-text-button |
| 47 | slot="secondaryAction" |
| 48 | dialogAction="cancel" |
| 49 | label="Cancel"> |
| 50 | </md-text-button> |
| 51 | </mwc-dialog> |
| 52 | `; |
| 53 | } |
| 54 | |
| 55 | _openingDialog() { |
| 56 | this.open = true; |
| 57 | } |
| 58 | |
| 59 | _closingDialog() { |
| 60 | this.open = false; |
| 61 | } |
| 62 | |
| 63 | _save() { |
| 64 | const success = this.workflowEditorRef.value.save(this.uuid); |
| 65 | if (success) this.open = false; |
| 66 | } |
| 67 | } |
| 68 | window.customElements.define('wf-workflow-dialog', WFWorkflowDialog); |