Skip to content

Instantly share code, notes, and snippets.

@RoyiNamir
Created August 22, 2018 08:48
Show Gist options
  • Save RoyiNamir/209a1bbf1bad7413ef4a585f8125fa50 to your computer and use it in GitHub Desktop.
Save RoyiNamir/209a1bbf1bad7413ef4a585f8125fa50 to your computer and use it in GitHub Desktop.
import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {TranslateService} from "@ngx-translate/core";
import {ObservableArray} from "tns-core-modules/data/observable-array";
import {Page} from "tns-core-modules/ui/page";
import {BaseComponent} from "~/core/classes/base-component.component";
import {ModalService} from "../../../core/services/modal.service";
import {RoutingService} from "../../../core/services/routing.service";
import {ConfirmComponent} from "../../../shared/components/dialogs/confirm/confirm.component";
@Component({
moduleId : module.id,
selector : 'app-davidcard',
templateUrl: './davidcard.component.html',
styleUrls : ['./davidcard.component.scss']
})
export class DavidcardComponent extends BaseComponent implements OnInit
{
templateSelector(item: any, index: number, items: any): string {
console.log("here: " + item.type);
return item.type ;
}
dataItems: ObservableArray<any> = new ObservableArray([
{
name : "a1",
type : "green",
description: "d1"
},
{
name : "a11",
type : "green",
description: "d11"
},
{
name : "a21",
type : "green",
description: "d12"
}
]);
constructor(private routingService: RoutingService,
private modalService: ModalService,
public page: Page,
private translateService: TranslateService,
private vcRef: ViewContainerRef)
{
super(page);
}
ngOnInit()
{
}
public getRefundClicked(): void
{
if (this.shouldOpenPopup())
{
let dialogHeaderKey: string = "Resources.dc_post_paid_dialog_header";
let dialogBodyKey: string = "Resources.dc_post_paid_dialog_body";
let creditCardKey: string = "Resources.general_credit_card";
let davidCardKey: string = "Resources.general_david_card";
let res = this.translateService.instant([
dialogHeaderKey,
dialogBodyKey,
creditCardKey,
davidCardKey
]);
this.modalService.show(ConfirmComponent, {
viewContainerRef: this.vcRef,
context : {
isModal : true,
header : res[dialogHeaderKey],
body : res[dialogBodyKey],
confirmButtonText: res[creditCardKey],
cancelButtonText : res[davidCardKey]
},
fullscreen : false
})
.then((buttonClicked: string) =>
{
if (buttonClicked === res[creditCardKey])
{
//timeout used to avoid a bug where navigating to postpaid would immediately navigate to home->davidcard
setTimeout(() =>
{
this.navigateToPostPaid();
}, 50);
}
else
{
if (buttonClicked === res[davidCardKey])
{
//timeout here to be symmetric with timeout for navigating to postpaid
setTimeout(() =>
{
this.navigateToHistory();
}, 50);
}
}
});
}
else
{
this.navigateToPostPaid();
}
}
private shouldOpenPopup(): boolean
{
return true;
}
private navigateToHistory(): void
{
this.routingService.routeTo("/app/home/history");
}
private navigateToPostPaid(): void
{
this.routingService.routeTo("/app/home/postPaid");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment