Merge pull request #2341 from dpalou/MOBILE-3390
MOBILE-3390 database: Support URL force name and autolinkmain
commit
dc3d0d7138
|
@ -4,4 +4,7 @@
|
|||
<core-input-errors *ngIf="error && mode == 'edit'" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>
|
||||
</span>
|
||||
|
||||
<a *ngIf="isShowOrListMode() && value && value.content" [href]="value.content" core-link capture="true">{{value.content}}</a>
|
||||
<ng-container *ngIf="isShowOrListMode() && value && value.content">
|
||||
<a *ngIf="autoLink" [href]="value.content" core-link capture="true">{{ displayValue }}</a>
|
||||
<span *ngIf="!autoLink">{{ displayValue }}</span>
|
||||
</ng-container>
|
|
@ -24,6 +24,9 @@ import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-
|
|||
})
|
||||
export class AddonModDataFieldUrlComponent extends AddonModDataFieldPluginComponent {
|
||||
|
||||
protected autoLink = false;
|
||||
protected displayValue = '';
|
||||
|
||||
constructor(protected fb: FormBuilder) {
|
||||
super(fb);
|
||||
}
|
||||
|
@ -43,4 +46,36 @@ export class AddonModDataFieldUrlComponent extends AddonModDataFieldPluginCompon
|
|||
|
||||
this.addControl('f_' + this.field.id, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate data for show or list mode.
|
||||
*/
|
||||
protected calculateShowListData(): void {
|
||||
if (!this.value || !this.value.content) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = this.value.content;
|
||||
const text = this.field.param2 || this.value.content1; // Param2 forces the text to display.
|
||||
|
||||
this.autoLink = parseInt(this.field.param1, 10) === 1;
|
||||
|
||||
if (this.autoLink) {
|
||||
this.displayValue = text || url;
|
||||
} else {
|
||||
// No auto link, always display the URL.
|
||||
this.displayValue = url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update value being shown.
|
||||
*/
|
||||
protected updateValue(value: any): void {
|
||||
super.updateValue(value);
|
||||
|
||||
if (this.isShowOrListMode()) {
|
||||
this.calculateShowListData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue