// Generated by CoffeeScript 1.12.7
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  hasProp = {}.hasOwnProperty;

ez5.BarcodeSearchExpertPlugin = (function(superClass) {
  extend(BarcodeSearchExpertPlugin, superClass);

  function BarcodeSearchExpertPlugin() {
    return BarcodeSearchExpertPlugin.__super__.constructor.apply(this, arguments);
  }

  BarcodeSearchExpertPlugin.prototype.beforeFieldAdded = function(opts) {
    var _field, _fields, data, dataOptions, field, fields, i, j, len, len1, limit, ref;
    field = opts.field;
    data = opts.data;
    if (CUI.util.isEmpty(data[field.name()])) {
      return;
    }
    if (field != null ? field.mask : void 0) {
      fields = field.mask.getFields("all");
    } else if (field instanceof MultipleFieldsContainer && field.fields) {
      fields = [];
      ref = field.fields;
      for (i = 0, len = ref.length; i < len; i++) {
        _field = ref[i];
        _fields = _field.mask.getFields("all");
        fields = fields.concat(_fields);
      }
    } else {
      return;
    }
    for (j = 0, len1 = fields.length; j < len1; j++) {
      _field = fields[j];
      if (!(_field instanceof ez5.BarcodeMaskSplitter)) {
        continue;
      }
      dataOptions = _field.getDataOptions();
      if ((dataOptions != null ? dataOptions.field_name : void 0) !== field.name()) {
        continue;
      }
      limit = parseInt(dataOptions.expert_search_limit);
      if (limit > 0) {
        data[field.name()] = data[field.name()].substring(0, limit);
      }
    }
  };

  return BarcodeSearchExpertPlugin;

})(ez5.SearchExpertPlugin);

ez5.session_ready(function() {
  return SearchExpertOptions.plugins.registerPlugin(ez5.BarcodeSearchExpertPlugin);
});
