src/app/blocks/block-prop-instagram.ts
Compbaser
changeDetection | ChangeDetectionStrategy.OnPush |
host | { |
selector | block-prop-instagram |
template |
|
jsonMode
|
Type: |
Defined in src/app/blocks/block-prop-instagram.ts:48
|
setBlockData
|
|
Defined in src/app/blocks/block-prop-instagram.ts:51
|
constructor(fb: FormBuilder, cd: ChangeDetectorRef, bs: BlockService, ngmslibService: NgmslibService)
|
Defined in src/app/blocks/block-prop-instagram.ts:36
|
Protected _render |
_render()
|
Defined in src/app/blocks/block-prop-instagram.ts:60
|
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Defined in src/app/blocks/block-prop-instagram.ts:67
|
Returns :
void
|
_onCreateToken |
_onCreateToken()
|
Defined in src/app/blocks/block-prop-instagram.ts:71
|
Returns :
void
|
Protected saveToStore |
saveToStore()
|
Defined in src/app/blocks/block-prop-instagram.ts:80
|
Returns :
void
|
destroy |
destroy()
|
Defined in src/app/blocks/block-prop-instagram.ts:90
|
Returns :
void
|
m_blockData |
m_blockData: |
Defined in src/app/blocks/block-prop-instagram.ts:36
|
m_contGroup |
m_contGroup: |
Defined in src/app/blocks/block-prop-instagram.ts:35
|
m_formInputs |
m_formInputs: |
Defined in src/app/blocks/block-prop-instagram.ts:34
|
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";
@Component({
selector: 'block-prop-instagram',
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">
<div *ngIf="!jsonMode">
<ul class="list-group">
<li class="list-group-item">
<span i18n>token</span>
<input type="text" [formControl]="m_contGroup.controls['token']"/>
</li>
<li class="list-group-item">
<button class="btn btn-default" (click)="_onCreateToken()"><span i18n>create instagram access token</span></button>
</li>
</ul>
</div>
<div *ngIf="jsonMode">
<block-prop-json-player [setBlockData]="m_blockData"></block-prop-json-player>
</div>
</div>
</form>
`
})
export class BlockPropInstagram 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({
'token': ['']
});
_.forEach(this.m_contGroup.controls, (value, key: string) => {
this.m_formInputs[key] = this.m_contGroup.controls[key] as FormControl;
})
}
@Input() jsonMode: boolean;
@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;
}
}
private _render() {
var domPlayerData: XMLDocument = this.m_blockData.playerDataDom
var jXMLdata = jXML(domPlayerData).find('Json').find('Data');
this.m_formInputs['token'].setValue(jXMLdata.attr('token'));
// this.cd.markForCheck();
}
ngAfterViewInit() {
this._render();
}
_onCreateToken() {
var win = window.open('http://instagram.signage.me', '_blank');
if (win) {
win.focus();
} else {
bootbox.alert('Browser popups are blocked, please enable and try again');
}
}
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 item = jXML(domPlayerData).find('Json').find('Data');
jXML(item).attr('token', this.m_contGroup.value.token);
this.bs.setBlockPlayerData(this.m_blockData, domPlayerData);
}
destroy() {
}
}