Sha256: 3ae532cc33718f91b6045140fd57cfba05f887f820487493a6686c8b8ca3c90a

Contents?: true

Size: 1.52 KB

Versions: 81

Compression:

Stored size: 1.52 KB

Contents

export default class SelectWorkType {
  /**
   * Initializes the class in the context of an individual table element
   * @param {jQuery} element the table element that this class represents
   */
  constructor(element) {
      this.$element = element;
      this.target = element.data('target')
      this.modal = $(this.target)
      this.form = this.modal.find('form.new-work-select')

      // launch the modal.
      element.on('click', (e) => {
          e.preventDefault()
          this.modal.modal()
          // ensure the type is set for the last clicked element
          // type is either "batch" or "single" (work)
          this.type = element.data('create-type')
          // add custom routing logic when the modal is shown
          this.form.on('submit', this.routingLogic.bind(this))
      });

      // remove the routing logic when the modal is hidden
      this.modal.on('hide.bs.modal', (e) => {
          this.form.unbind('submit')
      });
  }

  // when the form is submitted route to the correct location
  routingLogic(e) {
      e.preventDefault()
      if (this.destination() === undefined)
        return false
      // get the destination from the data attribute of the selected radio button
      window.location.href = this.destination()
  }

  // Each input has two attributes that contain paths, one for the batch and one
  // for a single work.  So, given the value of 'this.type', return the appropriate
  // path.
  destination() {
      return this.form.find('input[type="radio"]:checked').data(this.type)
  }
}

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-5.0.0 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-5.0.0.rc3 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-5.0.0.rc2 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-5.0.0.rc1 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.6.0 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-4.0.0 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-4.0.0.rc3 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-4.0.0.rc2 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-4.0.0.rc1 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.5.0 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-4.0.0.beta2 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.4.2 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-4.0.0.beta1 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.4.1 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.4.0 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.3.0 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.2.0 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-2.9.6 app/assets/javascripts/hyrax/select_work_type.es6
hyrax-3.1.0 app/assets/javascripts/hyrax/select_work_type.es6