mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Code improvements
- shared global declarations - reduced hyperlink-related repetitive code
This commit is contained in:
@@ -18,14 +18,14 @@
|
||||
import { Input, AfterViewInit, Output, EventEmitter } from '@angular/core';
|
||||
import { FormFieldModel } from './core/index';
|
||||
|
||||
declare let __moduleName: string;
|
||||
declare var componentHandler;
|
||||
|
||||
/**
|
||||
* Base widget component.
|
||||
*/
|
||||
export class WidgetComponent implements AfterViewInit {
|
||||
|
||||
static DEFAULT_HYPERLINK_URL: string = '#';
|
||||
static DEFAULT_HYPERLINK_SCHEME: string = 'http://';
|
||||
|
||||
@Input()
|
||||
field: FormFieldModel;
|
||||
|
||||
@@ -67,4 +67,22 @@ export class WidgetComponent implements AfterViewInit {
|
||||
this.fieldChanged.emit(field);
|
||||
}
|
||||
|
||||
protected getHyperlinkUrl(field: FormFieldModel) {
|
||||
let url = WidgetComponent.DEFAULT_HYPERLINK_URL;
|
||||
if (field && field.hyperlinkUrl) {
|
||||
url = field.hyperlinkUrl;
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
url = `${WidgetComponent.DEFAULT_HYPERLINK_SCHEME}${url}`;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
protected getHyperlinkText(field: FormFieldModel) {
|
||||
if (field) {
|
||||
return field.displayText || field.hyperlinkUrl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user