Sha256: 2fd11085497fddf30743e1e38d67fb61726197d9482d1fa179c8ae2ec51579e6

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

/*jslint vars: true, white: true */
/*global jQuery, IQVOC */

IQVOC.ConceptMapper = (function($) {

"use strict";

// `selector` is either a jQuery object, a DOM node or a string
function ConceptMapper(selector) {
  if(arguments.length === 0) { // subclassing
    return;
  }

  this.root = selector.jquery ? selector : $(selector);
  this.matchTypes = this.determineMatchTypes();

  var matchOptions = $.map(this.matchTypes, function(desc, id) {
    return $("<option />").val(id).text(desc)[0];
  });

  // spawn UI elements

  this.container = $("<div />").addClass("concept-mapper control-group");

  this.input = $("<input />").attr("type", "text").prependTo(this.container);
  $("<button />").addClass("btn fa fa-plus").insertAfter(this.input).
      click($.proxy(this, "onConfirm"));
  this.matchType = $("<select />").append(matchOptions).insertAfter(this.input);

  this.container.prependTo(this.root);
}
ConceptMapper.prototype.delimiter = ", ";
ConceptMapper.prototype.onConfirm = function(ev) {
  ev.preventDefault();

  var textAreaName = this.matchType.val();
  var textArea = document.getElementsByName(textAreaName)[0];
  textArea = $(textArea);

  var newURI = this.input.val();
  var newValue = $.trim(textArea.val() + this.delimiter + newURI);

  textArea.val(newValue);
  this.input.val("");
  this.root.trigger("concept-mapped", {
    uri: newURI,
    matchType: this.matchTypes[textAreaName]
  });
};
ConceptMapper.prototype.determineMatchTypes = function() {
  var data = {};
  $("label", this.root).each(function(i, node) {
    var el = $(node);
    var fieldName = el.attr("for");
    data[fieldName] = el.text();
  });
  return data;
};

return ConceptMapper;

}(jQuery));

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
iqvoc-4.3.3 app/assets/javascripts/iqvoc/concept_mapper.js
iqvoc-4.3.2 app/assets/javascripts/iqvoc/concept_mapper.js
iqvoc-4.3.1 app/assets/javascripts/iqvoc/concept_mapper.js
iqvoc-4.3.0 app/assets/javascripts/iqvoc/concept_mapper.js