UNPKG

dhtmlx-scheduler

Version:

JavaScript event calendar. Allows to manage events and appointments in different views

1,227 lines (1,223 loc) 671 kB
/** @license dhtmlxScheduler v.7.2.5 Standard To use dhtmlxScheduler in non-GPL projects (and get Pro version of the product), please obtain Commercial/Enterprise or Ultimate license on our site https://dhtmlx.com/docs/products/dhtmlxScheduler/#licensing or contact us at sales@dhtmlx.com (c) XB Software Ltd. */ const le = typeof window < "u" ? window : global; function St(e) { let i = [], t = !1, n = null, o = null; function a() { return e.config.drag_highlight && e.markTimespan; } function s(d) { const l = e.getView(d); return l ? l.layout : d; } function _(d) { const { event: l, layout: h, viewName: v, sectionId: m, eventNode: f } = d; (function(p, y) { switch (y) { case "month": p.style.top = "", p.style.left = ""; break; case "timeline": p.style.left = "", p.style.marginLeft = "1px"; break; default: p.style.top = ""; } })(f, h); const c = {}; let u = { start_date: l.start_date, end_date: l.end_date, css: "dhx_scheduler_dnd_marker", html: f }; if (h == "timeline") { const p = e.getView(v); if (p.round_position) { const y = e._get_date_index(p, l.start_date), x = p._trace_x[y]; u.start_date = x; } } return h != "timeline" && h != "month" || (u = { ...u, end_date: e.date.add(l.start_date, 1, "minute") }), m && (c[v] = m, u.sections = c), u; } function r(d) { const { layout: l } = d; let h; switch (l) { case "month": h = function(v) { let m = []; const { event: f, layout: c, viewName: u, sectionId: p } = v, y = []; let x = new Date(f.start_date); for (; x.valueOf() < f.end_date.valueOf(); ) { let k = { start_date: x }; y.push(k), x = e.date.week_start(e.date.add(x, 1, "week")); } let S = e.$container.querySelectorAll(`[${e.config.event_attribute}='${f.id}']`); for (let k = 0; k < S.length; k++) { const D = { event: y[k], layout: c, viewName: u, sectionId: p, eventNode: S[k].cloneNode(!0) }; m.push(_(D)); } return m; }(d); break; case "timeline": case "units": h = function(v) { let m = []; const { event: f, layout: c, viewName: u, eventNode: p } = v; let y = function(x) { const S = e.getView(x); return S.y_property ? S.y_property : S.map_to ? S.map_to : void 0; }(u); if (y) { const x = String(f[y]).split(e.config.section_delimiter).map((k) => String(k)), S = []; for (let k = 0; k < x.length; k++) { S[k] = p.cloneNode(!0); const D = { event: f, layout: c, viewName: u, sectionId: x[k], eventNode: S[k] }; m.push(_(D)); } } return m; }(d); break; default: h = function(v) { const { event: m, layout: f, viewName: c, sectionId: u } = v; let p = [], y = e.$container.querySelectorAll(`[${e.config.event_attribute}='${m.id}']:not(.dhx_cal_select_menu):not(.dhx_drag_marker)`); if (y) for (let x = 0; x < y.length; x++) { let S = y[x].cloneNode(!0); const k = { event: { start_date: /* @__PURE__ */ new Date(+S.getAttribute("data-bar-start")), end_date: /* @__PURE__ */ new Date(+S.getAttribute("data-bar-end")) }, layout: f, viewName: c, sectionId: u, eventNode: S }; p.push(_(k)); } return p; }(d); } h.forEach((v) => { i.push(e.markTimespan(v)); }); } e.attachEvent("onBeforeDrag", function(d, l, h) { return a() && (t = !0, o = e.getEvent(d), n = h.target.closest(`[${e.config.event_attribute}]`), s(e.getState().mode) == "units" && e.config.cascade_event_display && (e.unselect(d), n = h.target.closest(`[${e.config.event_attribute}]`))), !0; }), e.attachEvent("onEventDrag", function(d, l, h) { if (t && a()) { t = !1; const v = e.getState().mode, m = s(v), f = e.getActionData(h).section; o && r({ event: o, layout: m, viewName: v, sectionId: f, eventNode: n }); } }), e.attachEvent("onDragEnd", function(d, l, h) { for (let v = 0; v < i.length; v++) e.unmarkTimespan(i[v]); i = [], n = null, o = null; }); } function Mt(e) { e.config.mark_now = !0, e.config.display_marked_timespans = !0, e.config.overwrite_marked_timespans = !0; var i = "dhx_time_block", t = "default", n = function(a, s, _) { var r = typeof a == "object" ? a : { days: a }; return r.type = i, r.css = "", s && (_ && (r.sections = _), r = function(d, l, h) { return l instanceof Date && h instanceof Date ? (d.start_date = l, d.end_date = h) : (d.days = l, d.zones = h), d; }(r, a, s)), r; }; function o(a, s, _, r, d) { var l = e, h = [], v = { _props: "map_to", matrix: "y_property" }; for (var m in v) { var f = v[m]; if (l[m]) for (var c in l[m]) { var u = l[m][c][f]; a[u] && (h = l._add_timespan_zones(h, e._get_blocked_zones(s[c], a[u], _, r, d))); } } return h = l._add_timespan_zones(h, e._get_blocked_zones(s, "global", _, r, d)); } e.blockTime = function(a, s, _) { var r = n(a, s, _); return e.addMarkedTimespan(r); }, e.unblockTime = function(a, s, _) { var r = n(a, s = s || "fullday", _); return e.deleteMarkedTimespan(r); }, e.checkInMarkedTimespan = function(a, s, _) { s = s || t; for (var r = !0, d = new Date(a.start_date.valueOf()), l = e.date.add(d, 1, "day"), h = e._marked_timespans; d < a.end_date; d = e.date.date_part(l), l = e.date.add(d, 1, "day")) { var v = +e.date.date_part(new Date(d)), m = o(a, h, d.getDay(), v, s); if (m) for (var f = 0; f < m.length; f += 2) { var c = e._get_zone_minutes(d), u = a.end_date > l || a.end_date.getDate() != d.getDate() ? 1440 : e._get_zone_minutes(a.end_date), p = m[f], y = m[f + 1]; if (p < u && y > c && !(r = typeof _ == "function" && _(a, c, u, p, y))) break; } } return !r; }, e.checkLimitViolation = function(a) { if (!a || !e.config.check_limits) return !0; var s = e, _ = s.config, r = []; if (a.rec_type && a._end_date || a.rrule) { const m = a._end_date || a.end_date; return !_.limit_start || !_.limit_end || m.valueOf() >= _.limit_start.valueOf() && a.start_date.valueOf() <= _.limit_end.valueOf(); } r = [a]; for (var d = !0, l = 0; l < r.length; l++) { var h = !0, v = r[l]; v._timed = e.isOneDayEvent(v), (h = !_.limit_start || !_.limit_end || v.start_date.valueOf() >= _.limit_start.valueOf() && v.end_date.valueOf() <= _.limit_end.valueOf()) && (h = !e.checkInMarkedTimespan(v, i, function(m, f, c, u, p) { var y = !0; return f <= p && f >= u && ((p == 1440 || c <= p) && (y = !1), m._timed && s._drag_id && s._drag_mode == "new-size" ? (m.start_date.setHours(0), m.start_date.setMinutes(p)) : y = !1), (c >= u && c <= p || f < u && c > p) && (m._timed && s._drag_id && s._drag_mode == "new-size" ? (m.end_date.setHours(0), m.end_date.setMinutes(u)) : y = !1), y; })), h || (h = s.checkEvent("onLimitViolation") ? s.callEvent("onLimitViolation", [v.id, v]) : h), d = d && h; } return d || (s._drag_id = null, s._drag_mode = null), d; }, e._get_blocked_zones = function(a, s, _, r, d) { var l = []; if (a && a[s]) for (var h = a[s], v = this._get_relevant_blocked_zones(_, r, h, d), m = 0; m < v.length; m++) l = this._add_timespan_zones(l, v[m].zones); return l; }, e._get_relevant_blocked_zones = function(a, s, _, r) { var d; return e.config.overwrite_marked_timespans ? d = _[s] && _[s][r] ? _[s][r] : _[a] && _[a][r] ? _[a][r] : [] : (d = [], _[s] && _[s][r] && (d = d.concat(_[s][r])), _[a] && _[a][r] && (d = d.concat(_[a][r]))), d; }, e._mark_now = function(a) { var s = "dhx_now_time"; this._els[s] || (this._els[s] = []); var _ = e._currentDate(), r = this.config; if (e._remove_mark_now(), !a && r.mark_now && _ < this._max_date && _ > this._min_date && _.getHours() >= r.first_hour && _.getHours() < r.last_hour) { var d = this.locate_holder_day(_); this._els[s] = e._append_mark_now(d, _); } }, e._append_mark_now = function(a, s) { var _ = "dhx_now_time", r = e._get_zone_minutes(s), d = { zones: [r, r + 1], css: _, type: _ }; if (!this._table_view) { if (this._props && this._props[this._mode]) { var l, h, v = this._props[this._mode], m = v.size || v.options.length; v.days > 1 ? (v.size && v.options.length && (a = (v.position + a) / v.options.length * v.size), l = a, h = a + m) : h = (l = 0) + m; for (var f = [], c = l; c < h; c++) { var u = c; d.days = u; var p = e._render_marked_timespan(d, null, u)[0]; f.push(p); } return f; } return d.days = a, e._render_marked_timespan(d, null, a); } if (this._mode == "month") return d.days = +e.date.date_part(s), e._render_marked_timespan(d, null, null); }, e._remove_mark_now = function() { for (var a = "dhx_now_time", s = this._els[a], _ = 0; _ < s.length; _++) { var r = s[_], d = r.parentNode; d && d.removeChild(r); } this._els[a] = []; }, e._marked_timespans = { global: {} }, e._get_zone_minutes = function(a) { return 60 * a.getHours() + a.getMinutes(); }, e._prepare_timespan_options = function(a) { var s = [], _ = []; if (a.days == "fullweek" && (a.days = [0, 1, 2, 3, 4, 5, 6]), a.days instanceof Array) { for (var r = a.days.slice(), d = 0; d < r.length; d++) { var l = e._lame_clone(a); l.days = r[d], s.push.apply(s, e._prepare_timespan_options(l)); } return s; } if (!a || !(a.start_date && a.end_date && a.end_date > a.start_date || a.days !== void 0 && a.zones) && !a.type) return s; a.zones == "fullday" && (a.zones = [0, 1440]), a.zones && a.invert_zones && (a.zones = e.invertZones(a.zones)), a.id = e.uid(), a.css = a.css || "", a.type = a.type || t; var h = a.sections; if (h) { for (var v in h) if (h.hasOwnProperty(v)) { var m = h[v]; for (m instanceof Array || (m = [m]), d = 0; d < m.length; d++) (S = e._lame_copy({}, a)).sections = {}, S.sections[v] = m[d], _.push(S); } } else _.push(a); for (var f = 0; f < _.length; f++) { var c = _[f], u = c.start_date, p = c.end_date; if (u && p) for (var y = e.date.date_part(new Date(u)), x = e.date.add(y, 1, "day"); y < p; ) { var S; delete (S = e._lame_copy({}, c)).start_date, delete S.end_date, S.days = y.valueOf(); var k = u > y ? e._get_zone_minutes(u) : 0, D = p > x || p.getDate() != y.getDate() ? 1440 : e._get_zone_minutes(p); S.zones = [k, D], s.push(S), y = x, x = e.date.add(x, 1, "day"); } else c.days instanceof Date && (c.days = e.date.date_part(c.days).valueOf()), c.zones = a.zones.slice(), s.push(c); } return s; }, e._get_dates_by_index = function(a, s, _) { var r = []; s = e.date.date_part(new Date(s || e._min_date)), _ = new Date(_ || e._max_date); for (var d = s.getDay(), l = a - d >= 0 ? a - d : 7 - s.getDay() + a, h = e.date.add(s, l, "day"); h < _; h = e.date.add(h, 1, "week")) r.push(h); return r; }, e._get_css_classes_by_config = function(a) { var s = []; return a.type == i && (s.push(i), a.css && s.push(i + "_reset")), s.push("dhx_marked_timespan", a.css), s.join(" "); }, e._get_block_by_config = function(a) { var s = document.createElement("div"); return a.html && (typeof a.html == "string" ? s.innerHTML = a.html : s.appendChild(a.html)), s; }, e._render_marked_timespan = function(a, s, _) { var r = [], d = e.config, l = this._min_date, h = this._max_date, v = !1; if (!d.display_marked_timespans) return r; if (!_ && _ !== 0) { if (a.days < 7) _ = a.days; else { var m = new Date(a.days); if (v = +m, !(+h > +m && +l <= +m)) return r; _ = m.getDay(); } var f = l.getDay(); f > _ ? _ = 7 - (f - _) : _ -= f; } var c = a.zones, u = e._get_css_classes_by_config(a); if (e._table_view && e._mode == "month") { var p = [], y = []; if (s) p.push(s), y.push(_); else { y = v ? [v] : e._get_dates_by_index(_); for (var x = 0; x < y.length; x++) p.push(this._scales[y[x]]); } for (x = 0; x < p.length; x++) { s = p[x], _ = y[x]; var S = this.locate_holder_day(_, !1) % this._cols.length; if (!this._ignores[S]) { var k = e._get_block_by_config(a); k.className = u, k.style.top = "0px", k.style.height = "100%"; for (var D = 0; D < c.length; D += 2) { var M = c[x]; if ((E = c[x + 1]) <= M) return []; (N = k.cloneNode(!0)).style.left = "0px", N.style.width = "100%", s.appendChild(N), r.push(N); } } } } else { var g = _; if (this._ignores[this.locate_holder_day(_, !1)]) return r; if (this._props && this._props[this._mode] && a.sections && a.sections[this._mode]) { var b = this._props[this._mode]; g = b.order[a.sections[this._mode]]; var w = b.order[a.sections[this._mode]]; b.days > 1 ? g = g * (b.size || b.options.length) + w : (g = w, b.size && g > b.position + b.size && (g = 0)); } for (s = s || e.locate_holder(g), x = 0; x < c.length; x += 2) { var E, N; if (M = Math.max(c[x], 60 * d.first_hour), (E = Math.min(c[x + 1], 60 * d.last_hour)) <= M) { if (x + 2 < c.length) continue; return []; } (N = e._get_block_by_config(a)).className = u; var T = 24 * this.config.hour_size_px + 1, A = 36e5; N.style.top = Math.round((60 * M * 1e3 - this.config.first_hour * A) * this.config.hour_size_px / A) % T + "px", N.style.height = Math.max(Math.round(60 * (E - M) * 1e3 * this.config.hour_size_px / A) % T, 1) + "px", s.appendChild(N), r.push(N); } } return r; }, e._mark_timespans = function() { var a = this._els.dhx_cal_data[0], s = []; if (e._table_view && e._mode == "month") for (var _ in this._scales) { var r = /* @__PURE__ */ new Date(+_); s.push.apply(s, e._on_scale_add_marker(this._scales[_], r)); } else { r = new Date(e._min_date); for (var d = 0, l = a.childNodes.length; d < l; d++) { var h = a.childNodes[d]; h.firstChild && e._getClassName(h.firstChild).indexOf("dhx_scale_hour") > -1 || (s.push.apply(s, e._on_scale_add_marker(h, r)), r = e.date.add(r, 1, "day")); } } return s; }, e.markTimespan = function(a) { if (!this._els) throw new Error("`scheduler.markTimespan` can't be used before scheduler initialization. Place `scheduler.markTimespan` call after `scheduler.init`."); var s = !1; this._els.dhx_cal_data || (e.get_elements(), s = !0); var _ = e._marked_timespans_ids, r = e._marked_timespans_types, d = e._marked_timespans; e.deleteMarkedTimespan(), e.addMarkedTimespan(a); var l = e._mark_timespans(); return s && (e._els = []), e._marked_timespans_ids = _, e._marked_timespans_types = r, e._marked_timespans = d, l; }, e.unmarkTimespan = function(a) { if (a) for (var s = 0; s < a.length; s++) { var _ = a[s]; _.parentNode && _.parentNode.removeChild(_); } }, e._addMarkerTimespanConfig = function(a) { var s = "global", _ = e._marked_timespans, r = a.id, d = e._marked_timespans_ids; d[r] || (d[r] = []); var l = a.days, h = a.sections, v = a.type; if (a.id = r, h) { for (var m in h) if (h.hasOwnProperty(m)) { _[m] || (_[m] = {}); var f = h[m], c = _[m]; c[f] || (c[f] = {}), c[f][l] || (c[f][l] = {}), c[f][l][v] || (c[f][l][v] = [], e._marked_timespans_types || (e._marked_timespans_types = {}), e._marked_timespans_types[v] || (e._marked_timespans_types[v] = !0)); var u = c[f][l][v]; a._array = u, u.push(a), d[r].push(a); } } else _[s][l] || (_[s][l] = {}), _[s][l][v] || (_[s][l][v] = []), e._marked_timespans_types || (e._marked_timespans_types = {}), e._marked_timespans_types[v] || (e._marked_timespans_types[v] = !0), u = _[s][l][v], a._array = u, u.push(a), d[r].push(a); }, e._marked_timespans_ids = {}, e.addMarkedTimespan = function(a) { var s = e._prepare_timespan_options(a); if (s.length) { for (var _ = s[0].id, r = 0; r < s.length; r++) e._addMarkerTimespanConfig(s[r]); return _; } }, e._add_timespan_zones = function(a, s) { var _ = a.slice(); if (s = s.slice(), !_.length) return s; for (var r = 0; r < _.length; r += 2) for (var d = _[r], l = _[r + 1], h = r + 2 == _.length, v = 0; v < s.length; v += 2) { var m = s[v], f = s[v + 1]; if (f > l && m <= l || m < d && f >= d) _[r] = Math.min(d, m), _[r + 1] = Math.max(l, f), r -= 2; else { if (!h) continue; var c = d > m ? 0 : 2; _.splice(r + c, 0, m, f); } s.splice(v--, 2); break; } return _; }, e._subtract_timespan_zones = function(a, s) { for (var _ = a.slice(), r = 0; r < _.length; r += 2) for (var d = _[r], l = _[r + 1], h = 0; h < s.length; h += 2) { var v = s[h], m = s[h + 1]; if (m > d && v < l) { var f = !1; d >= v && l <= m && _.splice(r, 2), d < v && (_.splice(r, 2, d, v), f = !0), l > m && _.splice(f ? r + 2 : r, f ? 0 : 2, m, l), r -= 2; break; } } return _; }, e.invertZones = function(a) { return e._subtract_timespan_zones([0, 1440], a.slice()); }, e._delete_marked_timespan_by_id = function(a) { var s = e._marked_timespans_ids[a]; if (s) { for (var _ = 0; _ < s.length; _++) for (var r = s[_], d = r._array, l = 0; l < d.length; l++) if (d[l] == r) { d.splice(l, 1); break; } } }, e._delete_marked_timespan_by_config = function(a) { var s, _ = e._marked_timespans, r = a.sections, d = a.days, l = a.type || t; if (r) { for (var h in r) if (r.hasOwnProperty(h) && _[h]) { var v = r[h]; _[h][v] && (s = _[h][v]); } } else s = _.global; if (s) { if (d !== void 0) s[d] && s[d][l] && (e._addMarkerTimespanConfig(a), e._delete_marked_timespans_list(s[d][l], a)); else for (var m in s) if (s[m][l]) { var f = e._lame_clone(a); a.days = m, e._addMarkerTimespanConfig(f), e._delete_marked_timespans_list(s[m][l], a); } } }, e._delete_marked_timespans_list = function(a, s) { for (var _ = 0; _ < a.length; _++) { var r = a[_], d = e._subtract_timespan_zones(r.zones, s.zones); if (d.length) r.zones = d; else { a.splice(_, 1), _--; for (var l = e._marked_timespans_ids[r.id], h = 0; h < l.length; h++) if (l[h] == r) { l.splice(h, 1); break; } } } }, e.deleteMarkedTimespan = function(a) { if (arguments.length || (e._marked_timespans = { global: {} }, e._marked_timespans_ids = {}, e._marked_timespans_types = {}), typeof a != "object") e._delete_marked_timespan_by_id(a); else { a.start_date && a.end_date || (a.days !== void 0 || a.type || (a.days = "fullweek"), a.zones || (a.zones = "fullday")); var s = []; if (a.type) s.push(a.type); else for (var _ in e._marked_timespans_types) s.push(_); for (var r = e._prepare_timespan_options(a), d = 0; d < r.length; d++) for (var l = r[d], h = 0; h < s.length; h++) { var v = e._lame_clone(l); v.type = s[h], e._delete_marked_timespan_by_config(v); } } }, e._get_types_to_render = function(a, s) { var _ = a ? e._lame_copy({}, a) : {}; for (var r in s || {}) s.hasOwnProperty(r) && (_[r] = s[r]); return _; }, e._get_configs_to_render = function(a) { var s = []; for (var _ in a) a.hasOwnProperty(_) && s.push.apply(s, a[_]); return s; }, e._on_scale_add_marker = function(a, s) { if (!e._table_view || e._mode == "month") { var _ = s.getDay(), r = s.valueOf(), d = this._mode, l = e._marked_timespans, h = [], v = []; if (this._props && this._props[d]) { var m = this._props[d], f = m.options, c = f[e._get_unit_index(m, s)]; if (m.days > 1) { var u = Math.round((s - e._min_date) / 864e5), p = m.size || f.length; s = e.date.add(e._min_date, Math.floor(u / p), "day"), s = e.date.date_part(s); } else s = e.date.date_part(new Date(this._date)); if (_ = s.getDay(), r = s.valueOf(), l[d] && l[d][c.key]) { var y = l[d][c.key], x = e._get_types_to_render(y[_], y[r]); h.push.apply(h, e._get_configs_to_render(x)); } } var S = l.global; if (e.config.overwrite_marked_timespans) { var k = S[r] || S[_]; h.push.apply(h, e._get_configs_to_render(k)); } else S[r] && h.push.apply(h, e._get_configs_to_render(S[r])), S[_] && h.push.apply(h, e._get_configs_to_render(S[_])); for (var D = 0; D < h.length; D++) v.push.apply(v, e._render_marked_timespan(h[D], a, s)); return v; } }, e.attachEvent("onScaleAdd", function() { e._on_scale_add_marker.apply(e, arguments); }), e.dblclick_dhx_marked_timespan = function(a, s) { e.callEvent("onScaleDblClick", [e.getActionData(a).date, s, a]), e.config.dblclick_create && e.addEventNow(e.getActionData(a).date, null, a); }; } function Nt(e) { var i = {}, t = !1; function n(r, d) { d = typeof d == "function" ? d : function() { }, i[r] || (i[r] = this[r], this[r] = d); } function o(r) { i[r] && (this[r] = i[r], i[r] = null); } function a(r) { for (var d in r) n.call(this, d, r[d]); } function s() { for (var r in i) o.call(this, r); } function _(r) { try { r(); } catch (d) { window.console.error(d); } } return e.$stateProvider.registerProvider("batchUpdate", function() { return { batch_update: t }; }, !1), function(r, d) { if (t) return void _(r); var l, h = this._dp && this._dp.updateMode != "off"; h && (l = this._dp.updateMode, this._dp.setUpdateMode("off")); const v = { setModeDate: { date: null, mode: null }, needRender: !1, needUpdateView: !1, repaintEvents: {} }, m = (c, u) => { c && (v.setModeDate.date = c), u && (v.setModeDate.mode = u); }; var f = { render: (c, u) => { v.needRender = !0, m(c, u); }, setCurrentView: (c, u) => { v.needRender = !0, m(c, u); }, updateView: (c, u) => { v.needUpdateView = !0, m(c, u); }, render_data: () => v.needRender = !0, render_view_data: (c) => { c && c.length ? c.forEach((u) => v.repaintEvents[u.id] = !0) : v.needRender = !0; } }; if (a.call(this, f), t = !0, this.callEvent("onBeforeBatchUpdate", []), _(r), this.callEvent("onAfterBatchUpdate", []), s.call(this), t = !1, !d) if (v.needRender) e.render(v.setModeDate.date, v.setModeDate.mode); else if (v.needUpdateView) e.updateView(v.setModeDate.date, v.setModeDate.mode); else for (const c in v.repaintEvents) e.updateEvent(c); h && (this._dp.setUpdateMode(l), this._dp.sendData()); }; } class Tt { constructor(i) { const { url: t, token: n } = i; this._url = t, this._token = n, this._mode = 1, this._seed = 1, this._queue = [], this.data = {}, this.api = {}, this._events = {}; } headers() { return { Accept: "application/json", "Content-Type": "application/json", "Remote-Token": this._token }; } fetch(i, t) { const n = { credentials: "include", headers: this.headers() }; return t && (n.method = "POST", n.body = t), fetch(i, n).then((o) => o.json()); } load(i) { return i && (this._url = i), this.fetch(this._url).then((t) => this.parse(t)); } parse(i) { const { key: t, websocket: n } = i; t && (this._token = i.key); for (const o in i.data) this.data[o] = i.data[o]; for (const o in i.api) { const a = this.api[o] = {}, s = i.api[o]; for (const _ in s) a[_] = this._wrapper(o + "." + _); } return n && this.connect(), this; } connect() { const i = this._socket; i && (this._socket = null, i.onclose = function() { }, i.close()), this._mode = 2, this._socket = function(t, n, o, a) { let s = n; s[0] === "/" && (s = document.location.protocol + "//" + document.location.host + n), s = s.replace(/^http(s|):/, "ws$1:"); const _ = s.indexOf("?") != -1 ? "&" : "?"; s = `${s}${_}token=${o}&ws=1`; const r = new WebSocket(s); return r.onclose = () => setTimeout(() => t.connect(), 2e3), r.onmessage = (d) => { const l = JSON.parse(d.data); switch (l.action) { case "result": t.result(l.body, []); break; case "event": t.fire(l.body.name, l.body.value); break; case "start": a(); break; default: t.onError(l.data); } }, r; }(this, this._url, this._token, () => (this._mode = 3, this._send(), this._resubscribe(), this)); } _wrapper(i) { return (function() { const t = [].slice.call(arguments); let n = null; const o = new Promise((a, s) => { n = { data: { id: this._uid(), name: i, args: t }, status: 1, resolve: a, reject: s }, this._queue.push(n); }); return this.onCall(n, o), this._mode === 3 ? this._send(n) : setTimeout(() => this._send(), 1), o; }).bind(this); } _uid() { return (this._seed++).toString(); } _send(i) { if (this._mode == 2) return void setTimeout(() => this._send(), 100); const t = i ? [i] : this._queue.filter((o) => o.status === 1); if (!t.length) return; const n = t.map((o) => (o.status = 2, o.data)); this._mode !== 3 ? this.fetch(this._url, JSON.stringify(n)).catch((o) => this.onError(o)).then((o) => this.result(o, n)) : this._socket.send(JSON.stringify({ action: "call", body: n })); } result(i, t) { const n = {}; if (i) for (let o = 0; o < i.length; o++) n[i[o].id] = i[o]; else for (let o = 0; o < t.length; o++) n[t[o].id] = { id: t[o].id, error: "Network Error", data: null }; for (let o = this._queue.length - 1; o >= 0; o--) { const a = this._queue[o], s = n[a.data.id]; s && (this.onResponse(a, s), s.error ? a.reject(s.error) : a.resolve(s.data), this._queue.splice(o, 1)); } } on(i, t) { const n = this._uid(); let o = this._events[i]; const a = !!o; return a || (o = this._events[i] = []), o.push({ id: n, handler: t }), a || this._mode != 3 || this._socket.send(JSON.stringify({ action: "subscribe", name: i })), { name: i, id: n }; } _resubscribe() { if (this._mode == 3) for (const i in this._events) this._socket.send(JSON.stringify({ action: "subscribe", name: i })); } detach(i) { if (!i) { if (this._mode == 3) for (const a in this._events) this._socket.send(JSON.stringify({ action: "unsubscribe", key: a })); return void (this._events = {}); } const { id: t, name: n } = i, o = this._events[n]; if (o) { const a = o.filter((s) => s.id != t); a.length ? this._events[n] = a : (delete this._events[n], this._mode == 3 && this._socket.send(JSON.stringify({ action: "unsubscribe", name: n }))); } } fire(i, t) { const n = this._events[i]; if (n) for (let o = 0; o < n.length; o++) n[o].handler(t); } onError(i) { return null; } onCall(i, t) { } onResponse(i, t) { } } class At { constructor(i, t) { const n = new Tt({ url: i, token: t }); n.fetch = function(o, a) { const s = { headers: this.headers() }; return a && (s.method = "POST", s.body = a), fetch(o, s).then((_) => _.json()); }, this._ready = n.load().then((o) => this._remote = o); } ready() { return this._ready; } on(i, t) { this.ready().then((n) => { if (typeof i == "string") n.on(i, t); else for (const o in i) n.on(o, i[o]); }); } } function Ct(e) { function i(n, o) { switch (n) { case "add-event": (function(a) { if (e.getEvent(a.id)) return void console.warn(`Event with ID ${a.id} already exists. Skipping add.`); a.start_date = e.templates.parse_date(a.start_date), a.end_date = e.templates.parse_date(a.end_date), a.original_start && (a.original_start = e.templates.parse_date(a.original_start)), t(() => { e.addEvent(a); }); })(o); break; case "update-event": (function(a) { const s = a.id; if (!e.getEvent(s)) return void console.warn(`Event with ID ${s} does not exist. Skipping update.`); const _ = e.getEvent(s); t(() => { for (let r in a) r !== "start_date" && r !== "end_date" && (_[r] = a[r]); _.start_date = e.templates.parse_date(a.start_date), _.end_date = e.templates.parse_date(a.end_date), a.original_start && (a.original_start = e.templates.parse_date(a.original_start)), e.callEvent("onEventChanged", [s, _]), e.updateEvent(s), s !== a.id && e.changeEventId(s, a.id); }); })(o); break; case "delete-event": (function(a) { const s = a.id; if (!e.getEvent(s)) return void (a.event_pid && t(() => { e.addEvent(a); })); t(() => { const _ = e.getEvent(s); if (_) { if (_.rec_type || _.rrule) { e._roll_back_dates(_); const r = e._get_rec_markers(s); for (const d in r) e.getEvent(d) && e.deleteEvent(d, !0); } if (e.getState().lightbox_id == s && (this._new_event = this._lightbox_id, a.id = this._lightbox_id, this._events[this._lightbox_id] = a, e.callEvent("onLiveUpdateCollision", [s, null, "delete", a]) === !1)) return void e.endLightbox(!1, e._lightbox); e.deleteEvent(s, !0); } }); })(o); } } function t(n) { e._dp ? e._dp.ignore(n) : n(); } return { events: function(n) { if (!n || !n.event || !n.event.id) return void console.error("Invalid message format:", n); const { type: o, event: a } = n; if (!e._dp._in_progress[a.id]) { if (o === "add-event") { for (const s in e._dp._in_progress) if (e._dp.getState(s) === "inserted") return void e._dp.attachEvent("onFullSync", function() { e.getEvent(a.id) || i(o, a); }, { once: !0 }); } i(o, a); } } }; } function Ot(e) { (function(i) { const t = {}; i.attachEvent("onConfirmedBeforeEventDelete", function(n) { return t[n] = !0, !0; }), i.attachEvent("onEventDeleted", function(n, o) { if (!t[n]) return; delete t[n]; let a = i.copy(o); i.config.undo_deleted && !i.getState().new_event && i.message({ text: `<div class="dhx_info_message"> <span class="undo_popup_text">Event deleted</span> <button class="undo_button" data-deleted-event-id="${o.id}">Undo</button> </div>`, expire: 1e4, type: "popup_after_delete", callback: function(s) { s.target.closest(`[data-deleted-event-id="${o.id}"]`) && (a.rrule && a.duration && (a.end_date = new Date(a.start_date.valueOf() + 1e3 * a.duration), i.addEvent(a)), i.addEvent(a), i.render()); } }); }); })(e), St(e), Mt(e), function(i) { i.batchUpdate = Nt(i); }(e), function(i) { i.ext || (i.ext = {}), i.ext.liveUpdates = { RemoteEvents: At, remoteUpdates: Ct(i) }; }(e); } var Lt = Date.now(); function Te(e) { return !(!e || typeof e != "object") && !!(e.getFullYear && e.getMonth && e.getDate); } const re = { uid: function() { return Lt++; }, mixin: function(e, i, t) { for (var n in i) (e[n] === void 0 || t) && (e[n] = i[n]); return e; }, copy: function e(i) { var t, n, o; if (i && typeof i == "object") switch (!0) { case Te(i): n = new Date(i); break; case (o = i, Array.isArray ? Array.isArray(o) : o && o.length !== void 0 && o.pop && o.push): for (n = new Array(i.length), t = 0; t < i.length; t++) n[t] = e(i[t]); break; case function(a) { return a && typeof a == "object" && Function.prototype.toString.call(a.constructor) === "function String() { [native code] }"; }(i): n = new String(i); break; case function(a) { return a && typeof a == "object" && Function.prototype.toString.call(a.constructor) === "function Number() { [native code] }"; }(i): n = new Number(i); break; case function(a) { return a && typeof a == "object" && Function.prototype.toString.call(a.constructor) === "function Boolean() { [native code] }"; }(i): n = new Boolean(i); break; default: for (t in n = {}, i) { const a = typeof i[t]; a === "string" || a === "number" || a === "boolean" ? n[t] = i[t] : Te(i[t]) ? n[t] = new Date(i[t]) : Object.prototype.hasOwnProperty.apply(i, [t]) && (n[t] = e(i[t])); } } return n || i; }, defined: function(e) { return e !== void 0; }, isDate: Te, delay: function(e, i) { var t, n = function() { n.$cancelTimeout(), n.$pending = !0; var o = Array.prototype.slice.call(arguments); t = setTimeout(function() { e.apply(this, o), n.$pending = !1; }, i); }; return n.$pending = !1, n.$cancelTimeout = function() { clearTimeout(t), n.$pending = !1; }, n.$execute = function() { var o = Array.prototype.slice.call(arguments); e.apply(this, o), n.$cancelTimeout(); }, n; } }; function $t(e) { function i(f) { var c = document.createElement("div"); return (f || "").split(" ").forEach(function(u) { c.classList.add(u); }), c; } var t = function() { return i("dhx_cal_navbar_rows_container"); }, n = function() { return i("dhx_cal_navbar_row"); }, o = function(f) { var c = i("dhx_cal_tab"); return c.setAttribute("name", f.view + "_tab"), c.setAttribute("data-tab", f.view), e.config.fix_tab_position && (f.$firstTab ? c.classList.add("dhx_cal_tab_first") : f.$lastTab ? c.classList.add("dhx_cal_tab_last") : f.view !== "week" && c.classList.add("dhx_cal_tab_standalone"), f.$segmentedTab && c.classList.add("dhx_cal_tab_segmented")), c; }, a = function() { return i("dhx_cal_date"); }, s = function(f) { return i("dhx_cal_nav_button dhx_cal_nav_button_custom dhx_cal_tab"); }, _ = function(f) { return i("dhx_cal_" + f.view + "_button dhx_cal_nav_button"); }, r = function() { return i("dhx_cal_line_spacer"); }, d = function(f) { var c = i("dhx_minical_icon"); return f.click || c.$_eventAttached || e.event(c, "click", function() { e.isCalendarVisible() ? e.destroyCalendar() : e.renderCalendar({ position: this, date: e.getState().date, navigation: !0, handler: function(u, p) { e.setCurrentView(u), e.destroyCalendar(); } }); }), c; }; function l(f) { var c = function(y) { var x; if (y.view) switch (y.view) { case "today": case "next": case "prev": x = _; break; case "date": x = a; break; case "spacer": x = r; break; case "button": x = s; break; case "minicalendar": x = d; break; default: x = o; } else y.rows ? x = t : y.cols && (x = n); return x; }(f); if (c) { var u = c(f); if (f.css && u.classList.add(f.css), f.width && ((p = f.width) === 1 * p && (p += "px"), u.style.width = p), f.height && ((p = f.height) === 1 * p && (p += "px"), u.style.height = p), f.click && e.event(u, "click", f.click), f.html && (u.innerHTML = f.html), f.align) { var p = ""; f.align == "right" ? p = "flex-end" : f.align == "left" && (p = "flex-start"), u.style.justifyContent = p; } return u; } } function h(f) { return typeof f == "string" && (f = { view: f }), f.view || f.rows || f.cols || (f.view = "button"), f; } function v(f) { var c, u = document.createDocumentFragment(); c = Array.isArray(f) ? f : [f]; for (var p = 0; p < c.length; p++) { var y, x = h(c[p]); x.view === "day" && c[p + 1] && ((y = h(c[p + 1])).view !== "week" && y.view !== "month" || (x.$firstTab = !0, x.$segmentedTab = !0)), x.view === "week" && c[p - 1] && ((y = h(c[p + 1])).view !== "week" && y.view !== "month" || (x.$segmentedTab = !0)), x.view === "month" && c[p - 1] && ((y = h(c[p - 1])).view !== "week" && y.view !== "day" || (x.$lastTab = !0, x.$segmentedTab = !0)); var S = l(x); u.appendChild(S), (x.cols || x.rows) && S.appendChild(v(x.cols || x.rows)); } return u; } e._init_nav_bar = function(f) { var c = this.$container.querySelector(".dhx_cal_navline"); return c || ((c = document.createElement("div")).className = "dhx_cal_navline dhx_cal_navline_flex", e._update_nav_bar(f, c), c); }; var m = null; e._update_nav_bar = function(f, c) { if (f) { var u = !1, p = f.height || e.xy.nav_height; m !== null && m === p || (u = !0), u && (e.xy.nav_height = p), c.innerHTML = "", c.appendChild(v(f)), e.unset_actions(), e._els = [], e.get_elements(), e.set_actions(), c.style.display = p === 0 ? "none" : "", m = p; } }; } function Ht(e) { function i(a) { return a.isConnected !== void 0 ? a.isConnected : document.body.contains(a); } function t(a) { return { w: a.innerWidth || document.documentElement.clientWidth, h: a.innerHeight || document.documentElement.clientHeight }; } function n(a, s) { var _, r = t(s); a.event(s, "resize", function() { clearTimeout(_), _ = setTimeout(function() { if (i(a.$container) && !a.$destroyed) { var d, l, h = t(s); l = h, ((d = r).w != l.w || d.h != l.h) && (r = h, o(a)); } }, 150); }); } function o(a) { a.$initialized && !a.$destroyed && a.$root && i(a.$root) && a.callEvent("onSchedulerResize", []) && (a.updateView(), a.callEvent("onAfterSchedulerResize", [])); } (function(a) { var s = a.$container; if (window.getComputedStyle(s).getPropertyValue("position") == "static" && (s.style.position = "relative"), window.ResizeObserver) { let r = !0; const d = new ResizeObserver(function(l) { r ? r = !1 : o(a); }); d.observe(s), a.attachEvent("onDestroy", function() { d.unobserve(s); }); } else { var _ = document.createElement("iframe"); _.className = "scheduler_container_resize_watcher", _.tabIndex = -1, a.config.wai_aria_attributes && (_.setAttribute("role", "none"), _.setAttribute("aria-hidden", !0)), window.Sfdc || window.$A || window.Aura ? function(r) { var d = r.$root.offsetHeight, l = r.$root.offsetWidth; (function h() { r.$destroyed || (r.$root && (r.$root.offsetHeight == d && r.$root.offsetWidth == l || o(r), d = r.$root.offsetHeight, l = r.$root.offsetWidth), setTimeout(h, 200)); })(); }(a) : (s.appendChild(_), _.contentWindow ? n(a, _.contentWindow) : (s.removeChild(_), n(a, window))); } })(e); } class zt { constructor() { this._silent_mode = !1, this.listeners = {}; } _silentStart() { this._silent_mode = !0; } _silentEnd() { this._silent_mode = !1; } } function Ve(e) { const i = new zt(); e.attachEvent = function(t, n, o) { t = "ev_" + t.toLowerCase(), i.listeners[t] || (i.listeners[t] = function(s) { let _ = {}, r = 0; const d = function() { let l = !0; for (const h in _) { const v = _[h].apply(s, arguments); l = l && v; } return l; }; return d.addEvent = function(l, h) { if (typeof l == "function") { let v; if (h && h.id ? v = h.id : (v = r, r++), h && h.once) { const m = l; l = function() { m(), d.removeEvent(v); }; } return _[v] = l, v; } return !1; }, d.removeEvent = function(l) { delete _[l]; }, d.clear = function() { _ = {}; }, d; }(this)), o && o.thisObject && (n = n.bind(o.thisObject)); let a = t + ":" + i.listeners[t].addEvent(n, o); return o && o.id && (a = o.id), a; }, e.attachAll = function(t) { this.attachEvent("listen_all", t); }, e.callEvent = function(t, n) { if (i._silent_mode) return !0; const o = "ev_" + t.toLowerCase(), a = i.listeners; return a.ev_listen_all && a.ev_listen_all.apply(this, [t].concat(n)), !a[o] || a[o].apply(this, n); }, e.checkEvent = function(t) { return !!i.listeners["ev_" + t.toLowerCase()]; }, e.detachEvent = function(t) { if (t) { let n = i.listeners; for (const a in n) n[a].removeEvent(t); const o = t.split(":"); if (n = i.listeners, o.length === 2) { const a = o[0], s = o[1]; n[a] && n[a].removeEvent(s); } } }, e.detachAllEvents = function() { for (const t in i.listeners) i.listeners[t].clear(); }; } const Ke = { event: function(e, i, t) { e.addEventListener ? e.addEventListener(i, t, !1) : e.attachEvent && e.attachEvent("on" + i, t); }, eventRemove: function(e, i, t) { e.removeEventListener ? e.removeEventListener(i, t, !1) : e.detachEvent && e.detachEvent("on" + i, t); } }; function qt(e) { var i = function() { var t = function(n, o) { n = n || Ke.event, o = o || Ke.eventRemove; var a = [], s = { attach: function(_, r, d, l) { a.push({ element: _, event: r, callback: d, capture: l }), n(_, r, d, l); }, detach: function(_, r, d, l) { o(_, r, d, l); for (var h = 0; h < a.length; h++) { var v = a[h]; v.element === _ && v.event === r && v.callback === d && v.capture === l && (a.splice(h, 1), h--); } }, detachAll: function() { for (var _ = a.slice(), r = 0; r < _.length; r++) { var d = _[r]; s.detach(d.element, d.event, d.callback, d.capture), s.detach(d.element, d.event, d.callback, void 0), s.detach(d.element, d.event, d.callback, !1), s.detach(d.element, d.event, d.callback, !0); } a.splice(0, a.length); }, extend: function() { return t(this.event, this.eventRemove); } }; return s; }; return t(); }(); e.event = i.attach, e.eventRemove = i.detach, e._eventRemoveAll = i.detachAll, e._createDomEventScope = i.extend, e._trim = function(t) { return (String.prototype.trim || function() { return this.replace(/^\s+|\s+$/g, ""); }).apply(t); }, e._isDate = function(t) { return !(!t || typeof t != "object") && !!(t.getFullYear && t.getMonth && t.getDate); }, e._isObject = function(t) { return t && typeof t == "object"; }; } function ft(e) { if (!e) return ""; var i = e.className || ""; return i.baseVal && (i = i.baseVal), i.indexOf || (i = ""), i || ""; } function pt(e, i, t) { t === void 0 && (t = !0); for (var n = e.target || e.srcElement, o = ""; n; ) { if (o = ft(n)) { var a = o.indexOf(i); if (a >= 0) { if (!t) return n; var s = a === 0 || !(o.charAt(a - 1) || "").trim(), _ = a + i.length >= o.length || !o.charAt(a + i.length).trim(); if (s && _) return n; } } n = n.parentNode; } return null; } function jt(e) { var i = !1, t = !1; if (window.getComputedStyle) { var n = window.getComputedStyle(e, null); i = n.display, t = n.visibility; } else e.currentStyle && (i = e.currentStyle.display, t = e.currentStyle.visibility); var o = !1, a = pt({ target: e }, "dhx_form_repeat", !1); return a && (o = a.style.height == "0px"), o = o || !e.offsetHeight, i != "none" && t != "hidden" && !o; } function It(e) { return !isNaN(e.getAttribute("tabindex")) && 1 * e.getAttribute("tabindex") >= 0; } function Rt(e) { return !{ a: !0, area: !0 }[e.nodeName.loLowerCase()] || !!e.getAttribute("href"); } function Pt(e) { return !{ input: !0, select: !0, textarea: !0, button: !0, object: !0 }[e.nodeName.toLowerCase()] || !e.hasAttribute("disabled"); } function vt() { return document.head.createShadowRoot || document.head.attachShadow; } function Ge(e) { if (!e || !vt()) return document.body; for (; e.parentNode && (e = e.parentNode); ) if (e instanceof ShadowRoot) return e.host; return document.body; } const ue = { getAbsoluteLeft: function(e) { return this.getOffset(e).left; }, getAbsoluteTop: function(e) { return this.getOffset(e).top; }, getOffsetSum: function(e) { for (var i = 0, t = 0; e; ) i += parseInt(e.offsetTop), t += parseInt(e.offsetLeft), e = e.offsetParent; return { top: i, left: t }; }, getOffsetRect: function(e) { var i = e.getBoundingClientRect(), t = 0, n = 0; if (/Mobi/.test(navigator.userAgent)) { var o = document.createElement("div"); o.style.position = "absolute", o.style.left = "0px", o.style.top = "0px", o.style.width = "1px", o.style.height = "1px", document.body.appendChild(o); var a = o.getBoundingClientRect(); t = i.top - a.top, n = i.left - a.left, o.parentNode.removeChild(o); } else { var s = document.body, _ = document.documentElement, r = window.pageYOffset || _.scrollTop || s.scrollTop, d = window.pageXOffset || _.scrollLeft || s.scrollLeft, l = _.clientTop || s.clientTop || 0, h = _.clientLeft || s.clientLeft || 0; t = i.top + r - l, n = i.left + d - h; } return { top: Math.round(t), left: Math.round(n) }; }, getOffset: function(e) { return e.getBoundingClientRect ? this.getOffsetRect(e) : this.getOffsetSum(e); }, closest: function(e, i) { return e && i ? $e(e, i) : null; }, insertAfter: function(e, i) { i.nextSibling ? i.parentNode.insertBefore(e, i.nextSibling) : i.parentNode.appendChild(e); }, remove: function(e) { e && e.parentNode && e.parentNode.removeChild(e); }, isChildOf: function(e, i) { return i.contains(e); }, getFocusableNodes: function(e) { for (var i = e.querySelectorAll(["a[href]", "area[href]", "input", "select", "textarea", "button", "iframe", "object", "embed", "[tabindex]", "[contenteditable]"].join(", ")), t = Array.prototype.slice.call(i, 0), n = 0; n < t.length; n++) t[n].$position = n; for (t.sort(function(a, s) { return a.tabIndex === 0 && s.tabIndex !== 0 ? 1 : a.tabIndex !== 0 && s.tabIndex === 0 ? -1 : a.tabIndex === s.tabIndex ? a.$position - s.$position : a.tabIndex < s.tabIndex ? -1 : 1; }), n = 0; n < t.length; n++) { var o = t[n]; (It(o) || Pt(o) || Rt(o)) && jt(o) || (t.splice(n, 1), n--); } return t; }, getClassName: ft, locateCss: pt, getRootNode: Ge, hasShadowParent: function(e) { return !!Ge(e); }, isShadowDomSupported: vt, getActiveElement: function() { var e = document.activeElement; return e.shadowRoot && (e = e.shadowRoot.activeElement), e === document.body && document.getSelection && (e = document.getSelection().focusNode || document.body), e; }, getRelativeEventPosition: function(e, i) { var t = document.documentElement, n = function(o) { var a = 0, s = 0, _ = 0, r = 0; if (o.getBoundingClientRect) { var d = o.getBoundingClientRect(), l = document.body, h = document.documentElement || document.body.parentNode || document.body, v = window.pageYOffset || h.scrollTop || l.scrollTop, m = window.pageXOffset || h.scrollLeft || l.scrollLeft, f = h.clientTop || l.clientTop || 0, c = h.clientLeft || l.clientLeft || 0; a = d.top + v - f, s = d.left + m - c, _ = document.body.offsetWidth - d.right, r = document.body.offsetHeight - d.bottom; } else { for (; o; ) a += parseInt(o.offsetTop, 10), s += parseInt(o.offsetLeft, 10), o = o.offsetParent; _ = document.body.offsetWidth - o.offsetWidth - s, r = document.body.offsetHeight - o.offsetHeight - a; } return { y: Math.round(a), x: Math.round(s), width: o.offsetWidth, height: o.offsetHeight, right: Math.round(_), bottom: Math.round(r) }; }(i); return { x: e.clientX - t.clientLeft - n.x + i.scrollLeft, y: e.clientY - t.clientTop - n.y + i.scrollTop }; }, getTargetNode: function(e) { var i; return e.tagName ? i = e : (i = (e = e || window.event).target || e.srcElement).shadowRoot && e.composedPath && (i = e.composedPath()[0]), i; }, getNodePosition: function(e) { var i = 0, t = 0, n = 0, o = 0; if (e.getBoundingClientRect) { var a = e.getBoundingClientRect(), s = document.body, _ = document.documentElement || document.body.parentNode || document.body, r = window.pageYOffset || _.scrollTop || s.scrollTop, d = window.pageXOffset || _.scrollLeft || s.scroll