DrawioFilePuller.js
1.28 KB
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
42
43
44
45
46
47
48
49
50
51
52
DrawioFilePuller = function(file, sync)
{
    this.file = file;
    this.sync = sync;
};
DrawioFilePuller.prototype.start = function(pullingInterval)
{
    var updateStatus = mxUtils.bind(this, function()
    {
        this.sync.lastModified = this.file.getLastModifiedDate();
        this.sync.updateStatus();
    });
    this.intId = setInterval(mxUtils.bind(this, function()
    {
        this.file.getLatestVersionId(mxUtils.bind(this, function(latestVersionId)
        {
            if (latestVersionId != this.file.getCurrentRevisionId())
            {
                this.file.getLatestVersion(mxUtils.bind(this, function(latestFile)
                {
                    this.file.mergeFile(latestFile, updateStatus);
                }), mxUtils.bind(this, function()
                {
                    // TODO Error handling
                }));
            }
            else
            {
                updateStatus();
            }
        }), mxUtils.bind(this, function()
        {
            // TODO Error handling
        }));
    }), pullingInterval);
    this._isConnected = true;
};
DrawioFilePuller.prototype.stop = function()
{
    clearInterval(this.intId);
    this._isConnected = false;
};
DrawioFilePuller.prototype.isConnected = function()
{
    return this._isConnected;
};