Sha256: f47f09ca568cf583115a3d3c0a20fe48d158414f34191b8c353ca556a756bda9

Contents?: true

Size: 1.16 KB

Versions: 25

Compression:

Stored size: 1.16 KB

Contents

export default class Work {
  // Autocomplete for finding possible related works.
  constructor(element, url, excludeWorkId) {
    this.url = url;
    this.excludeWorkId = excludeWorkId;
    this.initUI(element)
  }

  initUI(element) {
    element.select2( {
      minimumInputLength: 2,
      initSelection : (row, callback) => {
        var data = {id: row.val(), text: row.val()};
        callback(data);
      },
      ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
        url: this.url,
        dataType: 'json',
        data: (term, page) => {
          return {
            q: term, // search term
            id: this.excludeWorkId // Exclude this work
          };
        },
        results: this.processResults
      }
    }).select2('data', null);
  }

  // parse the results into the format expected by Select2.
  // since we are using custom formatting functions we do not need to alter remote JSON data
  processResults(data, page) {
    let results = data.map((obj) => {
                             return { id: obj.id, text: obj.label[0] };
                          })
    return { results: results };
  }
}

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
hyrax-1.1.1 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.3 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-1.1.0 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.2 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.1 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0.rc3 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0.rc2 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0.rc1 app/assets/javascripts/hyrax/autocomplete/work.es6
sufia-7.4.1 app/assets/javascripts/sufia/autocomplete/work.es6
hyrax-1.0.5 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0.beta5 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0.beta4 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0.beta3 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-2.0.0.beta2 app/assets/javascripts/hyrax/autocomplete/work.es6
sufia-7.4.0 app/assets/javascripts/sufia/autocomplete/work.es6
hyrax-2.0.0.beta1 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-1.0.4 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-1.0.3 app/assets/javascripts/hyrax/autocomplete/work.es6
hyrax-1.0.2 app/assets/javascripts/hyrax/autocomplete/work.es6