import { ContentPage, PopupWindowPage } from "@web-atoms/web-controls/dist/mobile-app/MobileApp.js"; import { DnsZoneRecord, DnsZoneRecordTypeArray, IDnsZone, IDnsZoneRecord } from "../../../../model/model.js"; import XNode from "@web-atoms/core/dist/core/XNode.js"; import Form from "@web-atoms/web-controls/dist/basic/Form.js"; import FormField from "@web-atoms/web-controls/dist/basic/FormField.js"; import ComboBox from "@web-atoms/web-controls/dist/basic/ComboBox.js"; import Bind from "@web-atoms/core/dist/core/Bind.js"; import Action from "@web-atoms/core/dist/view-model/Action.js"; export default class DnsRecordEditorPage extends PopupWindowPage<{ model?: IDnsZoneRecord, zone?: IDnsZone }, IDnsZoneRecord> { model: IDnsZoneRecord; zone: IDnsZone; async init() { this.title = this.parameters?.model ? "Edit Record" : "Add New Record"; const zone = this.zone = this.parameters?.zone; this.model ??= this.parameters?.model ?? DnsZoneRecord.create({ ttl: 600, type: "A", name: "@", zoneID: zone?.zoneID }); this.renderer =
this.model.type)}/> this.model.name ? "" : "Name is required")}> this.model.name)}/> this.model.ttl)}/> this.model.value ? "" : "Value is required")}> this.model.value)}/>
; } @Action({ onEvent: "save-record", close: true }) async saveRecord() { const { zone , model: { name, type, value, recordID } } = this; const records: IDnsZoneRecord[] = zone.records ??= []; if(records.find((x) => x.type === type && x.name === name && x.value === value && recordID && x.recordID !== recordID)) { throw new Error(`${name} ${type} ${value} already exists.`); } return this.model; } }