Sha256: 52cb3520489672230075e308dc48c5c570bac6408f0c4b40aab6df4370f4e1b1

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

import { Controller } from "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

8 entries across 8 versions & 1 rubygems

Version Path
pages_core-3.10.1 app/javascript/controllers/PageOptionsController.js
pages_core-3.9.2 app/javascript/controllers/PageOptionsController.js
pages_core-3.9.1 app/javascript/controllers/PageOptionsController.js
pages_core-3.9.0 app/javascript/controllers/PageOptionsController.js
pages_core-3.8.3 app/javascript/controllers/PageOptionsController.js
pages_core-3.8.2 app/javascript/controllers/PageOptionsController.js
pages_core-3.8.1 app/javascript/controllers/PageOptionsController.js
pages_core-3.8.0 app/javascript/controllers/PageOptionsController.js