diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-08 11:58:36 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-08 11:58:36 +0200 |
| commit | 618aca78a5574de3d5f5f275c73d33a5cdcb9df8 (patch) | |
| tree | 40456f2d06286dd7acec7173f540900eda132b4a | |
| parent | 971cbc3f0087f288fec9ae0320bb2b22d600df5e (diff) | |
WIP: dynamic rrule builder, javascript side
| -rw-r--r-- | public/javascripts/admin_interface.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 4b1d4a9..3c480aa 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -271,3 +271,104 @@ image_interface = { | |||
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | 273 | ||
| 274 | rrule_builder = { | ||
| 275 | initialize : function() { | ||
| 276 | rrule_builder.try_populate_from_rrule($("#event_rrule").val()); | ||
| 277 | |||
| 278 | $("input[name='rrule_freq']").bind("change", function() { | ||
| 279 | if ($(this).val() === "weekly") { rrule_builder.show_weekly_options(); } | ||
| 280 | else { rrule_builder.show_monthly_options(); } | ||
| 281 | rrule_builder.sync(); | ||
| 282 | }); | ||
| 283 | $("#rrule_monthly_ordinal").bind("change", function() { | ||
| 284 | $("#rrule_ordinal_fields").toggle($(this).is(":checked")); | ||
| 285 | rrule_builder.sync(); | ||
| 286 | }); | ||
| 287 | $("#rrule_exclude_month").bind("change", function() { | ||
| 288 | $("#rrule_excluded_month").toggle($(this).is(":checked")); | ||
| 289 | rrule_builder.sync(); | ||
| 290 | }); | ||
| 291 | $("#rrule_builder input, #rrule_builder select").bind("change", rrule_builder.sync); | ||
| 292 | }, | ||
| 293 | |||
| 294 | show_weekly_options : function() { | ||
| 295 | $("#rrule_weekly_options").show(); | ||
| 296 | $("#rrule_monthly_options").hide(); | ||
| 297 | }, | ||
| 298 | show_monthly_options : function() { | ||
| 299 | $("#rrule_weekly_options").hide(); | ||
| 300 | $("#rrule_monthly_options").show(); | ||
| 301 | }, | ||
| 302 | |||
| 303 | sync : function() { | ||
| 304 | var freq = $("input[name='rrule_freq']:checked").val(); | ||
| 305 | var parts = []; | ||
| 306 | |||
| 307 | if (freq === "weekly") { | ||
| 308 | parts.push("FREQ=WEEKLY"); | ||
| 309 | if ($("#rrule_biweekly").is(":checked")) parts.push("INTERVAL=2"); | ||
| 310 | var days = []; | ||
| 311 | $("input[id^='rrule_byday_']:checked").each(function() { | ||
| 312 | days.push($(this).attr("id").replace("rrule_byday_", "")); | ||
| 313 | }); | ||
| 314 | if (days.length > 0) parts.push("BYDAY=" + days.join(",")); | ||
| 315 | } else { | ||
| 316 | parts.push("FREQ=MONTHLY"); | ||
| 317 | if ($("#rrule_monthly_ordinal").is(":checked")) { | ||
| 318 | parts.push("BYDAY=" + $("#rrule_ordinal").val() + $("#rrule_ordinal_day").val()); | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | if ($("#rrule_exclude_month").is(":checked")) { | ||
| 323 | var excluded = parseInt($("#rrule_excluded_month").val(), 10); | ||
| 324 | var months = []; | ||
| 325 | for (var m = 1; m <= 12; m++) { if (m !== excluded) months.push(m); } | ||
| 326 | parts.push("BYMONTH=" + months.join(",")); | ||
| 327 | } | ||
| 328 | |||
| 329 | $("#event_rrule").val(parts.join(";")); | ||
| 330 | }, | ||
| 331 | |||
| 332 | try_populate_from_rrule : function(rrule) { | ||
| 333 | if (!rrule) return; | ||
| 334 | var parts = {}; | ||
| 335 | rrule.split(";").forEach(function(p) { | ||
| 336 | var kv = p.split("="); | ||
| 337 | parts[kv[0]] = kv[1]; | ||
| 338 | }); | ||
| 339 | if (parts.COUNT || parts.UNTIL) return; | ||
| 340 | |||
| 341 | if (parts.FREQ === "WEEKLY") { | ||
| 342 | $("input[name='rrule_freq'][value='weekly']").prop("checked", true); | ||
| 343 | rrule_builder.show_weekly_options(); | ||
| 344 | if (parts.INTERVAL === "2") $("#rrule_biweekly").prop("checked", true); | ||
| 345 | if (parts.BYDAY) { | ||
| 346 | parts.BYDAY.split(",").forEach(function(code) { | ||
| 347 | $("#rrule_byday_" + code).prop("checked", true); | ||
| 348 | }); | ||
| 349 | } | ||
| 350 | } else if (parts.FREQ === "MONTHLY") { | ||
| 351 | $("input[name='rrule_freq'][value='monthly']").prop("checked", true); | ||
| 352 | rrule_builder.show_monthly_options(); | ||
| 353 | var match = parts.BYDAY && parts.BYDAY.match(/^(-?\d+)([A-Z]{2})$/); | ||
| 354 | if (match) { | ||
| 355 | $("#rrule_monthly_ordinal").prop("checked", true); | ||
| 356 | $("#rrule_ordinal_fields").show(); | ||
| 357 | $("#rrule_ordinal").val(match[1]); | ||
| 358 | $("#rrule_ordinal_day").val(match[2]); | ||
| 359 | } | ||
| 360 | } else { | ||
| 361 | return; | ||
| 362 | } | ||
| 363 | |||
| 364 | if (parts.BYMONTH) { | ||
| 365 | var included = parts.BYMONTH.split(",").map(function(s) { return parseInt(s, 10); }); | ||
| 366 | var missing = []; | ||
| 367 | for (var m = 1; m <= 12; m++) { if (included.indexOf(m) === -1) missing.push(m); } | ||
| 368 | if (missing.length === 1) { | ||
| 369 | $("#rrule_exclude_month").prop("checked", true); | ||
| 370 | $("#rrule_excluded_month").val(missing[0]).show(); | ||
| 371 | } | ||
| 372 | } | ||
| 373 | } | ||
| 374 | }; | ||
