Bug 1299610 - Enable enforcing of email based scheduling if caldav servers advertise auto-scheduling capability - UI part. r=philipp
authormakemyday@gmx-topmail.de
Sat, 09 Dec 2017 12:48:29 +0100
changeset 29747 87048847b0a3394a17eb395d3e6546488996733c
parent 29746 bc64c9f2d5258de10f5b7575f64bd78eba955cd3
child 29748 e68975aea49460e776227f3cbef28ef020806a4a
push id2108
push userclokep@gmail.com
push dateMon, 22 Jan 2018 17:53:55 +0000
treeherdercomm-beta@c44930d8ad9b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1299610
Bug 1299610 - Enable enforcing of email based scheduling if caldav servers advertise auto-scheduling capability - UI part. r=philipp
calendar/lightning/content/lightning-calendar-creation.js
calendar/lightning/content/lightning-calendar-creation.xul
calendar/lightning/content/lightning-calendar-properties.js
calendar/lightning/content/lightning-calendar-properties.xul
calendar/lightning/content/lightning-utils.js
calendar/lightning/jar.mn
calendar/locales/en-US/chrome/lightning/lightning.dtd
calendar/locales/en-US/chrome/lightning/lightning.properties
calendar/providers/caldav/content/caldav-lightning-calendar-creation.js
calendar/providers/caldav/content/caldav-lightning-calendar-creation.xul
calendar/providers/caldav/content/caldav-lightning-calendar-properties.js
calendar/providers/caldav/content/caldav-lightning-calendar-properties.xul
calendar/providers/caldav/content/caldav-lightning-utils.js
--- a/calendar/lightning/content/lightning-calendar-creation.js
+++ b/calendar/lightning/content/lightning-calendar-creation.js
@@ -1,17 +1,24 @@
 /* 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/. */
 
+/* exported onChangeIdentity */
+
 var common_initCustomizePage = initCustomizePage;
 var common_doCreateCalendar = doCreateCalendar;
 
 initCustomizePage = function() {
     common_initCustomizePage();
     ltnInitMailIdentitiesRow();
+    ltnNotifyOnIdentitySelection();
 };
 
 doCreateCalendar = function() {
     common_doCreateCalendar();
     ltnSaveMailIdentitySelection();
     return true;
 };
+
+function onChangeIdentity(aEvent) {
+    ltnNotifyOnIdentitySelection();
+}
--- a/calendar/lightning/content/lightning-calendar-creation.xul
+++ b/calendar/lightning/content/lightning-calendar-creation.xul
@@ -12,19 +12,23 @@
   <script type="application/javascript"
           src="chrome://calendar/content/calendar-ui-utils.js"/>
   <script type="application/javascript"
           src="chrome://lightning/content/lightning-utils.js"/>
   <script type="application/javascript"
           src="chrome://lightning/content/lightning-calendar-creation.js"/>
 
   <rows id="customize-rows">
+    <notificationbox id="no-identity-notification"
+                     flex="1"
+                     insertafter="customize-suppressAlarms-row" />
     <row id="calendar-email-identity-row"
          align="center"
-         insertafter="customize-suppressAlarms-row">
+         insertafter="no-identity-notification">
       <label value="&lightning.calendarproperties.email.label;"
              control="email-identity-menulist"/>
-      <menulist id="email-identity-menulist">
+      <menulist id="email-identity-menulist"
+                oncommand="onChangeIdentity(event)">
         <menupopup id="email-identity-menupopup"/>
       </menulist>
     </row>
   </rows>
 </overlay>
--- a/calendar/lightning/content/lightning-calendar-properties.js
+++ b/calendar/lightning/content/lightning-calendar-properties.js
@@ -1,17 +1,25 @@
 /* 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/. */
 
+/* exported onChangeIdentity */
+
 var common_onLoad = onLoad;
 var common_onAcceptDialog = onAcceptDialog;
 
 onLoad = function() {
     gCalendar = window.arguments[0].calendar;
     ltnInitMailIdentitiesRow();
+    ltnNotifyOnIdentitySelection();
     common_onLoad();
 };
 
 onAcceptDialog = function() {
     ltnSaveMailIdentitySelection();
     return common_onAcceptDialog();
 };
+
+function onChangeIdentity(aEvent) {
+    ltnNotifyOnIdentitySelection();
+    sizeToContent();
+}
--- a/calendar/lightning/content/lightning-calendar-properties.xul
+++ b/calendar/lightning/content/lightning-calendar-properties.xul
@@ -12,21 +12,25 @@
   <script type="application/javascript"
           src="chrome://calendar/content/calendar-ui-utils.js"/>
   <script type="application/javascript"
           src="chrome://lightning/content/lightning-utils.js"/>
   <script type="application/javascript"
           src="chrome://lightning/content/lightning-calendar-properties.js"/>
 
   <rows id="calendar-properties-rows">
+    <notificationbox id="no-identity-notification"
+                     flex="1"
+                     insertafter="calendar-uri-row" />
     <row id="calendar-email-identity-row"
          align="center"
-         insertafter="calendar-uri-row">
+         insertafter="no-identity-notification">
       <label value="&lightning.calendarproperties.email.label;"
              control="email-identity-menulist"
              disable-with-calendar="true"/>
       <menulist id="email-identity-menulist"
-                disable-with-calendar="true">
+                disable-with-calendar="true"
+                oncommand="onChangeIdentity(event)">
         <menupopup id="email-identity-menupopup"/>
       </menulist>
     </row>
   </rows>
 </overlay>
--- a/calendar/lightning/content/lightning-utils.js
+++ b/calendar/lightning/content/lightning-utils.js
@@ -1,31 +1,39 @@
 /* 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/. */
 
-/* exported ltnInitMailIdentitiesRow, ltnSaveMailIdentitySelection */
+/* exported ltnGetString, ltnInitMailIdentitiesRow,
+ *          ltnGetMailIdentitySelection, ltnSaveMailIdentitySelection,
+ *          ltnNotifyOnIdentitySelection
+ */
 
 Components.utils.import("resource:///modules/iteratorUtils.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
+Components.utils.import("resource://calendar/modules/ltnUtils.jsm");
 
 /**
- * Gets the value of a string in a .properties file from the lightning bundle
+ * Gets a localized string in a .properties file from the lightning bundle
  *
- * @param aBundleName  the name of the properties file.  It is assumed that the
- *                     file lives in chrome://lightning/locale/
- * @param aStringName  the name of the string within the properties file
- * @param aParams      optional array of parameters to format the string
+ * @param   {String}  aBundleName  the name of the properties file.  It is assumed
+ *                                 that the file lives in chrome://lightning/locale/
+ * @param   {String}  aStringName  the name of the string within the properties file
+ * @param   {Array}   aParams      optional array of parameters to format the string
+ * @returns {String}               the localized string
  */
 function ltnGetString(aBundleName, aStringName, aParams) {
     return cal.calGetString(aBundleName, aStringName, aParams, "lightning");
 }
 
-// shared by lightning-calendar-properties.js and lightning-calendar-creation.js:
+/**
+ * Initializing the email identity row
+ * (shared between calendar creation wizard and properties dialog)
+ */
 function ltnInitMailIdentitiesRow() {
     if (!gCalendar) {
         collapseElement("calendar-email-identity-row");
     }
 
     let imipIdentityDisabled = gCalendar.getProperty("imip.identity.disabled");
     setElementValue("calendar-email-identity-row",
                     imipIdentityDisabled && "true",
@@ -61,26 +69,63 @@ function ltnInitMailIdentitiesRow() {
     }
     try {
         let sel = gCalendar.getProperty("imip.identity");
         if (sel) {
             sel = sel.QueryInterface(Components.interfaces.nsIMsgIdentity);
         }
         menuListSelectItem("email-identity-menulist", sel ? sel.key : "none");
     } catch (exc) {
-        // Don't select anything if the message identity can't be found
+        // Don't select anything if the identity can't be found
     }
 }
 
-function ltnSaveMailIdentitySelection() {
-    if (!gCalendar) {
-        return;
-    }
+/**
+ * Providing the selected email identity
+ * (shared between calendar creation wizard and properties dialog)
+ *
+ * @returns {String}  the key of the selected nsIMsgIdentity or 'none'
+ */
+function ltnGetMailIdentitySelection() {
     let sel = "none";
-    let imipIdentityDisabled = gCalendar.getProperty("imip.identity.disabled");
-    let selItem = document.getElementById("email-identity-menulist").selectedItem;
-    if (!imipIdentityDisabled && selItem) {
-        sel = selItem.getAttribute("value");
+    if (gCalendar) {
+        let imipIdentityDisabled = gCalendar.getProperty("imip.identity.disabled");
+        let selItem = document.getElementById("email-identity-menulist").selectedItem;
+        if (!imipIdentityDisabled && selItem) {
+            sel = selItem.getAttribute("value");
+        }
+    }
+    return sel;
+}
+
+/**
+ * Persisting the selected email identity
+ * (shared between calendar creation wizard and properties dialog)
+ */
+function ltnSaveMailIdentitySelection() {
+    if (gCalendar) {
+        let sel = ltnGetMailIdentitySelection();
+        // no imip.identity.key will default to the default account/identity, whereas
+        // an empty key indicates no imip; that identity will not be found
+        gCalendar.setProperty("imip.identity.key", sel == "none" ? "" : sel);
     }
-    // no imip.identity.key will default to the default account/identity, whereas
-    // an empty key indicates no imip; that identity will not be found
-    gCalendar.setProperty("imip.identity.key", sel == "none" ? "" : sel);
 }
+
+/**
+ * Displays a warning if the user doesn't assign an email identity to a calendar
+ * (shared between calendar creation wizard and properties dialog)
+ */
+function ltnNotifyOnIdentitySelection() {
+    let notificationBox = document.getElementById("no-identity-notification");
+    let msg = ltn.getString("lightning", "noIdentitySelectedNotification");
+    let sel = ltnGetMailIdentitySelection();
+
+    if (sel == "none") {
+        notificationBox.appendNotification(
+            msg,
+            "noIdentitySelected",
+            null,
+            notificationBox.PRIORITY_WARNING_MEDIUM
+        );
+    } else {
+        notificationBox.removeAllNotifications();
+    }
+}
--- a/calendar/lightning/jar.mn
+++ b/calendar/lightning/jar.mn
@@ -28,16 +28,18 @@ lightning.jar:
 % overlay about:preferences chrome://calendar/content/preferences/views.xul
 % overlay chrome://lightning/content/messenger-overlay-sidebar.xul chrome://calendar/content/calendar-unifinder.xul
 % overlay chrome://lightning/content/messenger-overlay-sidebar.xul chrome://calendar/content/calendar-unifinder-todo.xul
 % overlay chrome://lightning/content/messenger-overlay-sidebar.xul chrome://calendar/content/calendar-task-view.xul
 % overlay chrome://lightning/content/messenger-overlay-sidebar.xul chrome://calendar/content/today-pane.xul
 % overlay chrome://lightning/content/messenger-overlay-sidebar.xul chrome://lightning/content/suite-overlay-sidebar.xul application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
 % overlay chrome://calendar/content/calendarCreation.xul chrome://lightning/content/lightning-calendar-creation.xul
 % overlay chrome://calendar/content/calendar-properties-dialog.xul chrome://lightning/content/lightning-calendar-properties.xul
+% overlay chrome://lightning/content/lightning-calendar-creation.xul chrome://lightning/content/caldav-lightning-calendar-creation.xul
+% overlay chrome://lightning/content/lightning-calendar-properties.xul chrome://lightning/content/caldav-lightning-calendar-properties.xul
 % override chrome://lightning/skin/accountCentral.css chrome://lightning-common/skin/suite-accountCentral.css application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
 % content lightning %content/lightning/
     content/lightning/imip-bar.js                          (content/imip-bar.js)
     content/lightning/imip-bar-overlay.xul                 (content/imip-bar-overlay.xul)
     content/lightning/lightning-calendar-creation.xul      (content/lightning-calendar-creation.xul)
     content/lightning/lightning-calendar-creation.js       (content/lightning-calendar-creation.js)
     content/lightning/lightning-calendar-properties.xul    (content/lightning-calendar-properties.xul)
     content/lightning/lightning-calendar-properties.js     (content/lightning-calendar-properties.js)
@@ -60,16 +62,22 @@ lightning.jar:
     content/lightning/suite-overlay-sidebar.xul            (content/suite-overlay-sidebar.xul)
     content/lightning/lightning-item-toolbar.xul           (content/lightning-item-toolbar.xul)
     content/lightning/lightning-item-panel.xul             (content/lightning-item-panel.xul)
     content/lightning/lightning-item-panel.js              (content/lightning-item-panel.js)
     content/lightning/lightning-item-iframe.xul            (content/lightning-item-iframe.xul)
     content/lightning/lightning-item-iframe.js             (content/lightning-item-iframe.js)
     content/lightning/html-item-editing/lightning-item-iframe.html      (content/html-item-editing/lightning-item-iframe.html)
     content/lightning/html-item-editing/react-code.js                   (content/html-item-editing/react-code.js)
+    content/lightning/caldav-lightning-calendar-creation.xul    (../providers/caldav/content/caldav-lightning-calendar-creation.xul)
+    content/lightning/caldav-lightning-calendar-creation.js     (../providers/caldav/content/caldav-lightning-calendar-creation.js)
+    content/lightning/caldav-lightning-calendar-properties.xul  (../providers/caldav/content/caldav-lightning-calendar-properties.xul)
+    content/lightning/caldav-lightning-calendar-properties.js   (../providers/caldav/content/caldav-lightning-calendar-properties.js)
+    content/lightning/caldav-lightning-utils.js                 (../providers/caldav/content/caldav-lightning-utils.js)
+
 % skin lightning classic/1.0 chrome/skin/linux/lightning/
 % skin lightning classic/1.0 chrome/skin/osx/lightning/ os=Darwin
 % skin lightning classic/1.0 chrome/skin/windows/lightning/ os=WINNT
 % skin lightning-common classic/1.0 chrome/skin/lightning-common/
 % style chrome://messenger/content/messageWindow.xul chrome://lightning/skin/lightning.css
 % style chrome://global/content/customizeToolbar.xul chrome://lightning/skin/lightning-toolbar.css
 % style chrome://calendar/content/calendar-event-dialog.xul chrome://communicator/skin/communicator.css application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
 % style chrome://global/content/customizeToolbar.xul chrome://lightning-common/skin/lightning.css application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
--- a/calendar/locales/en-US/chrome/lightning/lightning.dtd
+++ b/calendar/locales/en-US/chrome/lightning/lightning.dtd
@@ -32,17 +32,28 @@
 <!ENTITY lightning.menu.view.tasks.label               "Tasks">
 <!ENTITY lightning.menu.view.tasks.accesskey           "k">
 
 <!-- Events and Tasks menu -->
 <!ENTITY lightning.menu.eventtask.label                "Events and Tasks">
 <!ENTITY lightning.menu.eventtask.accesskey            "n">
 
 <!-- properties dialog, calendar creation wizard -->
-<!ENTITY lightning.calendarproperties.email.label               "E-Mail:">
+<!-- LOCALIZATON NOTE(lightning.calendarproperties.email.label,
+     lightning.calendarproperties.forceEmailScheduling.label)
+     These strings are used in the calendar wizard and the calendar properties dialog, but are only
+     displayed when setting/using a caldav calendar -->
+<!ENTITY lightning.calendarproperties.email.label                           "Email:">
+<!ENTITY lightning.calendarproperties.forceEmailScheduling.label            "Prefer client-side email scheduling">
+<!-- LOCALIZATON NOTE(lightning.calendarproperties.forceEmailScheduling.tooltiptext1,
+     lightning.calendarproperties.forceEmailScheduling.tooltiptext2)
+     - tooltiptext1 is used in the calendar wizard when setting a new caldav calendar
+     - tooltiptext2 is used in the calendar properties dialog for caldav calendars -->
+<!ENTITY lightning.calendarproperties.forceEmailScheduling.tooltiptext1     "For now, you can only enable this after setting up this calendar in its property dialog if the calendar server takes care of scheduling.">
+<!ENTITY lightning.calendarproperties.forceEmailScheduling.tooltiptext2     "This option is only available if the calendar server handles scheduling. Enabling will allow to fall back to the standard email based scheduling instead of leaving it to the server.">
 
 <!-- iMIP Bar (meeting support) -->
 <!ENTITY lightning.imipbar.btnAccept.label                                  "Accept">
 <!ENTITY lightning.imipbar.btnAccept2.tooltiptext                           "Accept event invitation">
 <!ENTITY lightning.imipbar.btnAcceptRecurrences.label                       "Accept all">
 <!ENTITY lightning.imipbar.btnAcceptRecurrences2.tooltiptext                "Accept event invitation for all occurrences of the event">
 <!ENTITY lightning.imipbar.btnAdd.label                                     "Add">
 <!ENTITY lightning.imipbar.btnAdd.tooltiptext                               "Add the event to the calendar">
--- a/calendar/locales/en-US/chrome/lightning/lightning.properties
+++ b/calendar/locales/en-US/chrome/lightning/lightning.properties
@@ -208,8 +208,11 @@ integrationKeepItAccessKey=K
 # clear if we will be completely uninstalling Lightning or disabling it. Please
 # translate this string in a general manner, so that it makes sense for both
 # options.
 integrationRestartLabel=%1$S will be removed the next time you restart %2$S. You can add it again at any time using the Add-ons Manager.
 integrationRestartButton=Restart now
 integrationRestartAccessKey=R
 integrationUndoButton=Undo
 integrationUndoAccessKey=U
+
+# LOCALIZATION NOTE(noIdentitySelectedNotification):
+noIdentitySelectedNotification=If you want to use this calendar to store invitations to or from other people you should assign an email identity below.
new file mode 100644
--- /dev/null
+++ b/calendar/providers/caldav/content/caldav-lightning-calendar-creation.js
@@ -0,0 +1,23 @@
+/* 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 ltn_initCustomizePage = initCustomizePage;
+var ltn_doCreateCalendar = doCreateCalendar;
+var ltn_onChangeIdentity = onChangeIdentity;
+
+initCustomizePage = function() {
+    ltn_initCustomizePage();
+    caldavInitForceEmailScheduling();
+};
+
+doCreateCalendar = function() {
+    ltn_doCreateCalendar();
+    caldavSaveForceEmailScheduling();
+    return true;
+};
+
+onChangeIdentity = function(aEvent) {
+    ltn_onChangeIdentity();
+    caldavUpdateForceEmailSchedulingControl();
+};
new file mode 100644
--- /dev/null
+++ b/calendar/providers/caldav/content/caldav-lightning-calendar-creation.xul
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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/. -->
+
+<!DOCTYPE overlay SYSTEM "chrome://lightning/locale/lightning.dtd">
+
+<overlay id="ltnCalendarCreationOverlay"
+         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+  <script type="application/javascript"
+          src="chrome://lightning/content/caldav-lightning-utils.js"/>
+  <script type="application/javascript"
+          src="chrome://lightning/content/caldav-lightning-calendar-creation.js"/>
+
+  <rows id="customize-rows">
+    <row id="calendar-force-email-scheduling-row"
+         align="center"
+         insertafter="calendar-email-identity-row">
+      <spacer/>
+      <!-- The capability to enforce email scheduling wouldn't be enabled in the calendar wizard
+           atm because we would have to check the server capabilities with an OPTIONS request to
+           find out whether this server advertises server-side scheduling. We would need to rework
+           the wizard for that - fixing bug 306495 would probably prepare this. So for now, we just
+           let the user that he can enable this subsequently if applicable -->
+      <checkbox id="force-email-scheduling"
+                label="&lightning.calendarproperties.forceEmailScheduling.label;"
+                disable-with-calendar="true"
+                tooltiptext="&lightning.calendarproperties.forceEmailScheduling.tooltiptext1;"/>
+    </row>
+  </rows>
+</overlay>
new file mode 100644
--- /dev/null
+++ b/calendar/providers/caldav/content/caldav-lightning-calendar-properties.js
@@ -0,0 +1,23 @@
+/* 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 ltn_onChangeIdentity = onChangeIdentity;
+
+onLoad = function() {
+    gCalendar = window.arguments[0].calendar;
+    ltnInitMailIdentitiesRow();
+    caldavInitForceEmailScheduling();
+    common_onLoad();
+};
+
+onAcceptDialog = function() {
+    ltnSaveMailIdentitySelection();
+    caldavSaveForceEmailScheduling();
+    return common_onAcceptDialog();
+};
+
+onChangeIdentity = function(aEvent) {
+    ltn_onChangeIdentity();
+    caldavUpdateForceEmailSchedulingControl();
+};
new file mode 100644
--- /dev/null
+++ b/calendar/providers/caldav/content/caldav-lightning-calendar-properties.xul
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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/. -->
+
+<!DOCTYPE overlay SYSTEM "chrome://lightning/locale/lightning.dtd">
+
+<overlay id="ltnCalendarPropertiesOverlay"
+         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+  <script type="application/javascript"
+          src="chrome://lightning/content/caldav-lightning-utils.js"/>
+  <script type="application/javascript"
+          src="chrome://lightning/content/caldav-lightning-calendar-properties.js"/>
+
+  <rows id="calendar-properties-rows">
+    <row id="calendar-force-email-scheduling-row"
+         align="center"
+         insertafter="calendar-email-identity-row">
+      <spacer/>
+      <checkbox id="force-email-scheduling"
+                label="&lightning.calendarproperties.forceEmailScheduling.label;"
+                disable-with-calendar="true"
+                tooltiptext="&lightning.calendarproperties.forceEmailScheduling.tooltiptext2;"/>
+    </row>
+  </rows>
+</overlay>
new file mode 100644
--- /dev/null
+++ b/calendar/providers/caldav/content/caldav-lightning-utils.js
@@ -0,0 +1,65 @@
+/* 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/. */
+
+/* exported caldavInitForceEmailScheduling, caldavSaveForceEmailScheduling,
+ *          caldavUpdateForceEmailSchedulingControl
+ */
+
+Components.utils.import("resource://calendar/modules/calUtils.jsm");
+
+/**
+ * Initializing calendar creation wizard and properties dialog to display the
+ * option to enforce email scheduling for outgoing scheduling operations
+ * (shared between calendar creation wizard and properties dialog)
+ */
+function caldavInitForceEmailScheduling() {
+    if (gCalendar && gCalendar.type == "caldav") {
+        let checkbox = document.getElementById("force-email-scheduling");
+        let curStatus = checkbox.getAttribute("checked") == "true";
+        let newStatus = gCalendar.getProperty("forceEmailScheduling") ||
+                        curStatus;
+        if (curStatus != newStatus) {
+            if (newStatus) {
+                checkbox.setAttribute("checked", "true");
+            } else {
+                checkbox.removeAttribute("checked");
+            }
+        }
+        caldavUpdateForceEmailSchedulingControl();
+    } else {
+        collapseElement("calendar-force-email-scheduling-row");
+    }
+}
+
+/**
+ * Persisting the calendar property to enforce email scheduling
+ * (shared between calendar creation wizard and properties dialog)
+ */
+function caldavSaveForceEmailScheduling() {
+    if (gCalendar && gCalendar.type == "caldav") {
+        let checkbox = document.getElementById("force-email-scheduling");
+        if (checkbox && checkbox.getAttribute("disable-capability") != "true") {
+            let status = checkbox.getAttribute("checked") == "true";
+            gCalendar.setProperty("forceEmailScheduling", status);
+        }
+    }
+}
+
+/**
+ * Updates the forceEmailScheduling control based on the currently assigned
+ * email identity to this calendar
+ * (shared between calendar creation wizard and properties dialog)
+ */
+function caldavUpdateForceEmailSchedulingControl() {
+    let checkbox = document.getElementById("force-email-scheduling");
+    if (gCalendar &&
+        gCalendar.getProperty("capabilities.autoschedule.supported") &&
+        ltnGetMailIdentitySelection() != "none") {
+        checkbox.removeAttribute("disable-capability");
+        checkbox.removeAttribute("disabled");
+    } else {
+        checkbox.setAttribute("disable-capability", "true");
+        checkbox.setAttribute("disabled", "true");
+    }
+}