summaryrefslogtreecommitdiffstats
path: root/comm/calendar/providers/storage/CalStorageOfflineModel.jsm
blob: 23f6cd5330eaf73552e205af97b0985c841c8ed2 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var EXPORTED_SYMBOLS = ["CalStorageOfflineModel"];

var { CalStorageModelBase } = ChromeUtils.import(
  "resource:///modules/calendar/CalStorageModelBase.jsm"
);

/**
 * CalStorageOfflineModel provides methods for manipulating the offline flags
 * of items.
 */
class CalStorageOfflineModel extends CalStorageModelBase {
  /**
   * Returns the offline_journal column value for an item.
   *
   * @param {calIItemBase} item
   *
   * @returns {number}
   */
  async getItemOfflineFlag(item) {
    let flag = null;
    let query = item.isEvent() ? this.statements.mSelectEvent : this.statements.mSelectTodo;
    this.db.prepareStatement(query);
    query.params.id = item.id;
    await this.db.executeAsync(query, row => {
      flag = row.getResultByName("offline_journal") || null;
    });
    return flag;
  }

  /**
   * Sets the offline_journal column value for an item.
   *
   * @param {calIItemBase} item
   * @param {number} flag
   */
  async setOfflineJournalFlag(item, flag) {
    let id = item.id;
    let query = item.isEvent()
      ? this.statements.mEditEventOfflineFlag
      : this.statements.mEditTodoOfflineFlag;
    this.db.prepareStatement(query);
    query.params.id = id;
    query.params.offline_journal = flag || null;
    try {
      await this.db.executeAsync(query);
    } catch (e) {
      this.db.logError("Error setting offline journal flag for " + item.title, e);
    }
  }
}