2017-12-11 19:29:57 -05:00
|
|
|
import { Component } from "@angular/core";
|
|
|
|
import { DialogRef, ModalComponent } from "ngx-modialog";
|
|
|
|
import { WidgetComponent } from "../widget.component";
|
2017-12-15 01:46:17 -05:00
|
|
|
import { ScalarService } from "../../../shared/services/scalar.service";
|
2017-12-11 19:29:57 -05:00
|
|
|
import { ConfigModalContext } from "../../../integration/integration.component";
|
|
|
|
import { ToasterService } from "angular2-toaster";
|
2017-12-14 00:44:20 -05:00
|
|
|
import { EditableWidget, WIDGET_GOOGLE_CALENDAR } from "../../../shared/models/widget";
|
2017-12-11 19:29:57 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "my-googlecalendarwidget-config",
|
|
|
|
templateUrl: "googlecalendar-config.component.html",
|
|
|
|
styleUrls: ["googlecalendar-config.component.scss", "./../../config.component.scss"],
|
|
|
|
})
|
|
|
|
export class GoogleCalendarWidgetConfigComponent extends WidgetComponent implements ModalComponent<ConfigModalContext> {
|
|
|
|
|
|
|
|
constructor(public dialog: DialogRef<ConfigModalContext>,
|
|
|
|
toaster: ToasterService,
|
|
|
|
scalarService: ScalarService,
|
|
|
|
window: Window) {
|
|
|
|
super(
|
2017-12-14 00:44:20 -05:00
|
|
|
window,
|
2017-12-11 19:29:57 -05:00
|
|
|
toaster,
|
|
|
|
scalarService,
|
|
|
|
dialog.context.roomId,
|
|
|
|
dialog.context.integration,
|
|
|
|
dialog.context.integrationId,
|
2017-12-14 00:44:20 -05:00
|
|
|
WIDGET_GOOGLE_CALENDAR,
|
2017-12-11 19:29:57 -05:00
|
|
|
"Google Calendar",
|
|
|
|
"", // we intentionally don't specify the wrapper so we can control the behaviour
|
|
|
|
"googleCalendar" // scalar wrapper
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
protected onWidgetsDiscovered() {
|
|
|
|
for (const widget of this.widgets) {
|
|
|
|
if (widget.data.dimSrc) {
|
|
|
|
// Convert legacy Dimension widgets to use src
|
|
|
|
widget.data.src = widget.data.dimSrc;
|
|
|
|
}
|
2017-12-11 19:29:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public validateAndAddWidget() {
|
2017-12-14 00:44:20 -05:00
|
|
|
this.setCalendarUrl(this.newWidget);
|
|
|
|
this.addWidget();
|
2017-12-11 19:29:57 -05:00
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
public validateAndSaveWidget(widget: EditableWidget) {
|
|
|
|
this.setCalendarUrl(widget);
|
2017-12-11 19:29:57 -05:00
|
|
|
this.saveWidget(widget);
|
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
private setCalendarUrl(widget: EditableWidget) {
|
|
|
|
const encodedId = encodeURIComponent(widget.dimension.newData.src);
|
|
|
|
widget.dimension.newUrl = window.location.origin + "/widget/gcal?calendarId=" + encodedId;
|
2017-12-11 19:29:57 -05:00
|
|
|
}
|
|
|
|
}
|