File

src/app/blocks/block-prop-video.ts

Extends

Compbaser

Implements

AfterViewInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
host {
    "(input-blur)":"saveToStore($event)"
}
selector block-prop-video
template
<small class="debug">{{me}}</small>
<form novalidate autocomplete="off" class="inner5" [formGroup]="m_contGroup">
    <div class="row">
        <ul class="list-group">
            <li *ngIf="external" class="list-group-item">
                <span i18n>url</span><br/>
                <input class="default-prop-width" type="text" [formControl]="m_contGroup.controls['url']"/>
            </li>
            <li *ngIf="!external" class="list-group-item">
                <span i18n>maintain aspect ratio</span>
                <div class="material-switch pull-right">
                    <input #imageRatio (change)="_toggleAspectRatio(imageRatio.checked)"
                           [formControl]="m_contGroup.controls['maintain']"
                           id="imageRatio"
                           name="imageRatio" type="checkbox"/>
                    <label for="imageRatio" class="label-primary"></label>
                </div>
            </li>
        </ul>
    </div>
</form>

Inputs

external

Type: boolean

Default value: false

setBlockData

Constructor

constructor(fb: FormBuilder, cd: ChangeDetectorRef, bs: BlockService, ngmslibService: NgmslibService)

Methods

_toggleAspectRatio
_toggleAspectRatio(i_value: any)

Toggle maintain aspect ratio


Returns : void
Protected _render
_render()
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
Protected saveToStore
saveToStore()
Returns : void
destroy
destroy()
Returns : void

Properties

m_blockData
m_blockData: IBlockData
m_contGroup
m_contGroup: FormGroup
m_formInputs
m_formInputs: {}
import {AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, Input} from "@angular/core";
import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
import {BlockService, IBlockData} from "./block-service";
import {Compbaser, NgmslibService} from "ng-mslib";
import * as _ from "lodash";
import {urlRegExp} from "../../Lib";

@Component({
    selector: 'block-prop-video',
    host: {'(input-blur)': 'saveToStore($event)'},
    changeDetection: ChangeDetectionStrategy.OnPush,
    template: `
        <small class="debug">{{me}}</small>
        <form novalidate autocomplete="off" class="inner5" [formGroup]="m_contGroup">
            <div class="row">
                <ul class="list-group">
                    <li *ngIf="external" class="list-group-item">
                        <span i18n>url</span><br/>
                        <input class="default-prop-width" type="text" [formControl]="m_contGroup.controls['url']"/>
                    </li>
                    <li *ngIf="!external" class="list-group-item">
                        <span i18n>maintain aspect ratio</span>
                        <div class="material-switch pull-right">
                            <input #imageRatio (change)="_toggleAspectRatio(imageRatio.checked)"
                                   [formControl]="m_contGroup.controls['maintain']"
                                   id="imageRatio"
                                   name="imageRatio" type="checkbox"/>
                            <label for="imageRatio" class="label-primary"></label>
                        </div>
                    </li>
                </ul>
            </div>
        </form>
    `
})
export class BlockPropVideo extends Compbaser implements AfterViewInit {
    m_formInputs = {};
    m_contGroup: FormGroup;
    m_blockData: IBlockData;

    constructor(private fb: FormBuilder, private cd: ChangeDetectorRef, private bs: BlockService, private ngmslibService: NgmslibService) {
        super();
        this.m_contGroup = fb.group({
            'url': ['', [Validators.pattern(urlRegExp)]],
            'maintain': []
        });
        _.forEach(this.m_contGroup.controls, (value, key: string) => {
            this.m_formInputs[key] = this.m_contGroup.controls[key] as FormControl;
        })
    }

    @Input() external: boolean = false;

    @Input()
    set setBlockData(i_blockData) {
        if (this.m_blockData && this.m_blockData.blockID != i_blockData.blockID) {
            this.m_blockData = i_blockData;
            this._render();
        } else {
            this.m_blockData = i_blockData;
        }
    }

    /**
     Toggle maintain aspect ratio
     **/
    _toggleAspectRatio(i_value) {
        i_value = StringJS(i_value).booleanToNumber()
        var domPlayerData = this.m_blockData.playerDataDom;
        var xSnippet = jXML(domPlayerData).find('AspectRatio');
        jXML(xSnippet).attr('maintain', i_value);
        this.bs.setBlockPlayerData(this.m_blockData, domPlayerData)
    }

    private _render() {
        var domPlayerData: XMLDocument = this.m_blockData.playerDataDom
        if (this.external) {
            var xSnippet = jXML(domPlayerData).find('LINK');
            this.m_formInputs['url'].setValue(xSnippet.attr('src'));
        } else {
            var xSnippet = jXML(domPlayerData).find('AspectRatio');
            var maintain = StringJS(jXML(xSnippet).attr('maintain')).booleanToNumber();
            this.m_formInputs['maintain'].setValue(maintain);
        }
    }

    ngAfterViewInit() {
        this._render();
    }

    private saveToStore() {
        con(this.m_contGroup.status + ' ' + JSON.stringify(this.ngmslibService.cleanCharForXml(this.m_contGroup.value)));
        if (this.m_contGroup.status != 'VALID')
            return;
        var domPlayerData: XMLDocument = this.m_blockData.playerDataDom;
        var xSnippet = jXML(domPlayerData).find('LINK');
        xSnippet.attr('src', this.m_contGroup.value.url);
        this.bs.setBlockPlayerData(this.m_blockData, domPlayerData);
    }

    destroy() {
    }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""