matrix-dimension/web/app/configs/widget/etherpad/etherpad-config.component.ts

62 lines
2.3 KiB
TypeScript
Raw Normal View History

2017-11-18 21:33:47 +00:00
import { Component } from "@angular/core";
2017-12-09 23:31:36 +00:00
import { DialogRef, ModalComponent } from "ngx-modialog";
2017-11-18 21:33:47 +00:00
import { WidgetComponent } from "../widget.component";
import { ScalarService } from "../../../shared/scalar.service";
import { ConfigModalContext } from "../../../integration/integration.component";
import { ToasterService } from "angular2-toaster";
import { WIDGET_ETHERPAD } from "../../../shared/models/widget";
2017-12-09 23:31:36 +00:00
import { EtherpadWidgetIntegration } from "../../../shared/models/integration";
2017-11-18 21:33:47 +00:00
@Component({
selector: "my-etherpadwidget-config",
templateUrl: "etherpad-config.component.html",
styleUrls: ["etherpad-config.component.scss", "./../../config.component.scss"],
})
export class EtherpadWidgetConfigComponent extends WidgetComponent implements ModalComponent<ConfigModalContext> {
2017-12-09 23:31:36 +00:00
private widgetOpts: EtherpadWidgetIntegration;
2017-11-18 21:33:47 +00:00
constructor(public dialog: DialogRef<ConfigModalContext>,
toaster: ToasterService,
scalarService: ScalarService,
window: Window) {
super(
window,
2017-11-18 21:33:47 +00:00
toaster,
scalarService,
dialog.context.roomId,
dialog.context.integration,
2017-11-18 21:33:47 +00:00
dialog.context.integrationId,
WIDGET_ETHERPAD,
2017-11-18 21:33:47 +00:00
"Etherpad Widget",
"generic", // wrapper
"etherpad" // scalar wrapper
);
2017-12-09 23:31:36 +00:00
this.widgetOpts = <EtherpadWidgetIntegration>dialog.context.integration;
2017-11-18 21:33:47 +00:00
}
public validateAndAddWidget() {
if (this.newWidget.dimension.newUrl.startsWith("http://") || this.newWidget.dimension.newUrl.startsWith("https://")) {
this.newWidget.dimension.newName = "Etherpad";
2017-11-18 22:05:15 +00:00
} else {
this.newWidget.dimension.newName = this.newWidget.dimension.newUrl;
this.newWidget.dimension.newUrl = this.generatePadUrl(this.newWidget.dimension.newName);
2017-11-18 22:05:15 +00:00
}
2017-12-09 23:31:36 +00:00
this.addWidget();
2017-11-18 21:33:47 +00:00
}
2017-12-09 23:31:36 +00:00
private generatePadUrl(forName: string): string {
let template = "https://demo.riot.im/etherpad/p/$roomId_$padName";
if (this.widgetOpts && this.widgetOpts.defaultUrl) {
template = this.widgetOpts.defaultUrl;
2017-11-18 21:33:47 +00:00
}
2017-12-09 23:31:36 +00:00
template = template.replace("$roomId", encodeURIComponent(this.roomId));
template = template.replace("$padName", encodeURIComponent(forName));
return template;
}
2017-11-18 21:33:47 +00:00
}