const WidgetConfigurator = { template: `

{{ $t("comp.title") }}

{{ $t("shared.cancel") }} {{ $t("shared.save") }}
{{ $t("comp.search.showFilter") }} {{ $t("comp.search.pagination") }} {{ $t("comp.search.showEventCallyLink") }} {{ $t("comp.search.printButton") }}
{{ $t("comp.preview") }}
`, i18n: { messages: { en: { comp: { title: "Widget configurator", successMessage: "Widget successfully saved", preview: "Preview", tabSettings: "Serrings", tabStyles: "Styles", generic: { fontFamily: "Font family", padding: "Padding", backgroundColor: "Background color", textColor: "Text color", linkColor: "Link color", borderColor: "Border color", color: "Color", disabled: "Deactivated", active: "Activ", }, calendar: { iFrameHeight: "Height", eventBackgroundColor: "Event color", calendarType: "Calendar type", }, search: { iFrameMinHeight: "Min. Height", iFrameMaxHeight: "Max. Height", eventListId: "Event list", view: "Display", showFilter: "Filter", showEventCallyLink: "Link", layout: "Layout", eventsPerPage: "Events per page", event: "Event", eventName: "Event name", eventDate: "Event datum", eventInfo: "Event info", eventBadgeWarning: "Event warning badge", eventBadgeInfo: "Event info badge", filterLabel: "Filter label", filterInput: "Filter input", filterButton: "Filter button", pagination: "Pagination", printButton: "Print button", }, }, }, de: { comp: { title: "Widget Konfigurator", successMessage: "Widget erfolgreich gespeichert", preview: "Vorschau", tabSettings: "Einstellungen", tabStyles: "Styles", generic: { fontFamily: "Schriftart", padding: "Abstand", backgroundColor: "Hintergrundfarbe", textColor: "Textfarbe", linkColor: "Link-Farbe", borderColor: "Rahmen-Farbe", color: "Farbe", disabled: "Deaktiviert", active: "Aktiv", }, calendar: { iFrameHeight: "Höhe", eventBackgroundColor: "Event Farbe", calendarType: "Kalender Typ", }, search: { iFrameMinHeight: "Min. Höhe", iFrameMaxHeight: "Max. Höhe", eventListId: "Veranstaltungsliste", view: "Anzeige", showFilter: "Filter", showEventCallyLink: "Link", layout: "Layout", eventsPerPage: "Events pro Seite", event: "Event", eventName: "Event-Name", eventDate: "Event-Datum", eventInfo: "Event-Info", eventBadgeWarning: "Event Warnungszeichen", eventBadgeInfo: "Event Infozeichen", filterLabel: "Filter-Label", filterInput: "Filter-Eingabe", filterButton: "Filter-Button", pagination: "Paginierung", printButton: "Drucken-Button", }, }, }, }, }, data: () => ({ iFrameActive: true, iFrameCounter: 0, previewSize: '100%', previewSizes: [ { text: 'Desktop', value: '100%' }, { text: 'Tablet', value: '768px' }, { text: 'Mobile', value: '400px' }, ], previewBackgroundColor: '#f8f9fa', isLoading: false, isSubmitting: false, customWidget: null, form: { search: { layout: "card", iFrameMinHeight: 400, iFrameMaxHeight: "Infinity", iFrameAutoResize: true, organizationId: null, eventListId: null, eventsPerPage: 10, showFilter: true, showPagination: true, showPrintButton: false, showEventCallyLink: true, fontFamily: "", background: "#ffffff", textColor: "#212529", padding: "1rem", linkColor: "#007bff", buttonBackgroundColor: "#007bff", buttonBorderColor: "#007bff", buttonTextColor: "#ffffff", printButtonBackgroundColor: "#6c757d", printButtonBorderColor: "#6c757d", printButtonTextColor: "#ffffff", filterLabelBackgroundColor: "#e9ecef", filterLabelBorderColor: "#ced4da", filterLabelTextColor: "#495057", filterInputBackgroundColor: "#ffffff", filterInputBorderColor: "#ced4da", filterInputTextColor: "#495057", eventBackgroundColor: "#ffffff", eventBorderColor: "#00000020", eventNameTextColor: "#000000", eventDateTextColor: "#212529", eventInfoTextColor: "#6c757d", pagingBorderColor: "#dee2e6", pagingColor: "#007bff", pagingTextColor: "#007bff", pagingActiveTextColor: "#ffffff", pagingDisabledTextColor: "#6c757d", eventBadgeWarningBackgroundColor: "#ffc107", eventBadgeWarningTextColor: "#212529", eventBadgeInfoBackgroundColor: "#17a2b8", eventBadgeInfoTextColor: "#ffffff", }, calendar: { iFrameHeight: 600, iFrameAutoResize: false, organizationId: null, eventListId: null, calendarType: "week", eventBackgroundColor: "#007bff", } }, calendarTypes: [ { value: "week", text: 'Woche' }, { value: 'month', text: 'Monat' }, ], searchLayouts: [ { value: "card", text: 'Karten' }, { value: 'text', text: 'Text' }, ], widgetType: "search", widgetTypes: [], name: "Widget", searchEventList: null, }), computed: { iFrameSource() { return `${window.location.origin}/custom_widget/${this.widgetType}`; }, organizationId() { return this.$route.params.organization_id; }, customWidgetId() { return this.$route.params.custom_widget_id; }, settings() { return this.form[this.widgetType]; }, iFrameResizerOptions() { return { autoResize: this.settings.iFrameAutoResize, minHeight: this.settings.iFrameMinHeight != null ? this.settings.iFrameMinHeight : this.settings.iFrameHeight, maxHeight: this.settings.iFrameMaxHeight != null ? this.settings.iFrameMaxHeight : this.settings.iFrameHeight, scrolling: "omit", }; }, eventListFetchUrl() { return `/api/v1/organizations/${this.organizationId}/event-lists?name={query}`; }, }, mounted() { this.isLoading = false; this.customWidget = null; this.widgetTypes = [ { value: "search", text: this.$t("shared.models.customWidget.widgetTypeSearch") }, { value: "calendar", text: this.$t("shared.models.customWidget.widgetTypeCalendar") }, ] this.form.search.organizationId = this.organizationId; this.form.calendar.organizationId = this.organizationId; if (this.customWidgetId == null) { this.initResizer(); } else { this.loadFormData(); } }, watch: { settings: { handler: function (val, oldVal) { this.updatePreview(); }, deep: true }, iFrameResizerOptions: { handler: function (val, oldVal) { this.reloadIframe(); }, deep: true }, searchEventList: function(val) { this.form.search.eventListId = val != null ? val.id : null; }, previewSize: function(val) { this.resizePreview(); } }, methods: { reloadIframe() { this.iFrameActive = false; this.iFrameCounter++; this.iFrameActive = true; this.initResizer(); }, initResizer() { const vm = this; Vue.nextTick(function () { iFrameResize({ autoResize: vm.iFrameResizerOptions.autoResize, minHeight: vm.iFrameResizerOptions.minHeight, maxHeight: vm.iFrameResizerOptions.maxHeight, scrolling: vm.iFrameResizerOptions.scrolling, onMessage: function(m) {}, onInit: function() { vm.updatePreview() }, }, '.preview_iframe'); }); }, updatePreview() { const resizer = this.$refs.previewIframe.iFrameResizer; if (resizer === undefined) { return; } resizer.sendMessage({'type': 'EVENTCALLY_WIDGET_SETTINGS_UPDATE_EVENT', 'data': this.settings}); }, resizePreview() { const resizer = this.$refs.previewIframe.iFrameResizer; if (resizer === undefined) { return; } resizer.resize(); }, loadFormData() { axios .get(`/api/v1/custom-widgets/${this.customWidgetId}`, { withCredentials: true, handleLoading: this.handleLoading, }) .then((response) => { this.customWidget = response.data; this.widgetType = this.customWidget.widget_type; this.name = this.customWidget.name; for (var key in this.customWidget.settings) { this.settings[key] = this.customWidget.settings[key]; } this.initResizer(); }); }, handleLoading(isLoading) { this.isLoading = isLoading; }, submitForm() { let data = { 'widget_type': this.widgetType, 'name': this.name, 'settings': this.settings, }; if (this.customWidgetId == null) { axios .post(`/api/v1/organizations/${this.organizationId}/custom-widgets`, data, { withCredentials: true, handleLoading: this.handleSubmitting, }) .then(() => { this.$root.makeSuccessToast(this.$t("comp.successMessage")) this.goBack() }) } else { axios .put(`/api/v1/custom-widgets/${this.customWidgetId}`, data, { withCredentials: true, handleLoading: this.handleSubmitting, }) .then(() => { this.$root.makeSuccessToast(this.$t("comp.successMessage")) this.goBack() }) } }, handleSubmitting(isLoading) { this.isSubmitting = isLoading; }, goBack() { window.location.href = `/manage/admin_unit/${this.organizationId}/custom-widgets`; }, }, };