Sha256: f4df46c2f78f332f54cdd0d268e7e8e865ece936758bf573071f18bb41db79b2

Contents?: true

Size: 1.12 KB

Versions: 18

Compression:

Stored size: 1.12 KB

Contents

export class VToggleDisabled {
  constructor(options, params, event, root) {
    this.targetId = options.target;
    this.params = params;
    this.event = event;
    this.root = root;
  }

  call(results) {
    const targetId = this.targetId;
    const action = this.params.action;
    const delayAmt = this.event instanceof FocusEvent ? 500 : 0;
    const elem = this.root.getElementById(targetId);

    if (!elem) {
      const err = new Error(
        `Unable to locate node ${targetId}!`
        + ' Did you forget to attach it?',
      );

      results.push({
        action: 'toggle_disabled',
        contentType: 'v/errors',
        content: {exception: err.message},
      });

      return new Promise((_, reject) => reject(results));
    }

    const promiseObj = new Promise(function(resolve) {
      clearTimeout(elem.vTimeout);
      elem.vTimeout = setTimeout(function() {
        console.debug('Toggling disabled on: ' + targetId);
        elem.disabled = (action === 'disable')
        results.push({action: 'toggle_disabled', statusCode: 200});
        resolve(results);
      }, delayAmt);
    });
    return promiseObj;
  }
}

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
coprl-3.0.0.beta.12 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.11 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.10 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.9 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.8 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.7 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.6 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.5 views/mdc/assets/js/components/events/toggle_disabled.js
voom-presenters-2.1.2 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.4 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.3 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.2 views/mdc/assets/js/components/events/toggle_disabled.js
coprl-3.0.0.beta.1 views/mdc/assets/js/components/events/toggle_disabled.js
voom-presenters-2.1.0 views/mdc/assets/js/components/events/toggle_disabled.js
voom-presenters-2.0.3 views/mdc/assets/js/components/events/toggle_disabled.js
voom-presenters-2.0.2 views/mdc/assets/js/components/events/toggle_disabled.js
voom-presenters-2.0.1 views/mdc/assets/js/components/events/toggle_disabled.js
voom-presenters-2.0.0 views/mdc/assets/js/components/events/toggle_disabled.js