Sha256: 6ca99dbb388a151a7dc30d52983957fd1b9e92fcb47db9b25f4b54dbd1c81774

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

import { Controller } from "@hotwired/stimulus";

export default class PageOptionsController extends Controller {
  static get targets() {
    return ["advancedOptions", "autoPublishNotice", "published", "publishedDate"];
  }

  connect() {
    this.checkAutoPublish();
    this.checkPublishedDate();
  }

  checkAutoPublish() {
    if (this.publishedDate() > new Date()) {
      this.show(this.autoPublishNoticeTarget);
    } else {
      this.hide(this.autoPublishNoticeTarget);
    }
  }

  checkPublishedDate() {
    if (this.publishedTarget.value == 2) {
      this.show(this.publishedDateTarget);
    } else {
      this.hide(this.publishedDateTarget);
    }
  }

  publishedDate() {
    const lookup = (name) => {
      return this.publishedDateTarget.getElementsByClassName(name)[0].value;
    };
    return new Date(
      lookup("year"),
      (lookup("month") - 1),
      lookup("day"),
      lookup("hour"),
      lookup("minute")
    );
  }

  show(elem) {
    elem.classList.add("show");
  }

  hide(elem) {
    elem.classList.remove("show");
  }

  toggle(elem) {
    if (elem.classList.contains("show")) {
      this.hide(elem);
    } else {
      this.show(elem);
    }
  }

  toggleAdvancedOptions(evt) {
    evt.preventDefault();
    this.toggle(this.advancedOptionsTarget);
  }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pages_core-3.12.4 app/javascript/controllers/PageOptionsController.js
pages_core-3.12.3 app/javascript/controllers/PageOptionsController.js
pages_core-3.12.2 app/javascript/controllers/PageOptionsController.js
pages_core-3.12.1 app/javascript/controllers/PageOptionsController.js
pages_core-3.12.0 app/javascript/controllers/PageOptionsController.js
pages_core-3.11.3 app/javascript/controllers/PageOptionsController.js
pages_core-3.11.2 app/javascript/controllers/PageOptionsController.js
pages_core-3.11.1 app/javascript/controllers/PageOptionsController.js
pages_core-3.11.0 app/javascript/controllers/PageOptionsController.js
pages_core-3.10.2 app/javascript/controllers/PageOptionsController.js