UNPKG

@jinntec/fore

Version:

Fore - declarative user interfaces in plain HTML

62 lines (58 loc) 1.79 kB
import { AbstractAction } from './abstract-action.js'; import { Fore } from '../fore.js'; import { resolveId } from '../xpath-evaluation.js'; import { XPathUtil } from '../xpath-util.js'; /** * `fx-refresh` * * Calls refresh() on fx-form * */ class FxRefresh extends AbstractAction { async perform() { this.dispatchEvent( new CustomEvent('execute-action', { composed: true, bubbles: true, cancelable: true, detail: { action: this, event: this.event }, }), ); if (this.hasAttribute('self')) { console.log(`### <<<<< refresh() self ${this} >>>>>`); const control = XPathUtil.getClosest('fx-control, fx-output, fx-upload', this); if (control) { control.refresh(true); return; } } if (this.hasAttribute('force')) { console.log(`### <<<<< refresh() force ${this} >>>>>`); this.getOwnerForm().refresh(true); return; } if(this.hasAttribute('selector')){ const target = document.querySelector(this.getAttribute('selector')); if (target && Fore.isUiElement(target.nodeName) && typeof target.refresh === 'function') { target.refresh(true); } return; } if (this.hasAttribute('control')) { const targetId = this.getAttribute('control'); console.log(`### <<<<< refresh() control '${targetId}' >>>>>`); let ctrl = resolveId(targetId, this); if(!ctrl){ ctrl = document.querySelector(`#${targetId}`); } if (ctrl && Fore.isUiElement(ctrl.nodeName) && typeof ctrl.refresh === 'function') { ctrl.refresh(true); } return; } this.getOwnerForm().refresh(); } } if (!customElements.get('fx-refresh')) { window.customElements.define('fx-refresh', FxRefresh); }