aboutsummaryrefslogtreecommitdiff
path: root/src/fields/ImageField.ts
blob: ef616b2adf4f92f1f6056bd31d9fca98d8411f1c (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
import { BasicField } from "./BasicField";
import { Field, FieldId } from "./Field";
import { Types } from "../server/Message";

export class ImageField extends BasicField<URL> {
    constructor(data: URL | undefined = undefined, id?: FieldId, save: boolean = true) {
        super(data === undefined ? new URL("http://cs.brown.edu/~bcz/bob_fettucine.jpg") : data, save, id);
    }

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

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

    Copy(): Field {
        return new ImageField(this.Data);
    }

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