File

src/app/modules/shared-feature/components/tnc-popup/terms-conditions-popup.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(userService: UserService, resourceService: ResourceService, toasterService: ToasterService, tenantService: TenantService, sanitizer: DomSanitizer, popupControlService: PopupControlService, matDialog: MatDialog)
Parameters :
Name Type Optional
userService UserService No
resourceService ResourceService No
toasterService ToasterService No
tenantService TenantService No
sanitizer DomSanitizer No
popupControlService PopupControlService No
matDialog MatDialog No

Inputs

adminTncVersion
Type : any
reportViewerTncVersion
Type : any
showAcceptTnc
Type : boolean
tncUrl
Type : string

Outputs

close
Type : EventEmitter

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public onClickCheckbox
onClickCheckbox(tncChecked)
Parameters :
Name Optional
tncChecked No
Returns : void
Public onClose
onClose(modalId?: string)
Parameters :
Name Type Optional
modalId string Yes
Returns : void
Public onSubmitTnc
onSubmitTnc(modalId: string)

This method used to submit terms and conditions acceptance

Parameters :
Name Type Optional
modalId string No
Returns : void

Properties

disableContinueBtn
Default value : false
loaderMessage
Type : ILoaderMessage
Default value : { 'loaderMessage': this.resourceService.messages.stmsg.m0129 }
logo
Type : string
Public popupControlService
Type : PopupControlService
Public resourceService
Type : ResourceService
Public sanitizer
Type : DomSanitizer
showLoader
Default value : true
tenantDataSubscription
Type : Subscription
tenantName
Type : string
Public tenantService
Type : TenantService
tncChecked
Default value : false
tncLatestVersionUrl
Type : any
Public toasterService
Type : ToasterService
Public unsubscribe
Default value : new Subject<void>()
Private userProfile
Type : IUserProfile

user profile details.

Public userService
Type : UserService
userSubscription
Type : Subscription
import { Component, OnInit, Input, EventEmitter, Output, OnDestroy } from '@angular/core';
import { UserService, TenantService } from '@sunbird/core';
import { Subscription, Subject } from 'rxjs';
import { ResourceService, ToasterService } from '@sunbird/shared';
import { IUserProfile, ILoaderMessage } from '@sunbird/shared';
import { DomSanitizer } from '@angular/platform-browser';
import * as _ from 'lodash-es';
import { PopupControlService } from '../../../../service/popup-control.service';
import { MatDialog } from '@angular/material/dialog';

@Component({
  selector: 'app-tnc-popup',
  templateUrl: './terms-conditions-popup.component.html',
  styleUrls: ['./terms-conditions-popup.component.scss']
})

export class TermsAndConditionsPopupComponent implements OnInit, OnDestroy {
  @Input() tncUrl: string;
  @Input() showAcceptTnc: boolean;
  @Input() adminTncVersion: any;
  @Input() reportViewerTncVersion: any;
  @Output() close = new EventEmitter<any>();

  /**
   * user profile details.
   */
  private userProfile: IUserProfile;
  public unsubscribe = new Subject<void>();
  tenantDataSubscription: Subscription;
  userSubscription: Subscription;
  logo: string;
  tenantName: string;
  tncLatestVersionUrl: any;
  tncChecked = false;
  disableContinueBtn = false;
  showLoader = true;
  loaderMessage: ILoaderMessage = {
    'loaderMessage': this.resourceService.messages.stmsg.m0129
  };

  constructor(public userService: UserService, public resourceService: ResourceService,
    public toasterService: ToasterService, public tenantService: TenantService,
    public sanitizer: DomSanitizer, public popupControlService: PopupControlService, private matDialog: MatDialog) {
  }

  ngOnInit() {
    this.popupControlService.changePopupStatus(false);
    if (this.tncUrl) {
      this.tncLatestVersionUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.tncUrl);
    } else {
      this.userSubscription = this.userService.userData$.subscribe(
        (user: any) => {
          if (user && !user.err) {
            this.userProfile = user.userProfile;
            this.tncLatestVersionUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.userProfile.tncLatestVersionUrl);
          } else if (user.err) {
            this.toasterService.error(this.resourceService.messages.emsg.m0005);
          }
        });
    }
    this.tenantDataSubscription = this.tenantService.tenantData$.subscribe(
      data => {
        if (data && !data.err) {
          this.logo = data.tenantData.logo;
          this.tenantName = data.tenantData.titleName;
        }
      }
    );
  }

  /**
   * This method used to submit terms and conditions acceptance
   */
  public onSubmitTnc(modalId: string) {
    const requestBody = {
      request: {
        version: _.get(this.userProfile, 'tncLatestVersion')
      }
    };
    if (_.get(this.userService, 'userProfile.managedBy')) {
      requestBody.request['userId'] = this.userService.userid;
    }
    if (this.adminTncVersion || this.reportViewerTncVersion) {
      requestBody.request['version'] = this.adminTncVersion || this.reportViewerTncVersion;
      requestBody.request['tncType'] = this.adminTncVersion ? 'orgAdminTnc' : 'reportViewerTnc';
    }

    this.disableContinueBtn = true;
    this.userService.acceptTermsAndConditions(requestBody).subscribe(res => {
      this.onClose(modalId);
    }, err => {
      this.disableContinueBtn = false;
      this.toasterService.error(this.resourceService.messages.fmsg.m0085);
    });
  }

  public onClickCheckbox(tncChecked) {
    this.disableContinueBtn = !tncChecked;
  }

  public onClose(modalId?: string) {
    if (modalId) {
      const dialogRef = this.matDialog.getDialogById(modalId);
      dialogRef && dialogRef.close();
    }
    this.close.emit();
    this.popupControlService.changePopupStatus(true);
  }

  ngOnDestroy() {
    this.popupControlService.changePopupStatus(true);
    if (this.userSubscription) {
      this.userSubscription.unsubscribe();
    }
    if (this.tenantDataSubscription) {
      this.tenantDataSubscription.unsubscribe();
    }
    this.unsubscribe.next();
    this.unsubscribe.complete();
  }

}
<app-modal-wrapper [config]="{disableClose: (tncUrl && !reportViewerTncVersion) ? false : true, size: 'large'}"
  (dismiss)="(tncUrl && !reportViewerTncVersion) ? onClose() : ''">
  <ng-template sbModalContent let-data>
    <div class="sb-modal sb-modal-termscondition">

      <div class="transition ui dimmer page modals active visible">
        <div class="ui modal transition active visible large">

          <button aria-label="close dialog" mat-dialog-close class="mat-close-btn"
            *ngIf="(tncUrl && !reportViewerTncVersion) ? true : false">
            <span>&times;</span>
          </button>

          <!--Header-->
          <div class="sb-modal-header" role="heading" aria-level="1">
            {{resourceService?.frmelmnts?.lbl?.termsAndCond}}&lrm;
          </div>
          <!--/Header-->

          <!--Content-->
          <div class="sb-modal-content pl-0 pr-8">
            <div class="d-flex flex-jc-center mb-10 terms-modal-logo">
              <img class="image centered" alt={{tenantName}} height="45" src="{{logo}}">
            </div>
            <div class="fs-1 font-weight-bold d-flex flex-jc-center mb-16">
              {{resourceService?.frmelmnts?.lbl?.termsAndCond}}&lrm;</div>
            <app-loader *ngIf="showLoader" [data]='loaderMessage'></app-loader>
            <form class="ui form d-flex flex-jc-center terms-and-cond-form">
              <iframe id="serviceFrameSend" [src]="tncLatestVersionUrl"
                title="{{resourceService?.frmelmnts?.lbl?.termsAndCondAgree}}"
                attr.aria-label="{{resourceService?.frmelmnts?.lbl?.termsAndCondAgree}}" width="100%" height="200px"
                class="toc-page" frameborder="0" (load)="showLoader = false"></iframe>
            </form>
            <label *ngIf="!tncUrl || showAcceptTnc" class="d-flex flex-jc-center flex-ai-center mt-16 mb-0">
              <input type="checkbox" role="checkbox" [(ngModel)]="tncChecked" value="true" tabindex="0"
                (click)="onClickCheckbox(tncChecked)" class="mr-10 cursor-pointer"><span>
                {{resourceService?.frmelmnts?.lbl?.termsAndCondAgree}}</span>
            </label>
          </div>

          <!--/Content-->

          <!--Actions-->
          <div class="sb-modal-actions">
            <button class="sb-btn sb-btn-normal sb-btn-primary" [ngClass]="tncChecked ? '' : 'sb-btn-disabled'"
              [disabled]="!disableContinueBtn" (click)="onSubmitTnc(data?.id)" tabindex="0"
              *ngIf="!tncUrl || showAcceptTnc">
              {{resourceService?.frmelmnts?.lbl?.continue}}
            </button>
          </div>
          <!--/Actions-->
        </div>
      </div>
    </div>
  </ng-template>
</app-modal-wrapper>

./terms-conditions-popup.component.scss


@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;

.terms-and-cond-form{
  height: calc(100vh - 21.875rem);
 iframe{
   height: 100%;
 }
}
@include respond-below(sm) {

  ::ng-deep {

    .sb-modal-termscondition {
      &.sb-modal {
        .ui.modal.normal {
          width: 100% !important;
          margin: 0px !important;
          left: 0px !important;
          max-width: 100%;
          height: 100%;
          .sb-modal-content {
            height: calc(100% - 6rem);
            max-height: 100%;
            overflow: hidden;
          }
        }
        .toc-page { 
          height: 100%;
        }
      }
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""