diff --git a/src/pat/recurrence/README.md b/src/pat/recurrence/README.md index c926ec4f3..5bc964ae5 100644 --- a/src/pat/recurrence/README.md +++ b/src/pat/recurrence/README.md @@ -16,8 +16,54 @@ Show the recurrence widget. ## Example - +### Recurrence without additional start feature + + + + +```html + +``` + +### Recurrence with additional start feature + +Note: adding additional start dates is a feature of the specification but is +not supported by a number of external tools, like Google Calendar, Microsoft +Outlook or Gnome Calendar. +Therefore, this feature is disabled by default. +However, you can enable it with the `hasAdditionalDates` feature. + + + ```html - + ``` diff --git a/src/pat/recurrence/recurrence.js b/src/pat/recurrence/recurrence.js index 80b883ebc..6fe02ae21 100644 --- a/src/pat/recurrence/recurrence.js +++ b/src/pat/recurrence/recurrence.js @@ -739,7 +739,6 @@ const RecurrenceInput = function (conf, textarea) { } occurrenceDiv = element.find(".rioccurrences"); - occurrenceDiv.hide(); const year = startdate.getFullYear(); const month = startdate.getMonth() + 1; @@ -811,11 +810,11 @@ const RecurrenceInput = function (conf, textarea) { .find(".rioccurrences .action a.rdate") .on("click", occurrenceDelete); } - // Show the new div - occurrenceDiv.show(); }, - error: function (jqXHR, textStatus) { - alert(textStatus); + error: function () { + occurrenceDiv[0].innerHTML = ` +
${conf.localization.error_load_occurrences}
+ `; }, }); } @@ -1377,6 +1376,8 @@ export default Base.extend({ monthly: "Monthly", yearly: "Yearly", }, + + error_load_occurrences: "Cannot load the occurrences preview.", }, readOnly: false, @@ -1392,6 +1393,7 @@ export default Base.extend({ ributtonExtraClass: "", // INPUT CONFIGURATION + hasAdditionalDates: false, hasRepeatForeverButton: true, // JQUERY TEMPLATE NAMES diff --git a/src/pat/recurrence/recurrence.test.js b/src/pat/recurrence/recurrence.test.js index 521807dea..c227979ec 100644 --- a/src/pat/recurrence/recurrence.test.js +++ b/src/pat/recurrence/recurrence.test.js @@ -28,4 +28,71 @@ describe("Recurrence", function () { ).toEqual("none"); expect(document.querySelector("div.riform").style.display).toEqual("none"); }); + + it("Adds a warning, if the occurrences preview cannot be loaded.", async function () { + // Without any test mock server, the occurrences preview cannot be loaded. + document.body.innerHTML = ` + + + `; + + registry.scan(document.body); + await utils.timeout(1); + + const edit_btn = document.querySelector("[name=riedit]"); + edit_btn.click(); + + const occurrences_preview = document.querySelector( + ".rioccurrences .alert-warning", + ); + expect(occurrences_preview).toBeTruthy(); + expect(occurrences_preview.textContent.trim()).toBe( + "Cannot load the occurrences preview.", + ); + }); + + it("Initializes without the additional dates feature.", async function () { + document.body.innerHTML = ` + + + `; + + registry.scan(document.body); + await utils.timeout(1); + + const edit_btn = document.querySelector("[name=riedit]"); + edit_btn.click(); + + const add_occurrence = document.querySelector(".modal .riaddoccurrence"); + expect(add_occurrence).toBeFalsy(); + }); + + it("Initializes with the additional dates feature.", async function () { + document.body.innerHTML = ` + + + `; + + registry.scan(document.body); + await utils.timeout(1); + + const edit_btn = document.querySelector("[name=riedit]"); + edit_btn.click(); + + const add_occurrence = document.querySelector(".modal .riaddoccurrence"); + expect(add_occurrence).toBeTruthy(); + }); }); diff --git a/src/pat/recurrence/templates/form.xml b/src/pat/recurrence/templates/form.xml index d3db8cf9c..fe55aba56 100644 --- a/src/pat/recurrence/templates/form.xml +++ b/src/pat/recurrence/templates/form.xml @@ -291,6 +291,7 @@
+ <% if (hasAdditionalDates === true) { %>
<%= localization.addDate %>
@@ -299,6 +300,7 @@
+ <% } %>