aboutsummaryrefslogtreecommitdiff
path: root/src/fields/KVPField.ts
blob: a7ecc07689045b5063928a4cb82f8d1f8b94a012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { BasicField } from "./BasicField"
import { FieldId } from "./Field";
import { Types } from "../server/Message";
import { Document } from "./Document"

export class KVPField extends BasicField<Document> {
    constructor(data: Document | undefined = undefined, id?: FieldId, save: boolean = true) {
        super(data == undefined ? new Document() : data, save, id);
    }

    toString(): string {
        return this.Data.Title;
    }

    ToScriptString(): string {
        return `new KVPField("${this.Data}")`;
    }

    Copy() {
        return new KVPField(this.Data);
    }

    ToJson(): { type: Types, data: Document, _id: string } {
        return {
            type: Types.Text,
            data: this.Data,
            _id: this.Id
        }
    }
}