summaryrefslogtreecommitdiffstats
path: root/mailnews/extensions/mdn/content/am-mdn.js
blob: 4dd9e8d8d989db0bf7e878f5ea3d8267016fa101 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * 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 useCustomPrefs;
var requestReceipt;
var leaveInInbox;
var moveToSent;
var receiptSend;
var neverReturn;
var returnSome;
var notInToCcPref;
var notInToCcLabel;
var outsideDomainPref;
var outsideDomainLabel;
var otherCasesPref;
var otherCasesLabel;
var receiptArriveLabel;
var receiptRequestLabel;
var gIdentity;
var gIncomingServer;
var gMdnPrefBranch;

function onInit() 
{
  useCustomPrefs = document.getElementById("identity.use_custom_prefs");
  requestReceipt = document.getElementById("identity.request_return_receipt_on");
  leaveInInbox = document.getElementById("leave_in_inbox");
  moveToSent = document.getElementById("move_to_sent");
  receiptSend = document.getElementById("server.mdn_report_enabled");
  neverReturn = document.getElementById("never_return");
  returnSome = document.getElementById("return_some");
  notInToCcPref = document.getElementById("server.mdn_not_in_to_cc");
  notInToCcLabel = document.getElementById("notInToCcLabel");
  outsideDomainPref = document.getElementById("server.mdn_outside_domain");
  outsideDomainLabel = document.getElementById("outsideDomainLabel");
  otherCasesPref = document.getElementById("server.mdn_other");
  otherCasesLabel = document.getElementById("otherCasesLabel");
  receiptArriveLabel = document.getElementById("receiptArriveLabel");
  receiptRequestLabel = document.getElementById("receiptRequestLabel");
  
  EnableDisableCustomSettings();
        
  return true;
}

function onSave()
{

}

function EnableDisableCustomSettings() {
  if (useCustomPrefs && (useCustomPrefs.getAttribute("value") == "false")) {
    requestReceipt.setAttribute("disabled", "true");
    leaveInInbox.setAttribute("disabled", "true");
    moveToSent.setAttribute("disabled", "true");
    neverReturn.setAttribute("disabled", "true");
    returnSome.setAttribute("disabled", "true");
    receiptArriveLabel.setAttribute("disabled", "true");
    receiptRequestLabel.setAttribute("disabled", "true");
  }
  else {
    requestReceipt.removeAttribute("disabled");
    leaveInInbox.removeAttribute("disabled");
    moveToSent.removeAttribute("disabled");
    neverReturn.removeAttribute("disabled");
    returnSome.removeAttribute("disabled");
    receiptArriveLabel.removeAttribute("disabled");
    receiptRequestLabel.removeAttribute("disabled");
  }
  EnableDisableAllowedReceipts();
  // Lock id based prefs
  onLockPreference("mail.identity", gIdentity.key);
  // Lock server based prefs
  onLockPreference("mail.server", gIncomingServer.key);
  return true;
}

function EnableDisableAllowedReceipts() {
  if (receiptSend) {
    if (!neverReturn.getAttribute("disabled") && (receiptSend.getAttribute("value") != "false")) {
      notInToCcPref.removeAttribute("disabled");
      notInToCcLabel.removeAttribute("disabled");
      outsideDomainPref.removeAttribute("disabled");
      outsideDomainLabel.removeAttribute("disabled");
      otherCasesPref.removeAttribute("disabled");
      otherCasesLabel.removeAttribute("disabled");
    }
    else {
      notInToCcPref.setAttribute("disabled", "true");
      notInToCcLabel.setAttribute("disabled", "true");
      outsideDomainPref.setAttribute("disabled", "true");
      outsideDomainLabel.setAttribute("disabled", "true");
      otherCasesPref.setAttribute("disabled", "true");
      otherCasesLabel.setAttribute("disabled", "true");
    }
  }
  return true;
}

function onPreInit(account, accountValues)
{
  gIdentity = account.defaultIdentity;
  gIncomingServer = account.incomingServer;
}

// Disables xul elements that have associated preferences locked.
function onLockPreference(initPrefString, keyString)
{
    var finalPrefString; 

    var allPrefElements = [
      { prefstring:"request_return_receipt_on", id:"identity.request_return_receipt_on"},
      { prefstring:"select_custom_prefs", id:"identity.select_custom_prefs"},
      { prefstring:"select_global_prefs", id:"identity.select_global_prefs"},
      { prefstring:"incorporate_return_receipt", id:"server.incorporate_return_receipt"},
      { prefstring:"never_return", id:"never_return"},
      { prefstring:"return_some", id:"return_some"},
      { prefstring:"mdn_not_in_to_cc", id:"server.mdn_not_in_to_cc"},
      { prefstring:"mdn_outside_domain", id:"server.mdn_outside_domain"},
      { prefstring:"mdn_other", id:"server.mdn_other"},
    ];

    finalPrefString = initPrefString + "." + keyString + ".";
    gMdnPrefBranch = Services.prefs.getBranch(finalPrefString);

    disableIfLocked( allPrefElements );
} 

function disableIfLocked( prefstrArray )
{
  for (var i=0; i<prefstrArray.length; i++) {
    var id = prefstrArray[i].id;
    var element = document.getElementById(id);
    if (gMdnPrefBranch.prefIsLocked(prefstrArray[i].prefstring)) {
      if (id == "server.incorporate_return_receipt")
      {
        document.getElementById("leave_in_inbox").setAttribute("disabled", "true");
        document.getElementById("move_to_sent").setAttribute("disabled", "true");
      }
      else
        element.setAttribute("disabled", "true");
    }
  }
}

/**
 * Opens Preferences (Options) dialog on the pane and tab where
 * the global receipts settings can be found.
 */
function showGlobalReceipts() {
  openPrefsFromAccountManager("paneAdvanced", "generalTab",
                              {subdialog: "showReturnReceipts"}, "receipts_pane");
}