summaryrefslogtreecommitdiff
path: root/client/js/models/note.js
blob: 87c8b3bbd1e7b9620306a8e51936da94c6a81325 (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
31
32
33
34
35
36
37
38
39
40
41
"use strict";

const events = require("../events.js");
const Point = require("./point.js");
const PointList = require("./point_list.js");

class Note extends events.EventTarget {
    constructor() {
        super();
        this._text = "…";
        this._polygon = new PointList();
    }

    get text() {
        return this._text;
    }

    get polygon() {
        return this._polygon;
    }

    set text(value) {
        this._text = value;
    }

    static fromResponse(response) {
        const note = new Note();
        note._updateFromResponse(response);
        return note;
    }

    _updateFromResponse(response) {
        this._text = response.text;
        this._polygon.clear();
        for (let point of response.polygon) {
            this._polygon.add(new Point(point[0], point[1]));
        }
    }
}

module.exports = Note;