Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/apps/system/js/call_forwarding.js
blob: ee46def1bbc25d95afbc605dd8114d7c51a15f8f (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
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

'use strict';

(function() {

  // Must be in sync with nsIDOMMozMobileCFInfo interface.
  var _cfReason = {
    CALL_FORWARD_REASON_UNCONDITIONAL: 0,
    CALL_FORWARD_REASON_MOBILE_BUSY: 1,
    CALL_FORWARD_REASON_NO_REPLY: 2,
    CALL_FORWARD_REASON_NOT_REACHABLE: 3
  };
  var _cfAction = {
    CALL_FORWARD_ACTION_DISABLE: 0,
    CALL_FORWARD_ACTION_ENABLE: 1,
    CALL_FORWARD_ACTION_QUERY_STATUS: 2,
    CALL_FORWARD_ACTION_REGISTRATION: 3,
    CALL_FORWARD_ACTION_ERASURE: 4
  };

  var settings = window.navigator.mozSettings;
  if (!settings) {
    return;
  }
  var mobileconnection = window.navigator.mozMobileConnection;
  if (!mobileconnection) {
    return;
  }

  mobileconnection.addEventListener('cfstatechange', function(event) {
    if (event &&
        event.reason == _cfReason.CALL_FORWARD_REASON_UNCONDITIONAL) {
      var enabled = false;
      if (event.success &&
          (event.action == _cfAction.CALL_FORWARD_ACTION_REGISTRATION ||
           event.action == _cfAction.CALL_FORWARD_ACTION_ENABLE)) {
        enabled = true;
      }
      settings.createLock().set({'ril.cf.enabled': enabled});
    }
  });

})();