1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119

ash / webui / scanning / resources / multi_page_scan.ts [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'chrome://resources/ash/common/cr_elements/cros_color_overrides.css.js';
import 'chrome://resources/ash/common/cr_elements/cr_button/cr_button.js';
import './scanning_fonts.css.js';
import '/strings.m.js';

import {I18nMixin} from 'chrome://resources/ash/common/cr_elements/i18n_mixin.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {getTemplate} from './multi_page_scan.html.js';
import {AppState} from './scanning_app_types.js';
import {ScanningBrowserProxyImpl} from './scanning_browser_proxy.js';

/**
 * @fileoverview
 * 'multi-page-scan' shows the available actions for a multi-page scan.
 */

const MultiPageScanElementBase = I18nMixin(PolymerElement);

export class MultiPageScanElement extends MultiPageScanElementBase {
  static get is() {
    return 'multi-page-scan' as const;
  }

  static get template() {
    return getTemplate();
  }

  static get properties() {
    return {
      appState: {
        type: Number,
        observer: 'appStateChanged',
      },

      pageNumber: {
        type: Number,
        observer: 'pageNumberChanged',
      },

      scanButtonText: String,

      showCancelButton: {
        type: Boolean,
        value: false,
      },

      cancelButtonDisabled: {
        type: Boolean,
        value: false,
      },

      showCancelingText: {
        type: Boolean,
        value: false,
      },
    };
  }

  appState: AppState;
  pageNumber: number;
  private scanButtonText: string;
  private showCancelButton: boolean;
  private cancelButtonDisabled: boolean;
  private showCancelingText: boolean;

  private appStateChanged(): void {
    this.showCancelButton = this.appState === AppState.MULTI_PAGE_SCANNING ||
        this.appState === AppState.MULTI_PAGE_CANCELING;
    this.cancelButtonDisabled = this.appState === AppState.MULTI_PAGE_CANCELING;
    this.showCancelingText = this.appState === AppState.MULTI_PAGE_CANCELING;
  }

  private pageNumberChanged(): void {
    ScanningBrowserProxyImpl.getInstance()
        .getPluralString('scanButtonText', this.pageNumber + 1)
        .then(
            /* @type {string} */ (pluralString) => {
              this.scanButtonText = pluralString;
            });
  }

  private onScanClick(): void {
    this.dispatchEvent(
        new CustomEvent('scan-next-page', {bubbles: true, composed: true}));
  }

  private onSaveClick(): void {
    this.dispatchEvent(new CustomEvent(
        'complete-multi-page-scan', {bubbles: true, composed: true}));
  }

  private onCancelClick(): void {
    this.dispatchEvent(
        new CustomEvent('cancel-click', {bubbles: true, composed: true}));
  }

  private getProgressText(): string {
    return this.i18n('multiPageScanProgressText', this.pageNumber);
  }
}

declare global {
  interface HTMLElementEventMap {
    'cancel-click': CustomEvent<void>;
    'complete-multi-page-scan': CustomEvent<void>;
    'scan-next-page': CustomEvent<void>;
  }

  interface HTMLElementTagNameMap {
    [MultiPageScanElement.is]: MultiPageScanElement;
  }
}

customElements.define(MultiPageScanElement.is, MultiPageScanElement);